Skip to content

Commit 30e1a79

Browse files
committed
build: automate versioning by injecting dynamic version name and code from CI environment variables
1 parent 4012e9e commit 30e1a79

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,22 @@ jobs:
3535
id: vars
3636
run: |
3737
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
38-
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
38+
RAW_VER="${{ inputs.version }}"
3939
else
40-
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
40+
RAW_VER="${{ github.ref_name }}"
4141
fi
42+
echo "version=$RAW_VER" >> $GITHUB_OUTPUT
43+
CLEAN_VER="${RAW_VER#v}"
44+
echo "version_clean=$CLEAN_VER" >> $GITHUB_OUTPUT
4245
4346
- name: Decode Keystore
4447
run: |
4548
echo "${{ secrets.SIGNING_KEY_STORE_BASE64 }}" | base64 --decode > release.keystore
4649
4750
- name: Build and Sign Release APK
4851
env:
52+
VERSION_NAME: ${{ steps.vars.outputs.version_clean }}
53+
VERSION_CODE: ${{ github.run_number }}
4954
KEYSTORE_FILE: ${{ github.workspace }}/release.keystore
5055
KEYSTORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
5156
KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId = "dev.e88e89.hdb"
1212
minSdk = 26
1313
targetSdk = 35
14-
versionCode = 1
15-
versionName = "1.0"
14+
versionCode = (project.findProperty("VERSION_CODE") as? String ?: System.getenv("VERSION_CODE"))?.toIntOrNull() ?: 1
15+
versionName = (project.findProperty("VERSION_NAME") as? String ?: System.getenv("VERSION_NAME")) ?: "1.0"
1616
resourceConfigurations += listOf("en", "zh-rTW")
1717
}
1818

0 commit comments

Comments
 (0)