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 ────────────────────────────────────
|
// ── 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")
|
fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
|
||||||
.removePrefix("v")
|
.removePrefix("v")
|
||||||
.ifEmpty { "0.1.0" }
|
.ifEmpty { "0.1.0" }
|
||||||
|
|
||||||
fun gitCommitCount(): Int = runGit("rev-list", "--count", "HEAD")
|
// Build number = total commits (always increments) + offset for store history
|
||||||
.toIntOrNull() ?: 1
|
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")
|
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
|
||||||
.ifEmpty { "unknown" }
|
.ifEmpty { "unknown" }
|
||||||
|
|
||||||
|
// Display: "0.1.0+5.abc1234"
|
||||||
fun gitDisplayVersion(): String {
|
fun gitDisplayVersion(): String {
|
||||||
val base = gitVersionName()
|
val base = gitVersionName()
|
||||||
val count = gitCommitCount()
|
val build = gitBuildNumber()
|
||||||
val hash = gitShortHash()
|
val hash = gitShortHash()
|
||||||
return "$base+$count.$hash"
|
return "$base+$build.$hash"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runGit(vararg args: String): String = try {
|
fun runGit(vararg args: String): String = try {
|
||||||
@@ -59,7 +63,7 @@ android {
|
|||||||
applicationId = "com.omixlab.lckcontrol"
|
applicationId = "com.omixlab.lckcontrol"
|
||||||
minSdk = 32
|
minSdk = 32
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = gitCommitCount()
|
versionCode = gitBuildNumber()
|
||||||
versionName = gitVersionName()
|
versionName = gitVersionName()
|
||||||
|
|
||||||
buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"")
|
buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"")
|
||||||
|
|||||||
26
deploy.ps1
26
deploy.ps1
@@ -10,20 +10,18 @@ $ErrorActionPreference = "Stop"
|
|||||||
|
|
||||||
$AppId = "25653777174321448"
|
$AppId = "25653777174321448"
|
||||||
$Token = "OC|25653777174321448|b861e3eeaf58edf097812b5fe588dabb"
|
$Token = "OC|25653777174321448|b861e3eeaf58edf097812b5fe588dabb"
|
||||||
$BuildGradle = "$PSScriptRoot\app\build.gradle.kts"
|
|
||||||
$OvrUtil = "$PSScriptRoot\ovr-platform-util.exe"
|
$OvrUtil = "$PSScriptRoot\ovr-platform-util.exe"
|
||||||
|
|
||||||
# --- Bump versionCode ---
|
# --- Git version info ---
|
||||||
$content = Get-Content $BuildGradle -Raw
|
$versionName = (git describe --tags --abbrev=0 2>$null) -replace '^v', ''
|
||||||
if ($content -match 'versionCode\s*=\s*(\d+)') {
|
if (-not $versionName) { $versionName = "0.1.0" }
|
||||||
$oldCode = [int]$Matches[1]
|
$commitCount = git rev-list --count HEAD 2>$null
|
||||||
$newCode = $oldCode + 1
|
if (-not $commitCount) { $commitCount = "1" }
|
||||||
$content = $content -replace "versionCode\s*=\s*$oldCode", "versionCode = $newCode"
|
$shortHash = git rev-parse --short HEAD 2>$null
|
||||||
Set-Content $BuildGradle $content -NoNewline
|
if (-not $shortHash) { $shortHash = "unknown" }
|
||||||
Write-Host "Bumped versionCode: $oldCode -> $newCode" -ForegroundColor Cyan
|
$displayVersion = "$versionName+$commitCount.$shortHash"
|
||||||
} else {
|
|
||||||
Write-Error "Could not find versionCode in build.gradle.kts"
|
Write-Host "Version: $displayVersion (versionCode=$commitCount)" -ForegroundColor Cyan
|
||||||
}
|
|
||||||
|
|
||||||
# --- Build APK ---
|
# --- Build APK ---
|
||||||
$task = if ($BuildType -eq "release") { ":app:assembleRelease" } else { ":app:assembleDebug" }
|
$task = if ($BuildType -eq "release") { ":app:assembleRelease" } else { ":app:assembleDebug" }
|
||||||
@@ -44,8 +42,8 @@ Write-Host "Uploading to channel '$Channel'..." -ForegroundColor Cyan
|
|||||||
--apk $apk `
|
--apk $apk `
|
||||||
--channel $Channel `
|
--channel $Channel `
|
||||||
--age-group MIXED_AGES `
|
--age-group MIXED_AGES `
|
||||||
--notes "v$newCode $BuildType build"
|
--notes "$displayVersion $BuildType build"
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Error "Upload failed" }
|
if ($LASTEXITCODE -ne 0) { Write-Error "Upload failed" }
|
||||||
|
|
||||||
Write-Host "Deployed versionCode $newCode ($BuildType) to '$Channel'" -ForegroundColor Green
|
Write-Host "Deployed $displayVersion ($BuildType) to '$Channel'" -ForegroundColor Green
|
||||||
|
|||||||
Reference in New Issue
Block a user