Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created July 21, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/0a9a436be5f2ab67c862 to your computer and use it in GitHub Desktop.
Save kibotu/0a9a436be5f2ab67c862 to your computer and use it in GitHub Desktop.
git version count and version name
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()
}
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