Skip to content

Commit 11a1a9b

Browse files
committed
fix: tagged checkouts learn their version from git describe
F-Droid builds a bare checkout of the tag, where the env-injected version does not exist and every build claimed the 0.1.0 fallback. git describe gives any tagged checkout its real version with nothing committed back, keeping the no-loop invariant of the release flow. CI still injects the version before the tag exists.
1 parent 02dd500 commit 11a1a9b

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

app/build.gradle.kts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@ android {
1717
namespace = "me.spoo.android"
1818
compileSdk = 37
1919

20-
// The git tag is the version: CI passes it in, and local or PR builds
21-
// fall back to the dev value below. The code is derived from the name
22-
// so it can only ever go up.
23-
val appVersionName = System.getenv("SPOO_VERSION_NAME")?.removePrefix("v") ?: "0.1.0"
20+
// The git tag is the version: CI passes it in before the tag exists,
21+
// and any tagged checkout (F-Droid builders included) learns it from
22+
// git describe, so nothing is ever committed back. The code is derived
23+
// from the name so it can only ever go up.
24+
val describedVersion =
25+
providers
26+
.exec {
27+
commandLine("git", "describe", "--tags", "--match", "v*")
28+
isIgnoreExitValue = true
29+
}.standardOutput.asText
30+
.map { it.trim().removePrefix("v").substringBefore("-") }
31+
.orNull
32+
?.takeIf { it.isNotEmpty() }
33+
val appVersionName =
34+
System.getenv("SPOO_VERSION_NAME")?.removePrefix("v")
35+
?: describedVersion
36+
// Positive versionCode floor: CI PR checkouts are shallow and
37+
// tagless, so describe can come up empty there.
38+
?: "0.0.1"
2439

2540
defaultConfig {
2641
applicationId = "me.spoo.android"

0 commit comments

Comments
 (0)