Created
July 21, 2015 13:55
-
-
Save kibotu/0a9a436be5f2ab67c862 to your computer and use it in GitHub Desktop.
git version count and version name
This file contains 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
def getCommitCount() { | |
final Scanner s = new Scanner(getCommitNumberFromGit()); | |
int count = 0; | |
while (s.hasNextLine()) { | |
s.nextLine(); | |
count++; | |
} | |
return count; | |
} | |
def getCommitNumberFromGit() { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', '--all' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} | |
def getVersionNameFromGit() { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags', '--always' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} |
This file contains 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
android { | |
compileSdkVersion 22 | |
buildToolsVersion "22.0.1" | |
defaultConfig { | |
versionName getVersionNameFromGit() | |
versionCode = getCommitCount() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment