Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest tag to retrieve versionCode for nightly releases #5056

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions versioning.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import javax.inject.Inject
import org.gradle.api.provider.ValueSourceParameters
import java.nio.charset.Charset

ext {

buildVersionCode = {
def versionCode = buildNumberCode()
def versionName = getVersionName()
def (major, minor, patch) = versionName.toLowerCase().tokenize('.')
(major, minor, patch) = [major, minor, patch].collect { it.toInteger() }
(major * 10_000_000) + (minor * 10_000) + (patch * 1_000) + buildNumberCode()
(major * 10_000_000) + (minor * 10_000) + (patch * 1_000) + versionCode
}

getVersionName = {
Expand All @@ -31,15 +36,22 @@ ext {
}

buildNumberCode = {
filePath = "${CI_HOME_DIR}/build_number.properties"
if(!new File(filePath).exists()) return 0

def suffix = getVersionNameSuffix()
if (suffix?.trim()) {
def props = new Properties()
props.load(new FileInputStream(filePath))
String buildNumber = props["build"]
if (buildNumber == null) return 0 else return Integer.valueOf(buildNumber)
def latestGitTagProvider = providers.of(LatestGitTagValueSource.class) {}
def tag = latestGitTagProvider.get()
if (tag.contains('nightly')) {
def (major, minor, patch, nightly) = tag.toLowerCase().tokenize('.')
(major, minor, patch, nightly) = [major, minor, patch, nightly].collect { it.toString() }

def (code, sufix) = nightly.toLowerCase().tokenize('-')
(code, sufix) = [code, sufix].collect { it.toString() }

def newCode = Integer.parseInt(code) + 1
return newCode
} else {
return 0
}
} else {
return 0
}
Expand Down Expand Up @@ -97,4 +109,24 @@ tasks.register('getBuildVersionName') {
doLast {
print buildVersionName()
}
}

tasks.register('getBuildVersionCode') {
doLast {
print buildNumberCode()
}
}

abstract class LatestGitTagValueSource implements ValueSource<String, ValueSourceParameters.None> {
@Inject
abstract ExecOperations getExecOperations()

String obtain() {
ByteArrayOutputStream output = new ByteArrayOutputStream()
execOperations.exec {
it.commandLine "git", "describe", "--tags", "--abbrev=0"
it.standardOutput = output
}
return new String(output.toByteArray(), Charset.defaultCharset())
}
}
Loading