Created
November 23, 2018 22:17
-
-
Save dekalo-stanislav/197f3dbefcde2a05e3d7459357818977 to your computer and use it in GitHub Desktop.
Gradle script for version generation for tag
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
ext { | |
/** | |
* Gets the version name from the latest Git tag | |
*/ | |
getGitVersionName = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags', '--dirty' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} | |
ensureBuildTaggedProperly = { String versionName -> | |
gitVersionName = getGitVersionName() | |
if (!gitVersionName.startsWith(versionName)) { | |
throw new IllegalStateException("versionName = " + versionName + " gitVersionName = " + gitVersionName) | |
} | |
} | |
/** | |
* Build version number based on semver version name. | |
*/ | |
buildVersionNumber = { String versionName -> | |
// let's reserve last digit for flavors and other staff. | |
int patchDigit = 10 | |
int minorDigit = patchDigit * 1000 | |
int majorDigit = minorDigit * 1000 | |
def (major, minor, patch) = versionName.tokenize('.') | |
if (major == null) major = 0 | |
if (minor == null) minor = 0 | |
if (patch == null) patch = 0 | |
return (major.toInteger() * majorDigit) + (minor.toInteger() * minorDigit) + (patch.toInteger() * patchDigit) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment