Last active
August 29, 2015 14:13
-
-
Save piffall/7dec5faf535ecb2691da to your computer and use it in GitHub Desktop.
Get version from git tagging
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
// Copy and paste the content of this file in app/build.gradle | |
// Now you are able to use it under defaultConfig, for example: | |
// versionCode getRevCount() | |
// versionName getTag() + '-' + getRevHash() | |
System.println( "App: " + "com.example.app" + " v" + getTag() + '-' + getRevHash() + "(" + getRevCount() + ")" ) | |
def getTag() { | |
def cmd1 = "git rev-list --tags --max-count=1" | |
def proc1 = cmd1.execute() | |
def cmd2 = "git describe --tags " + proc1.text.trim() | |
def proc2 = cmd2.execute() | |
def revision = proc2.text.trim() | |
return revision | |
} | |
def getRevCount() { | |
def cmd = "git rev-list --all --count" | |
def proc = cmd.execute() | |
def revision = Integer.valueOf(proc.text.trim()) | |
return Integer.valueOf(revision) | |
} | |
def getRevHash() { | |
def cmd = "git rev-parse --short HEAD" | |
def proc = cmd.execute() | |
def revision = proc.text.trim() | |
return revision | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment