Use .buildcount file for unique auto-incrementing versionCode

Build counter is incremented by deploy.ps1 on every deploy, ensuring
unique versionCode even from the same commit. File is gitignored.
This commit is contained in:
2026-02-24 12:09:36 +01:00
parent 9259b0fb28
commit 756a3da783
3 changed files with 22 additions and 11 deletions

View File

@@ -14,18 +14,19 @@ fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
.removePrefix("v")
.ifEmpty { "0.1.0" }
// Build number = total commits (always increments) + offset for store history
const val VERSION_CODE_OFFSET = 4
fun gitBuildNumber(): Int = (runGit("rev-list", "--count", "HEAD")
.toIntOrNull() ?: 1) + VERSION_CODE_OFFSET
// Build number from .buildcount file (incremented by deploy.ps1)
fun buildNumber(): Int {
val file = rootProject.file(".buildcount")
return if (file.exists()) file.readText().trim().toIntOrNull() ?: 1 else 1
}
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
.ifEmpty { "unknown" }
// Display: "0.1.0+5.abc1234"
// Display: "0.1.0+6.abc1234"
fun gitDisplayVersion(): String {
val base = gitVersionName()
val build = gitBuildNumber()
val build = buildNumber()
val hash = gitShortHash()
return "$base+$build.$hash"
}
@@ -63,7 +64,7 @@ android {
applicationId = "com.omixlab.lckcontrol"
minSdk = 32
targetSdk = 34
versionCode = gitBuildNumber()
versionCode = buildNumber()
versionName = gitVersionName()
buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"")