Skip to content

Commit 1218ee7

Browse files
committed
Use branch tag for versioning
1 parent a2e9ff2 commit 1218ee7

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616

1717
- name: JDK setup
18-
uses: actions/setup-java@v3
18+
uses: actions/setup-java@v4
1919
with:
2020
java-version: 20
2121
distribution: corretto
@@ -24,14 +24,43 @@ jobs:
2424
- name: Setup Gradle
2525
uses: gradle/gradle-build-action@v2
2626

27+
- name: Derive versionName / versionCode
28+
id: ver
29+
shell: bash
30+
run: |
31+
# versionName
32+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
33+
VERSION_NAME="${GITHUB_REF#refs/tags/v}" # v1.4.2 -> 1.4.2
34+
else
35+
LAST_TAG="$(git describe --tags --abbrev=0 2>/dev/null || echo v0.0.0)"
36+
VERSION_NAME="${LAST_TAG#v}-SNAPSHOT+${GITHUB_SHA::7}"
37+
fi
38+
39+
# A) From SemVer (x.y.z -> x*10000 + y*100 + z)
40+
MAJOR="${VERSION_NAME%%.*}"; rest="${VERSION_NAME#*.}"
41+
MINOR="${rest%%.*}"; PATCH="${rest#*.}"
42+
PATCH="${PATCH%%-*}" # strip -SNAPSHOT if present
43+
if [[ "$MAJOR" =~ ^[0-9]+$ && "$MINOR" =~ ^[0-9]+$ && "$PATCH" =~ ^[0-9]+$ ]]; then
44+
VC=$((10#${MAJOR}*10000 + 10#${MINOR}*100 + 10#${PATCH}))
45+
else
46+
# B) Fallback for snapshots: time-based code (UTC yyyymmddHH)
47+
VC="$(date -u +%Y%m%d%H)"
48+
fi
49+
50+
echo "version_name=${VERSION_NAME}" >> $GITHUB_OUTPUT
51+
echo "version_code=${VC}" >> $GITHUB_OUTPUT
52+
2753
- name: Assemble Release Bundle
2854
env:
2955
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
3056
GOOGLE_SERVER_CLIENT_ID: ${{ secrets.GOOGLE_SERVER_CLIENT_ID }}
3157
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
3258
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
3359
run: |
34-
./gradlew bundleRelease
60+
./gradlew \
61+
-PVERSION_NAME="${{ steps.ver.outputs.version_name }}" \
62+
-PVERSION_CODE="${{ steps.ver.outputs.version_code }}" \
63+
bundleRelease
3564
3665
- name: Sign Release
3766
uses: r0adkll/sign-android-release@v1

composeApp/build.gradle.kts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,15 @@ kotlin {
257257
}
258258
}
259259

260-
val projectVersionName = project.findProperty("app.morestuff.versionName") as? String
261-
?: error("versionName undefined!")
262-
val projectVersionCode = (project.findProperty("app.morestuff.versionCode") as? String)?.toInt()
263-
?: error("versionCode undefined!")
260+
val projectVersionName =
261+
providers.gradleProperty("VERSION_NAME").orNull
262+
?: project.findProperty("app.morestuff.versionName") as? String
263+
?: error("versionName undefined!")
264+
265+
val projectVersionCode =
266+
providers.gradleProperty("VERSION_CODE").orNull?.toInt()
267+
?: (project.findProperty("app.morestuff.versionCode") as? String)?.toInt()
268+
?: error("versionCode undefined!")
264269

265270
buildConfig {
266271

0 commit comments

Comments
 (0)