refactor: [8/n] Extract git-based versioning logic
This commit is contained in:
parent
498f3c5478
commit
8845ceec9a
|
@ -3,33 +3,7 @@ plugins {
|
|||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
def getVersionCode = { ->
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return Integer.parseInt(stdout.toString().trim())
|
||||
}
|
||||
catch (ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
def getVersionName = { ->
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'describe', '--always', '--tags', '--dirty'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim()
|
||||
}
|
||||
catch (ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
apply from: '../helpers.gradle'
|
||||
|
||||
// Signing config, mainly intended for debug builds
|
||||
def keystorePropertiesFile = rootProject.file("keystore.properties");
|
||||
|
@ -43,8 +17,8 @@ android {
|
|||
applicationId "im.angry.openeuicc"
|
||||
minSdk 30
|
||||
targetSdk 31
|
||||
versionCode getVersionCode()
|
||||
versionName getVersionName()
|
||||
versionCode getGitVersionCode()
|
||||
versionName getGitVersionName()
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -67,7 +41,7 @@ android {
|
|||
signingConfig signingConfigs.config
|
||||
}
|
||||
}
|
||||
applicationVariants.all { variant ->
|
||||
applicationVariants.configureEach { variant ->
|
||||
if (variant.name == "debug") {
|
||||
variant.outputs.each { o -> o.versionCodeOverride = System.currentTimeSeconds() }
|
||||
}
|
||||
|
|
27
helpers.gradle
Normal file
27
helpers.gradle
Normal file
|
@ -0,0 +1,27 @@
|
|||
ext.getGitVersionCode = { ->
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return Integer.parseInt(stdout.toString().trim())
|
||||
}
|
||||
catch (ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ext.getGitVersionName = { ->
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'describe', '--always', '--tags', '--dirty'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim()
|
||||
}
|
||||
catch (ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue