Skip to content

Instantly share code, notes, and snippets.

@qguv
Created August 22, 2016 22:48
Show Gist options
  • Save qguv/5c213e2b2194a94a2098b897e0a1bb47 to your computer and use it in GitHub Desktop.
Save qguv/5c213e2b2194a94a2098b897e0a1bb47 to your computer and use it in GitHub Desktop.
Build a buncha different versions
#!/usr/bin/env python3
from itertools import zip_longest
from os import chdir, environ, getcwd, makedirs
from pathlib import Path
from subprocess import CalledProcessError, check_call
from sys import argv, exit
def commits_from_file(filename):
with open(filename, 'r') as f:
lines = [ line.strip() for line in f.readlines() ]
return list(filter(None, lines))
def checkout(commit):
check_call(['git', 'checkout', commit])
def cp(src, dest):
check_call(['cp', '-r', str(src), str(dest)])
def clone(url, name):
prefix = '/tmp/multibuild/prestine/'
dest = prefix + name
check_call(['rm', '-rf', prefix])
check_call(['mkdir', '-p', prefix])
check_call(['git', 'clone', url, dest])
return dest
def reclone(commit, prestine_project):
dest = '/tmp/multibuild/{}/'.format(commit)
cp(prestine_project, dest)
return dest
def rm(path):
check_call(['rm', '-rf', path])
def multibuild(project_name, url, commits, build, save):
print("Building {} commits of app {}:".format(len(commits), project_name))
prestine_project = clone(url, project_name)
back = getcwd()
ok, fail = [], []
for commit in commits:
project_dir = reclone(commit, prestine_project)
chdir(project_dir)
checkout(commit)
if build(commit) and save(commit):
ok.append(commit)
print("[ OK ]", commit)
else:
fail.append(commit)
print("[FAIL]", commit)
chdir(back)
rm(project_dir)
print("Summary for app {}:".format(project_name))
okp = len(ok) * 100 / len(commits)
print(" {} ({}) BUILT".format(len(ok), okp))
print(" {} ({}) BROKE".format(len(commits) - len(ok), 100 - okp))
print()
print(" [ OK ] [FAIL]")
for o, f in zip_longest(ok, fail, fillvalue=' ' * len(commits[-1])):
print(o, f)
## MyExpenses #################################################################
def mye_build(commit):
check_call(['git', 'submodule', 'init'])
check_call(['git', 'submodule', 'update'])
environ['ANDROID_HOME'] = '/opt/android-sdk'
try:
check_call(['./gradlew', 'build'])
return True
except (KeyboardInterrupt, Exception) as e:
print("Building commit {} failed: {}".format(commit, e))
return False
def mye_save(commit):
out_dir = '/home/qguv/build/multibuild-apks/MyExpenses/'
try:
makedirs(out_dir, exist_ok=True)
out_name = out_dir + commit + '.apk'
apk = './myExpenses/build/outputs/apk/myExpenses-release-unsigned.apk'
cp(apk, out_name)
return True
except (KeyboardInterrupt, Exception) as e:
print("Saving commit {} failed: {}".format(commit, e))
return False
mye_commits = commits_from_file('./MyExpenses_commits.txt')
multibuild('MyExpenses', 'https://github.com/mtotschnig/MyExpenses', mye_commits, mye_build, mye_save)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment