Skip to content

Commit 1ca0268

Browse files
feat(release): auto-set versionName from tag on release builds (#168)
* feat(release): auto-set versionName from tag on release builds * fix(release): replace broken sed with workflow_dispatch release flow The 'Set versionName from tag' sed regex introduced in this PR had a bug: the substitution matched up to but not including the closing quote of the existing versionName, so after substitution the line became versionName '0.x.y'" (dangling closing quote), a Groovy syntax error that breaks Gradle. F-Droid also requires the correct versionName in the committed source that the tag points to, so patching it post-checkout never helped there. Fix: revert the verify-before-tag step from #155, and add a new .github/workflows/release.yml with a workflow_dispatch trigger that does the whole release atomically: 1. Validates the version format and that the tag does not exist yet 2. Updates versionName in mobile/build.gradle with a correct sed that consumes both surrounding quotes (no dangling characters) 3. Commits the change and pushes a signed annotated tag 4. The tag push (via RELEASE_PAT) triggers the Build workflow This satisfies F-Droid: the tag now always points to a commit where the versionName matches. Requires a RELEASE_PAT secret (repo-scoped GitHub PAT) — documented in README and release.yml.
1 parent e9e3615 commit 1ca0268

3 files changed

Lines changed: 89 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,18 @@ jobs:
223223
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
224224
run: |
225225
SHORT_VERSION="${GITHUB_REF_NAME#v}"
226-
COMMITTED_VERSION=$(sed -n -E "s/^[[:space:]]*versionName[[:space:]]+['\"]([^'\"]+)['\"].*/\\1/p" mobile/build.gradle)
226+
COMMITTED_VERSION=$(sed -n -E "s/^[[:space:]]*versionName[[:space:]]+['\"]([^'\"]+)['\"].*/\1/p" mobile/build.gradle)
227227
if [ -z "$COMMITTED_VERSION" ]; then
228228
echo "Failed to parse versionName from mobile/build.gradle."
229229
exit 1
230230
fi
231231
if [ "$COMMITTED_VERSION" != "$SHORT_VERSION" ]; then
232232
echo "mobile/build.gradle versionName must match the release tag."
233+
echo "Use the Release workflow (workflow_dispatch) to bump, commit, and tag in one step."
233234
echo "tag=$SHORT_VERSION committed=$COMMITTED_VERSION"
234235
exit 1
235236
fi
236-
237+
echo "versionName ${COMMITTED_VERSION} matches tag ${GITHUB_REF_NAME}"
237238
- name: Set versionCode
238239
run: |
239240
# Sets versionCode

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release
2+
3+
# Full release workflow: bumps versionName in source, commits, tags, and pushes.
4+
# The tag push (via RELEASE_PAT) triggers the Build workflow automatically.
5+
#
6+
# Prerequisites:
7+
# - Add a RELEASE_PAT secret: a GitHub PAT with `repo` scope.
8+
# Using a PAT instead of GITHUB_TOKEN ensures the tag push triggers Build.
9+
#
10+
# Usage: Actions → Release → Run workflow → enter version (e.g. 0.12.2)
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
version:
16+
description: 'Version to release, without v prefix (e.g. 0.12.2)'
17+
required: true
18+
type: string
19+
20+
jobs:
21+
release:
22+
name: Bump versionName, commit, and tag
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
# RELEASE_PAT is a repo-scoped PAT; its pushes trigger the Build workflow.
31+
# Falls back to GITHUB_TOKEN (build won't auto-trigger, but tag is still created).
32+
token: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }}
33+
fetch-depth: 0
34+
35+
- name: Validate version format
36+
run: |
37+
VERSION="${{ inputs.version }}"
38+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
39+
echo "::error::Version must be X.Y.Z (e.g. 0.12.2). Got: ${VERSION}"
40+
exit 1
41+
fi
42+
if git rev-parse "refs/tags/v${VERSION}" >/dev/null 2>&1; then
43+
echo "::error::Tag v${VERSION} already exists."
44+
exit 1
45+
fi
46+
47+
- name: Bump versionName in mobile/build.gradle
48+
run: |
49+
VERSION="${{ inputs.version }}"
50+
# Replace quoted versionName value; works for both single and double quotes.
51+
sed -i -E "s/^([[:space:]]*versionName[[:space:]]+)[\"'][^\"']+[\"']/\1'${VERSION}'/" \
52+
mobile/build.gradle
53+
# Verify: the line must end with the closing quote (no dangling chars).
54+
grep -qE "^[[:space:]]*versionName[[:space:]]+'${VERSION}'[[:space:]]*$" \
55+
mobile/build.gradle || {
56+
echo "::error::versionName update failed. Current state:"
57+
grep "versionName" mobile/build.gradle
58+
exit 1
59+
}
60+
echo "Updated versionName to '${VERSION}'"
61+
62+
- name: Commit and tag
63+
run: |
64+
VERSION="${{ inputs.version }}"
65+
git config user.name "github-actions[bot]"
66+
git config user.email "github-actions[bot]@users.noreply.github.com"
67+
git add mobile/build.gradle
68+
git commit -m "chore: bump versionName to ${VERSION}"
69+
git tag -a "v${VERSION}" -m "Release v${VERSION}"
70+
git push origin HEAD:master
71+
git push origin "v${VERSION}"

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,26 @@ Once both aw-server-rust and aw-webui is built, you can build the Android app as
5757

5858
### Making a release
5959

60-
Before tagging, update `mobile/build.gradle` so `versionName` matches the
61-
release you are about to cut. The release workflow verifies the committed
62-
`versionName` instead of patching it after checkout, which keeps tagged source,
63-
GitHub release builds, and F-Droid builds on the same version.
60+
Use the **Release** workflow to bump the version, commit it, and create the
61+
tag in one atomic step. This ensures the committed `versionName` matches the
62+
tag (required for F-Droid, which builds from tagged source).
6463

65-
Then make a signed tag and push it to GitHub:
64+
1. Go to **Actions → Release → Run workflow**
65+
2. Enter the version number (e.g. `0.12.2`, without the `v` prefix)
66+
3. Click **Run workflow**
6667

67-
```sh
68-
git tag -s v0.1.0
69-
git push origin refs/tags/v0.1.0
70-
```
68+
The workflow will:
69+
- Update `versionName` in `mobile/build.gradle`
70+
- Commit the change to master
71+
- Create and push tag `v{version}`
72+
- Trigger the Build workflow (requires a `RELEASE_PAT` secret — a GitHub PAT with `repo` scope)
7173

7274
This will trigger a GitHub Actions workflow which will build the app and upload it to GitHub releases, and deploy it to the Play Store (including the metadata in `./fastlane/metadata/android`).
7375

76+
> **Note for maintainers:** Add a `RELEASE_PAT` secret (repo-scoped GitHub PAT) so
77+
> the tag push from the Release workflow triggers the Build workflow. Without it,
78+
> the Build workflow must be triggered manually after the tag is pushed.
79+
7480
## More info
7581

7682
For more info, check out the main [ActivityWatch repo](https://github.com/ActivityWatch/activitywatch).

0 commit comments

Comments
 (0)