From 38a7b264f2aebc5de0ab76e2549812ea4fdcad40 Mon Sep 17 00:00:00 2001 From: Chris Boyle Date: Fri, 31 Oct 2014 14:14:40 +0000 Subject: [PATCH] Automatic date-based version name, now Simon's using git. Will automate version code somehow at some future time... --- app/build.gradle | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index bf235bddd..894926dea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,10 +1,37 @@ import org.apache.tools.ant.taskdefs.condition.Os import com.google.common.base.Joiner +import java.text.SimpleDateFormat + apply plugin: 'com.android.application' def ndkDir = project.plugins.findPlugin('android').getNdkFolder() +def timestamp() { + def dateFormat = new SimpleDateFormat("yyyy-MM-dd-HHmm") + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")) + return dateFormat.format(new Date()) +} + +def idForSimon() { + try { + def commit = new ByteArrayOutputStream() + exec { + // Require remote called simon because someone downstream might call my branch "upstream" + commandLine 'git', 'merge-base', 'simon/master', 'master' + standardOutput = commit + } + def shortUnique = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--short', commit.toString().trim() + standardOutput = shortUnique + } + return shortUnique.toString().trim() + } catch (ignored) { + return "UNOFFICIAL" + } +} + android { compileSdkVersion 20 buildToolsVersion "20.0.0" @@ -12,7 +39,7 @@ android { defaultConfig { applicationId "name.boyle.chris.sgtpuzzles" versionCode 94 - versionName "10286.7" + versionName "${timestamp()}-${idForSimon()}" if (file(ndkDir.absolutePath + '/platforms/android-15').exists()) { // the last without PIE minSdkVersion 7