feat(release): auto-set versionName from tag on release builds#168
Conversation
| sed -i -E "s/^([[:space:]]*)versionName[[:space:]]+[\"']([^\"']+)/\1versionName '${SHORT_VERSION}'/" mobile/build.gradle | ||
| # Verify the update | ||
| grep -qE "^[[:space:]]*versionName[[:space:]]+[\"']${SHORT_VERSION}[\"']" mobile/build.gradle || { | ||
| echo "Failed to update versionName in mobile/build.gradle." | ||
| exit 1 | ||
| fi | ||
| if [ "$COMMITTED_VERSION" != "$SHORT_VERSION" ]; then | ||
| echo "mobile/build.gradle versionName must match the release tag." | ||
| echo "tag=$SHORT_VERSION committed=$COMMITTED_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| } |
There was a problem hiding this comment.
sed pattern omits the closing quote, corrupting build.gradle
The regex ends after the version digits ([^\"']+) without consuming the original closing quote, so the substitution replaces only versionName "0.12.1 and leaves the trailing " in place. The resulting line becomes versionName '0.13.0'", which is a Groovy syntax error that will crash the Gradle parse step. The subsequent grep verification still passes because it only checks for versionName '${SHORT_VERSION}' and doesn't assert that nothing follows — so the broken file silently slips through.
Fix: extend the pattern to also match and discard the closing quote:
sed -i -E "s/^([[:space:]]*)versionName[[:space:]]+[\"'][^\"']+[\"']/\1versionName '${SHORT_VERSION}'/" mobile/build.gradle
| - name: Set versionName from tag | ||
| if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag | ||
| run: | | ||
| SHORT_VERSION="${GITHUB_REF_NAME#v}" | ||
| COMMITTED_VERSION=$(sed -n -E "s/^[[:space:]]*versionName[[:space:]]+['\"]([^'\"]+)['\"].*/\\1/p" mobile/build.gradle) | ||
| if [ -z "$COMMITTED_VERSION" ]; then | ||
| echo "Failed to parse versionName from mobile/build.gradle." | ||
| echo "Setting versionName to ${SHORT_VERSION} from tag ${GITHUB_REF_NAME}" | ||
| # Update versionName in mobile/build.gradle to match the tag | ||
| sed -i -E "s/^([[:space:]]*)versionName[[:space:]]+[\"']([^\"']+)/\1versionName '${SHORT_VERSION}'/" mobile/build.gradle | ||
| # Verify the update | ||
| grep -qE "^[[:space:]]*versionName[[:space:]]+[\"']${SHORT_VERSION}[\"']" mobile/build.gradle || { | ||
| echo "Failed to update versionName in mobile/build.gradle." | ||
| exit 1 | ||
| fi | ||
| if [ "$COMMITTED_VERSION" != "$SHORT_VERSION" ]; then | ||
| echo "mobile/build.gradle versionName must match the release tag." | ||
| echo "tag=$SHORT_VERSION committed=$COMMITTED_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| } | ||
| echo "versionName set to ${SHORT_VERSION}" |
There was a problem hiding this comment.
F-Droid compatibility broken by patching-in-CI approach
mobile/build.gradle still carries a comment explaining that versionName is kept committed in source precisely so "tagged builds and F-Droid agree" — F-Droid builds directly from the tagged commit without running the CI workflow, so it reads whatever versionName value was committed. Under the previous workflow the committed value was forced to match the tag, keeping both in sync. After this change the committed value is never updated, so F-Droid will always report the stale pre-tag version. The stale // Tag workflows verify it matches… comment in mobile/build.gradle also needs updating to reflect the new behaviour.
|
@TimeToBuildBob Not sure this is what I had in mind, as Greptile noticed. Need to figure out a way to make this work with e.g. F-Droid without having the tag point to a commit with the wrong versionName. Maybe skipping tag-pushes to release is a good idea, and instead do it all from a workflow_trigger which can run pre-release checks, commit, tag, and then trigger the build and deploy on that tagged release commit. |
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 ActivityWatch#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.
|
Redesigned per your feedback. The new approach: What changed (commit ac07957):
For F-Droid: the tag now always points to a commit where To release: Actions → Release → Run workflow → enter version (e.g. One-time setup needed: Add a |
|
@TimeToBuildBob merged, chase me to set the PAT |
|
Noted. I created a local follow-up task to chase this: Concrete ask when you have a minute: add a repo-scoped PAT as the |
|
Tracked in ErikBjare/bob#1020 — will chase you on setting the PAT once the queue clears. |
Automate the release process via
workflow_dispatchso the full release — version bump, commit, tag, and build trigger — happens in one atomic step.Problem with the previous approach (tag-push patching):
sedregex had a bug: it matched up to but not including the closing quote of the existingversionName, leaving a dangling"after substitution → Groovy syntax error, Gradle build failsNew approach:
.github/workflows/release.yml(workflow_dispatch) that:versionNameinmobile/build.gradlewith a correctsed(matches both surrounding quotes, no trailing characters)RELEASE_PATtriggers the Build workflowF-Droid compatibility: The tag now always points to a commit where
versionNameis correct in the source — because the Release workflow commits it before tagging.Usage: Actions → Release → Run workflow → enter version (e.g.
0.12.2)One-time setup: Add a
RELEASE_PATsecret (repo-scoped GitHub PAT). Required so the tag push triggers the Build workflow (GitHub restricts GITHUB_TOKEN pushes from triggering other workflows). Documented inrelease.ymland README.