Add git-based versioning and build version display
- versionCode from commit count + offset (always incremental) - versionName from git tag (semantic versioning) - BuildConfig.DISPLAY_VERSION shows "0.1.0+N.hash" in login screen - Updated deploy.ps1 to use git versioning instead of manual bumps
This commit is contained in:
@@ -9,21 +9,25 @@ plugins {
|
||||
}
|
||||
|
||||
// ── Git-based versioning ────────────────────────────────────
|
||||
// Version name from latest git tag (e.g. v0.1.0 -> "0.1.0")
|
||||
fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
|
||||
.removePrefix("v")
|
||||
.ifEmpty { "0.1.0" }
|
||||
|
||||
fun gitCommitCount(): Int = runGit("rev-list", "--count", "HEAD")
|
||||
.toIntOrNull() ?: 1
|
||||
// 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
|
||||
|
||||
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
|
||||
.ifEmpty { "unknown" }
|
||||
|
||||
// Display: "0.1.0+5.abc1234"
|
||||
fun gitDisplayVersion(): String {
|
||||
val base = gitVersionName()
|
||||
val count = gitCommitCount()
|
||||
val build = gitBuildNumber()
|
||||
val hash = gitShortHash()
|
||||
return "$base+$count.$hash"
|
||||
return "$base+$build.$hash"
|
||||
}
|
||||
|
||||
fun runGit(vararg args: String): String = try {
|
||||
@@ -59,7 +63,7 @@ android {
|
||||
applicationId = "com.omixlab.lckcontrol"
|
||||
minSdk = 32
|
||||
targetSdk = 34
|
||||
versionCode = gitCommitCount()
|
||||
versionCode = gitBuildNumber()
|
||||
versionName = gitVersionName()
|
||||
|
||||
buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"")
|
||||
|
||||
Reference in New Issue
Block a user