on debug builds, set versionCode using DB_VERSION + commit count

This provides an automatic way to generate updates from each new debug
build, it is build from the developer's machine or via the nightly repo.
This commit is contained in:
Hans-Christoph Steiner 2017-11-09 22:56:14 +01:00
parent 427d0d0aa0
commit d4d9707631
2 changed files with 26 additions and 4 deletions

View File

@ -237,6 +237,32 @@ android {
} }
} }
/* set the debug versionCode based on DB verson and how many commits in the repo */
applicationVariants.all { variant ->
if (variant.buildType.isDebuggable()) {
// default to a timestamp, in case anything fails later
variant.mergedFlavor.versionCode = new Date().getTime() / 1000
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--first-parent', '--count', 'HEAD'
standardOutput = stdout
}
def commitCount = Integer.parseInt(stdout.toString().trim())
stdout = new ByteArrayOutputStream()
exec {
commandLine 'sed', '-n', 's,.*DB_VERSION *= *\\([0-9][0-9]*\\).*,\\1,p', 'src/main/java/org/fdroid/fdroid/data/DBHelper.java'
standardOutput = stdout
}
def dbVersion = Integer.parseInt(stdout.toString().trim())
println 'Setting debug versionCode: ' + sprintf("%d%05d", [dbVersion, commitCount])
variant.mergedFlavor.versionCode = Integer.parseInt(sprintf("%d%05d", [dbVersion, commitCount]))
}
catch (ignored) {
}
}
}
testOptions { testOptions {
unitTests { unitTests {
// prevent tests from dying on android.util.Log calls // prevent tests from dying on android.util.Log calls

View File

@ -9,10 +9,6 @@ apt-get update
apt-get install -y --no-install-recommends -t stretch-backports \ apt-get install -y --no-install-recommends -t stretch-backports \
fdroidserver openssh-client rsync python3-qrcode fdroidserver openssh-client rsync python3-qrcode
db=`sed -n 's,.*DB_VERSION *= *\([0-9][0-9]*\).*,\1,p' app/src/main/java/org/fdroid/fdroid/data/DBHelper.java`
count=`git rev-list --first-parent --count HEAD`
sed -i "s,versionCode *[0-9][0-9]*.*,versionCode `printf '%d%05d' $db $count`," app/build.gradle
repo_git_base=${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}-nightly repo_git_base=${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}-nightly
repo_base=https://gitlab.com/${repo_git_base} repo_base=https://gitlab.com/${repo_git_base}
repo_url=${repo_base}/raw/master/fdroid/repo repo_url=${repo_base}/raw/master/fdroid/repo