-
Notifications
You must be signed in to change notification settings - Fork 1
fix: tagged checkouts learn their version from git describe #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,25 @@ android { | |
| namespace = "me.spoo.android" | ||
| compileSdk = 37 | ||
|
|
||
| // The git tag is the version: CI passes it in, and local or PR builds | ||
| // fall back to the dev value below. The code is derived from the name | ||
| // so it can only ever go up. | ||
| val appVersionName = System.getenv("SPOO_VERSION_NAME")?.removePrefix("v") ?: "0.1.0" | ||
| // The git tag is the version: CI passes it in before the tag exists, | ||
| // and any tagged checkout (F-Droid builders included) learns it from | ||
| // git describe, so nothing is ever committed back. The code is derived | ||
| // from the name so it can only ever go up. | ||
| val describedVersion = | ||
| providers | ||
| .exec { | ||
| commandLine("git", "describe", "--tags", "--match", "v*") | ||
| isIgnoreExitValue = true | ||
| }.standardOutput.asText | ||
| .map { it.trim().removePrefix("v").substringBefore("-") } | ||
| .orNull | ||
| ?.takeIf { it.isNotEmpty() } | ||
| val appVersionName = | ||
| System.getenv("SPOO_VERSION_NAME")?.removePrefix("v") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- app/build.gradle.kts (target region) ---'
sed -n '24,42p' app/build.gradle.kts
printf '%s\n' '--- versionName references ---'
rg -n -C 3 'versionName|SPOO_VERSION_NAME|removePrefix' app/build.gradle.ktsRepository: spoo-me/spoo-android Length of output: 1529 Treat blank environment overrides as absent. Line 34 uses any defined 🤖 Prompt for AI Agents |
||
| ?: describedVersion | ||
| // Positive versionCode floor: CI PR checkouts are shallow and | ||
| // tagless, so describe can come up empty there. | ||
| ?: "0.0.1" | ||
|
|
||
| defaultConfig { | ||
| applicationId = "me.spoo.android" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: spoo-me/spoo-android
Length of output: 3132
🏁 Script executed:
Repository: spoo-me/spoo-android
Length of output: 641
🌐 Web query:
Gradle ProviderFactory.exec ExecOutput standardOutput asText orNull process start failure isIgnoreExitValue official documentation💡 Result:
In Gradle, when using
ProviderFactory.execto execute an external process, theExecOutputinterface provides lazy access to the process output [1][2]. If the executed process finishes with a non-zero exit code, callingget()on the provider returned bystandardOutput.asTextwill throw an exception by default [3]. This occurs becauseExecOutputdefaults to throwing an exception for non-zero exit values [4][5][6]. To read the standard output even when the process returns a non-zero exit code, you must explicitly configureignoreExitValue = truewithin theexecaction [3]: providerFactory.exec { commandLine 'your-command' ignoreExitValue = true } WhenignoreExitValueis set totrue, the provider returned byasTextwill successfully return the output content regardless of the exit status [3]. You can then check the actual execution result by accessingresult.get().exitValue[3]. Regarding process start failures (e.g., the executable cannot be found or started), the Gradle documentation specifies that if starting the process results in an exception, that exception is permanently propagated to callers ofProvider.get(),Provider.getOrElse(),Provider.getOrNull(), andProvider.isPresent()[1][7][8]. This means any attempt to resolve the provider will re-throw the original error that prevented the process from starting [1][8].Citations:
Make the Git lookup conditional and handle process-start failures.
orNullresolvesproviders.execbeforeSPOO_VERSION_NAMEis read, so Gradle startsgiteven when the override is set.isIgnoreExitValue = truehandles non-zero exits only; it does not handle process-start failures. Resolve Git only when the override is absent and catch start failures soSPOO_VERSION_NAME=1.2.3and the"0.0.0"fallback remain usable without Git.🤖 Prompt for AI Agents