Skip to content

Commit 6fc3519

Browse files
authored
chore(versionCode): add automated increase
1 parent f1d5db3 commit 6fc3519

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Update versionCode in Release PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled]
6+
branches: [ "main" ]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
set-versioncode:
13+
# Only run on Release PRs opened by release-please (they carry this label)
14+
if: contains(join(fromJson(toJson(github.event.pull_request.labels)).*.name, ','), 'autorelease: pending')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.event.pull_request.head.ref }}
21+
repository: ${{ github.event.pull_request.head.repo.full_name }}
22+
fetch-depth: 0
23+
24+
- name: Compute versionCode from semver in manifest
25+
run: |
26+
# Read the next version from release-please manifest in the PR
27+
VER=$(jq -r '."."' .github/.release-please-manifest.json)
28+
echo "Next version is: $VER"
29+
30+
# Extract MAJOR.MINOR.PATCH (ignore prerelease/build metadata if present)
31+
if [[ "$VER" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
32+
MAJOR=${BASH_REMATCH[1]}
33+
MINOR=${BASH_REMATCH[2]}
34+
PATCH=${BASH_REMATCH[3]}
35+
else
36+
echo "Could not parse semver from: $VER"
37+
exit 1
38+
fi
39+
40+
# Monotonic integer strategy for Google Play:
41+
# versionCode = MAJOR*10000 + MINOR*100 + PATCH (e.g., 2.3.4 -> 20304)
42+
CODE=$((MAJOR*10000 + MINOR*100 + PATCH))
43+
echo "Computed versionCode: $CODE"
44+
45+
echo $CODE > versionCode.txt
46+
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
49+
git add versionCode.txt
50+
git commit -m "chore(android): set versionCode $CODE for $VER" || echo "No changes to commit"
51+
git push

0 commit comments

Comments
 (0)