Skip to content

Commit 77af289

Browse files
committed
Use git commit hash as config version marker
Replace the package version with the 12-char short commit hash as the config version marker. This ensures that any change to the default config triggers a reset — even between releases that share the same version number. build.rs emits LINUXDO_GIT_HASH (fallback: LINUXDO_BUILD_VERSION) at compile time. Android build.gradle.kts reads LINUXDO_GIT_HASH from the environment or falls back to `git rev-parse --short=12 HEAD`. Both release and edge CI workflows export LINUXDO_GIT_HASH=${GITHUB_SHA::12}.
1 parent 1ea61c4 commit 77af289

6 files changed

Lines changed: 36 additions & 2 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
fi
5959
echo "RELEASE_VERSION=${{ github.event.inputs.release_tag || github.ref_name }}" | sed 's/^RELEASE_VERSION=v/RELEASE_VERSION=/' >> "${GITHUB_ENV}"
6060
echo "LINUXDO_BUILD_VERSION=${{ github.event.inputs.release_tag || github.ref_name }}" | sed 's/^LINUXDO_BUILD_VERSION=v/LINUXDO_BUILD_VERSION=/' >> "${GITHUB_ENV}"
61+
echo "LINUXDO_GIT_HASH=${GITHUB_SHA::12}" >> "${GITHUB_ENV}"
6162
6263
- uses: dtolnay/rust-toolchain@stable
6364

@@ -148,6 +149,7 @@ jobs:
148149
fi
149150
echo "RELEASE_VERSION=${{ github.event.inputs.release_tag || github.ref_name }}" | sed 's/^RELEASE_VERSION=v/RELEASE_VERSION=/' >> "${GITHUB_ENV}"
150151
echo "LINUXDO_BUILD_VERSION=${{ github.event.inputs.release_tag || github.ref_name }}" | sed 's/^LINUXDO_BUILD_VERSION=v/LINUXDO_BUILD_VERSION=/' >> "${GITHUB_ENV}"
152+
echo "LINUXDO_GIT_HASH=${GITHUB_SHA::12}" >> "${GITHUB_ENV}"
151153
152154
- uses: actions/setup-java@v4
153155
with:

.github/workflows/publish-edge-pre-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
"$PYTHON_BIN" ./scripts/ci-sync-version.py
7373
echo "RELEASE_VERSION=${base_version}-edge.${GITHUB_RUN_NUMBER}" >> "${GITHUB_ENV}"
7474
echo "LINUXDO_BUILD_VERSION=${base_version}-edge.${GITHUB_RUN_NUMBER}" >> "${GITHUB_ENV}"
75+
echo "LINUXDO_GIT_HASH=${GITHUB_SHA::12}" >> "${GITHUB_ENV}"
7576
7677
- uses: dtolnay/rust-toolchain@stable
7778

@@ -174,6 +175,7 @@ jobs:
174175
"$PYTHON_BIN" ./scripts/ci-sync-version.py
175176
echo "RELEASE_VERSION=${base_version}-edge.${GITHUB_RUN_NUMBER}" >> "${GITHUB_ENV}"
176177
echo "LINUXDO_BUILD_VERSION=${base_version}-edge.${GITHUB_RUN_NUMBER}" >> "${GITHUB_ENV}"
178+
echo "LINUXDO_GIT_HASH=${GITHUB_SHA::12}" >> "${GITHUB_ENV}"
177179
178180
- uses: actions/setup-java@v4
179181
with:

android/app/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ val generatedAssetsDir = layout.buildDirectory.dir("generated/linuxdoAssets")
1111
val rustBinaryProvider = providers
1212
.environmentVariable("LINUXDO_ANDROID_RUST_BIN")
1313
.orElse(repoRoot.resolve("target/aarch64-linux-android/release/linuxdo-accelerator").absolutePath)
14+
val gitHash: String = providers.environmentVariable("LINUXDO_GIT_HASH").getOrElse(
15+
runCatching {
16+
val output = ByteArrayOutputStream()
17+
exec {
18+
commandLine("git", "rev-parse", "--short=12", "HEAD")
19+
workingDir(repoRoot)
20+
standardOutput = output
21+
}
22+
output.toString().trim().ifEmpty { null }
23+
}.getOrNull() ?: "unknown"
24+
)
1425

1526
android {
1627
namespace = "io.linuxdo.accelerator.android"
@@ -22,6 +33,7 @@ android {
2233
targetSdk = 35
2334
versionCode = 3
2435
versionName = "0.1.10-android"
36+
buildConfigField("String", "GIT_HASH", "\"$gitHash\"")
2537
}
2638

2739
buildTypes {

android/app/src/main/java/io/linuxdo/accelerator/android/LinuxdoBinary.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object LinuxdoBinary {
116116
val configFile = configFile(context)
117117
val markerFile = File(configFile.parentFile, "$CONFIG_NAME.version")
118118
val backupFile = File(configFile.parentFile, "$CONFIG_NAME.bak")
119-
val currentVersion = BuildConfig.VERSION_NAME
119+
val currentVersion = BuildConfig.GIT_HASH
120120

121121
if (configFile.exists()) {
122122
val markerVersion = readVersionMarker(markerFile)

build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ fn main() {
22
println!("cargo:rerun-if-changed=assets/icons/linuxdo.ico");
33
println!("cargo:rerun-if-env-changed=LINUXDO_BUILD_VERSION");
44
println!("cargo:rerun-if-env-changed=RELEASE_VERSION");
5+
println!("cargo:rerun-if-env-changed=LINUXDO_GIT_HASH");
6+
println!("cargo:rerun-if-changed=.git/HEAD");
7+
println!("cargo:rerun-if-changed=.git/refs");
58

69
let build_version = std::env::var("LINUXDO_BUILD_VERSION")
710
.ok()
@@ -19,6 +22,21 @@ fn main() {
1922
.unwrap_or_else(|| "0.0.0".to_string());
2023
println!("cargo:rustc-env=LINUXDO_BUILD_VERSION={build_version}");
2124

25+
let git_hash = std::env::var("LINUXDO_GIT_HASH")
26+
.ok()
27+
.filter(|value| !value.trim().is_empty())
28+
.unwrap_or_else(|| {
29+
std::process::Command::new("git")
30+
.args(["rev-parse", "--short=12", "HEAD"])
31+
.output()
32+
.ok()
33+
.filter(|output| output.status.success())
34+
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string())
35+
.filter(|value| !value.is_empty())
36+
.unwrap_or_else(|| build_version.clone())
37+
});
38+
println!("cargo:rustc-env=LINUXDO_GIT_HASH={git_hash}");
39+
2240
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
2341
let mut res = winresource::WindowsResource::new();
2442
res.set_icon("assets/icons/linuxdo.ico");

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{Context, Result, anyhow};
77
use serde::{Deserialize, Serialize};
88

99
const DEFAULT_APP_CONFIG: &str = include_str!("../assets/defaults/linuxdo-accelerator.toml");
10-
const CURRENT_CONFIG_VERSION: &str = env!("CARGO_PKG_VERSION");
10+
const CURRENT_CONFIG_VERSION: &str = env!("LINUXDO_GIT_HASH");
1111

1212
#[derive(Debug, Clone, Serialize, Deserialize)]
1313
pub struct AppConfig {

0 commit comments

Comments
 (0)