spiegel-keyman/android/version.gradle

100 lines
No EOL
3.7 KiB
Groovy

// version.gradle
//
// This depends on ext.rootPath = path to /android folder in repository
// It can be a relative path. Gradle does not appear to support relative
// paths from included scripts.
//
def getVersionCode = { ->
String env_version_major = System.getenv("VERSION_MAJOR")
String env_version_minor = System.getenv("VERSION_MINOR")
String env_version_patch = System.getenv("VERSION_PATCH")
if(env_version_patch != null && env_version_minor != null && env_version_patch != null) {
// Version code is, for 17.1.33: 1810033. This supports up to 9999
// builds for a given major.minor version. We only support up to 9 minor
// versions for a given major version but at present we are not using
// minor versions at all.
//
// Despite this calculation, the version_code should be treated as an
// opaque integer, used only for Play Store publishing.
//
// NOTE: accidental publish of beta 17.0.6 during 16.0 beta cycle has
// forced a version_major bump, which is a permanent change. Relates to
// #7705.
Integer version_code =
(env_version_major.toInteger() + 1) * 100000 +
env_version_minor.toInteger() * 10000 +
env_version_patch.toInteger()
println "Using version code " + version_code
return version_code
}
// Probably building from IDE
println "Using fixed version code 100"
return 100
}
def getVersionMD = { ->
String env_version = System.getenv("VERSION")
if (env_version != null) {
// If building from script, we have build number in VERSION
println "Using build $env_version from VERSION"
return "$env_version"
} else {
String version_md = file("$rootPath/../VERSION.md").text.trim()
return "$version_md"
}
}
def getVersionName = { ->
String env_version = System.getenv("VERSION_WITH_TAG")
if (env_version != null) {
// If building from script, we have build number in VERSION_WITH_TAG
println "Using build $env_version from VERSION_WITH_TAG"
return "$env_version"
} else {
// Building probably from IDE, so let's use VERSION.md and TIER.md directly
// This is a close match with VERSION_WITH_TAG, except that 'stable' tier
// is not normally included with VERSION_WITH_TAG
String version_md = file("$rootPath/../VERSION.md").text.trim()
String tier_md = file("$rootPath/../TIER.md").text.trim()
println "Using build $version_md-$tier_md-local from project VERSION.md/TIER.md"
return "$version_md-$tier_md-local"
}
}
def getVersionEnvironment = { ->
String env_environment = System.getenv("VERSION_ENVIRONMENT")
if (env_environment != null) {
// If building from script, we have build number in VERSION_ENVIRONMENT
println "Using $env_environment from VERSION_ENVIRONMENT"
return "$env_environment"
} else {
// Building probably from IDE, so use "local"
println "Using local environment"
return "local"
}
}
def getVersionGitTag = { ->
String env_git_tag = System.getenv("VERSION_GIT_TAG")
if (env_git_tag != null) {
println "Using $env_git_tag from VERSION_GIT_TAG"
return "$env_git_tag"
} else {
// Building probably from IDE
println "Using release@$VERSION_NAME"
return "release@$VERSION_NAME"
}
}
ext {
VERSION_CODE=getVersionCode()
VERSION_MD=getVersionMD()
VERSION_NAME=getVersionName()
VERSION_ENVIRONMENT=getVersionEnvironment()
VERSION_TAG=System.getenv("VERSION_TAG")
VERSION_GIT_TAG=getVersionGitTag()
}
//println "version.gradle: VERSION_TAG: " + VERSION_TAG