From a12bd4837e51f4172b8c1e27e58a694f16d7ce18 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Apr 2026 11:46:00 +0000 Subject: [PATCH 1/2] build: derive version from git tags via axion-release versionName now comes from the latest v* git tag (project.version) and versionCode is the git rev-list --count HEAD commit count. CI checkouts use fetch-depth: 0 so tags and full history are visible to both axion-release and rev-list. --- .github/workflows/ci.yml | 3 +++ .github/workflows/release.yml | 3 +++ AGENTS.md | 2 +- app/build.gradle.kts | 9 ++++++--- build.gradle.kts | 13 +++++++++++++ gradle/libs.versions.toml | 2 ++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b39589..4c4ab2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up JDK 17 uses: actions/setup-java@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b449871..2e2cc03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up JDK 17 uses: actions/setup-java@v4 diff --git a/AGENTS.md b/AGENTS.md index 0004bd4..3a1c935 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ Toolchain: JDK 17, Android SDK platform 36 (`compileSdk`/`targetSdk`), `minSdk = - `./gradlew testDebugUnitTest` — unit tests (currently no test sources exist; CI runs the task anyway to catch new ones) - Single-module variants: `./gradlew :feature:timer:lintDebug`, `./gradlew :core:service:testDebugUnitTest`, etc. -`versionCode` in `app/build.gradle.kts` follows the schema `major*100_000 + minor*1_000 + patch*10`; the last digit is reserved for hotfixes. Bump both `versionCode` and `versionName` together. Release tags named `v*` trigger `.github/workflows/release.yml`, which builds a signed APK and publishes a GitHub Release. +Versioning is dynamic via the [axion-release](https://github.com/allegro/axion-release-plugin) plugin (applied at the root). `versionName` is derived from the latest `v*` git tag (`project.version`); `versionCode` is the `git rev-list --count HEAD` commit count. Don't hand-edit either field in `app/build.gradle.kts`. To cut a release, push a new `v` tag — `.github/workflows/release.yml` builds a signed APK and publishes the GitHub Release. CI checkouts must use `fetch-depth: 0` so tags and full history are visible. ## Module architecture diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b585c85..79a5ba3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,6 +6,10 @@ plugins { alias(libs.plugins.ksp) } +val gitCommitCount: Provider = providers.exec { + commandLine("git", "rev-list", "--count", "HEAD") +}.standardOutput.asText.map { it.trim().toInt() } + android { namespace = "dev.xitee.sleeptimer" compileSdk = 36 @@ -14,9 +18,8 @@ android { applicationId = "dev.xitee.sleeptimer" minSdk = 26 targetSdk = 36 - // Schema: major * 100000 + minor * 1000 + patch * 10 (last digit reserved for hotfixes) - versionCode = 1 * 100000 + 0 * 1000 + 1 * 10 - versionName = "1.0.1" + versionCode = gitCommitCount.get() + versionName = project.version.toString() } signingConfigs { diff --git a/build.gradle.kts b/build.gradle.kts index a73cca7..de008c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,4 +5,17 @@ plugins { alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.hilt.android) apply false alias(libs.plugins.ksp) apply false + alias(libs.plugins.axion.release) +} + +scmVersion { + tag { + prefix.set("v") + } +} + +val resolvedScmVersion: String = scmVersion.version + +allprojects { + version = resolvedScmVersion } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6eee6f9..b6a2402 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,6 +12,7 @@ androidxCoreKtx = "1.18.0" androidxActivityCompose = "1.13.0" kotlinxSerializationJson = "1.11.0" shizuku = "13.1.5" +axionRelease = "1.18.16" [libraries] androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } @@ -49,3 +50,4 @@ kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "ko kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +axion-release = { id = "pl.allegro.tech.build.axion-release", version.ref = "axionRelease" } From 917d980c7f3f8f7f665fd6e078bbc51e8192ab68 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Apr 2026 11:54:31 +0000 Subject: [PATCH 2/2] build: use rootProject.scmVersion in allprojects block Reads cleaner than capturing the version into a local val first; both forms resolve the extension on the root project. --- build.gradle.kts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index de008c1..43d18d2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,8 +14,6 @@ scmVersion { } } -val resolvedScmVersion: String = scmVersion.version - allprojects { - version = resolvedScmVersion + version = rootProject.scmVersion.version }