Skip to content

Commit 7bf2a3d

Browse files
committed
build: automate versioning via GitHub Actions
Configure build.gradle.kts to consume version values from environment variables and update the release workflow to calculate them dynamically based on run numbers.
1 parent 1bce9ec commit 7bf2a3d

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ jobs:
2929
with:
3030
fetch-depth: 0
3131

32-
- name: Extract Version
32+
- name: Compute and Increment Version
3333
id: version_step
3434
run: |
35+
RUN_NUM="${{ github.run_number }}"
36+
CALC_CODE=$((100 + RUN_NUM))
37+
3538
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
3639
TAG="${{ github.ref_name }}"
3740
VER="${TAG#v}"
3841
elif [ -n "${{ inputs.tag_name }}" ]; then
3942
TAG="${{ inputs.tag_name }}"
4043
VER="${TAG#v}"
4144
else
42-
# Extract versionName from app/build.gradle.kts
43-
VER=$(grep 'versionName = ' app/build.gradle.kts | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')
45+
VER="1.0.${CALC_CODE}"
4446
TAG="v${VER}"
4547
fi
48+
49+
echo "APP_VERSION_CODE=${CALC_CODE}" >> $GITHUB_ENV
50+
echo "APP_VERSION_NAME=${VER}" >> $GITHUB_ENV
4651
echo "tag=${TAG}" >> $GITHUB_OUTPUT
4752
echo "version=${VER}" >> $GITHUB_OUTPUT
48-
echo "Target Tag: ${TAG} (Version: ${VER})"
53+
echo "version_code=${CALC_CODE}" >> $GITHUB_OUTPUT
54+
echo "Target Tag: ${TAG} (Version Name: ${VER}, Version Code: ${CALC_CODE})"
4955
5056
- name: Set up JDK 21
5157
uses: actions/setup-java@v5

app/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ android {
99
namespace = "com.example"
1010
compileSdk { version = release(36) { minorApiLevel = 1 } }
1111

12+
val envVersionCode = System.getenv("APP_VERSION_CODE")?.toIntOrNull() ?: 108
13+
val envVersionName = System.getenv("APP_VERSION_NAME") ?: "1.0.108"
14+
1215
defaultConfig {
1316
applicationId = "com.aistudio.browser.lwbxbz"
1417
minSdk = 24
1518
targetSdk = 36
16-
versionCode = 8
17-
versionName = "1.0.8"
19+
versionCode = envVersionCode
20+
versionName = envVersionName
1821

1922
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2023
}

0 commit comments

Comments
 (0)