Skip to content

Commit 1d293ed

Browse files
committed
refactor: integrate auto version update into release workflow
- Removes separate version-change-trigger.yml workflow - Adds auto version update step directly in release.yml prepare job - Automatically updates config.gradle when tag version differs - Ensures all build jobs use updated version from main branch - Prevents version mismatch issues like the v2.3.4 incident - Simplifies release process - just create tag and everything updates automatically
1 parent e6843ed commit 1d293ed

File tree

2 files changed

+47
-95
lines changed

2 files changed

+47
-95
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ jobs:
3838
runs-on: ubuntu-latest
3939
outputs:
4040
version: ${{ steps.version.outputs.version }}
41-
version_code: ${{ steps.version_info.outputs.version_code }}
41+
version_code: ${{ steps.auto_update.outputs.version_code }}
4242

4343
steps:
4444
- name: Checkout code
4545
uses: actions/checkout@v4
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
ref: main
49+
fetch-depth: 0
4650

4751
- name: Determine version
4852
id: version
@@ -55,13 +59,45 @@ jobs:
5559
echo "version=$VERSION" >> $GITHUB_OUTPUT
5660
echo "Version: $VERSION"
5761
58-
- name: Extract version code
59-
id: version_info
62+
- name: Auto update version in config.gradle
63+
id: auto_update
6064
run: |
61-
# Extract version code from config.gradle
62-
VERSION_CODE=$(grep "versionCode:" config.gradle | sed 's/.*versionCode: \([0-9]*\).*/\1/')
63-
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
64-
echo "Version Code: $VERSION_CODE"
65+
VERSION="${{ steps.version.outputs.version }}"
66+
VERSION_NAME="${VERSION#v}" # Remove 'v' prefix if present
67+
68+
# Get current version info from config.gradle
69+
CURRENT_VERSION=$(grep versionName config.gradle | cut -d'"' -f2)
70+
CURRENT_CODE=$(grep versionCode config.gradle | grep -o '[0-9]*')
71+
72+
echo "Current version: $CURRENT_VERSION (code: $CURRENT_CODE)"
73+
echo "Target version: $VERSION_NAME"
74+
75+
# Check if version needs updating
76+
if [ "$CURRENT_VERSION" = "$VERSION_NAME" ]; then
77+
echo "✅ Version already matches $VERSION_NAME"
78+
echo "version_code=$CURRENT_CODE" >> $GITHUB_OUTPUT
79+
echo "updated=false" >> $GITHUB_OUTPUT
80+
else
81+
# Auto-increment version code
82+
NEW_CODE=$((CURRENT_CODE + 1))
83+
echo "📝 Updating version to $VERSION_NAME (code: $NEW_CODE)"
84+
85+
# Update config.gradle
86+
sed -i "s/versionCode: [0-9]*/versionCode: $NEW_CODE/" config.gradle
87+
sed -i "s/versionName: \"[^\"]*\"/versionName: \"$VERSION_NAME\"/" config.gradle
88+
89+
# Commit and push the changes
90+
git config user.name "github-actions[bot]"
91+
git config user.email "github-actions[bot]@users.noreply.github.com"
92+
93+
git add config.gradle
94+
git commit -m "chore: auto-update version to $VERSION_NAME (code: $NEW_CODE) [skip ci]"
95+
git push origin main
96+
97+
echo "✅ Version updated and pushed to main"
98+
echo "version_code=$NEW_CODE" >> $GITHUB_OUTPUT
99+
echo "updated=true" >> $GITHUB_OUTPUT
100+
fi
65101
66102
build-apk:
67103
name: Build Release APK
@@ -71,6 +107,8 @@ jobs:
71107
steps:
72108
- name: Checkout code
73109
uses: actions/checkout@v4
110+
with:
111+
ref: main # Always use main branch with updated version
74112

75113
- name: Set up JDK 17
76114
uses: actions/setup-java@v4
@@ -146,6 +184,8 @@ jobs:
146184
steps:
147185
- name: Checkout code
148186
uses: actions/checkout@v4
187+
with:
188+
ref: main # Always use main branch with updated version
149189

150190
- name: Set up JDK 17
151191
uses: actions/setup-java@v4

.github/workflows/version-change-trigger.yml

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)