Created
June 13, 2017 06:37
-
-
Save eefret/23eaa35588743c7b02530bedd3518cc0 to your computer and use it in GitHub Desktop.
This automatically sets your version number based on your git commit count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaultConfig { | |
# Add 10000 to move past old SVN revisions. | |
versionCode gitCommitCount() + 10000 ?: 0 | |
} | |
def gitCommitCount() { | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', '--count', 'HEAD' | |
standardOutput = stdout | |
} | |
def commitCount = stdout.toString().trim().toInteger() | |
return commitCount | |
} | |
catch (ignored) { | |
return 0; | |
} | |
} | |
def gitRevision() { | |
try { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', 'HEAD', '-n', '1' | |
standardOutput = stdout | |
} | |
def commitRevision = stdout.toString().trim() | |
return commitRevision | |
} | |
catch (ignored) { | |
return "(unknown revision)"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment