From 76dad5c80634792da9f79529ae2310c780c12711 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 6 Aug 2026 21:56:39 +0600 Subject: [PATCH] Derive versionName/versionCode from git instead of a hand-maintained literal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A static versionName only matches a release tag if someone remembers to bump it first — nothing enforces that, so they drift. versionName now comes from `git describe --tags` (the tag itself when built exactly on a tagged commit, otherwise the usual git-describe dev form), and versionCode from commit count. Cutting a release is now just tagging a commit; there's nothing left to hand-edit. Co-Authored-By: agent --- app/build.gradle.kts | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2653866..1f58ada 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,3 +1,4 @@ +import java.io.ByteArrayOutputStream import java.util.Properties plugins { @@ -12,6 +13,36 @@ if (hasReleaseKeystore) { keystoreProperties.load(keystorePropertiesFile.inputStream()) } +// versionName/versionCode come from git, not a hand-maintained literal, so a release tag and +// the app's own version can never drift apart. Exactly on a tagged commit this is the tag +// itself (e.g. "1.0.0"); otherwise it's "--g" (git-describe's +// usual dev-build form). No tags yet, or git unavailable: falls back to "0.0.0". +fun gitDescribe(): String { + return try { + val out = ByteArrayOutputStream() + exec { + commandLine("git", "describe", "--tags", "--always") + standardOutput = out + } + out.toString().trim() + } catch (e: Exception) { + "0.0.0" + } +} + +fun gitCommitCount(): Int { + return try { + val out = ByteArrayOutputStream() + exec { + commandLine("git", "rev-list", "--count", "HEAD") + standardOutput = out + } + out.toString().trim().toInt() + } catch (e: Exception) { + 1 + } +} + android { namespace = "space.bdeshi.veil" compileSdk = 35 @@ -23,8 +54,8 @@ android { // on which OS versions can install and run the app. minSdk = 27 targetSdk = 35 - versionCode = 1 - versionName = "1.0" + versionCode = gitCommitCount() + versionName = gitDescribe() } signingConfigs {