Automate manifest.json version updates during release #9
@@ -16,6 +16,15 @@ jobs:
|
|||||||
- name: Check out code
|
- name: Check out code
|
||||||
|
|
|||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Verify manifest version matches tag
|
||||||
|
run: |
|
||||||
|
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
||||||
|
MANIFEST_VERSION=$(grep -oP '"version"\s*:\s*"\K[^"]+' manifest.json)
|
||||||
|
if [ "$TAG_VERSION" != "$MANIFEST_VERSION" ]; then
|
||||||
|
echo "::error::Tag version ($TAG_VERSION) does not match manifest.json version ($MANIFEST_VERSION)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ release: test
|
|||||||
@if [[ ! "${V}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "Usage: make release V=X.X.X"; exit 1; fi
|
@if [[ ! "${V}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "Usage: make release V=X.X.X"; exit 1; fi
|
||||||
|
The shell variable Additionally, 
The shell variable `${V}` will not be expanded within single quotes. This will result in the literal string `"${V}"` being written to `manifest.json` instead of the version number. To fix this, you should use double quotes for the `sed` expression and escape the inner double quotes.
Additionally, `sed -i` behaves differently on GNU/Linux versus macOS/BSD systems. For better portability, you might consider a different approach in the future, but fixing the variable expansion is the critical part.
```
@sed -i "s/\"version\": *\"[^\"]*\"/\"version\": \"${V}\"/" manifest.json
```
`git push origin main v${V}` pushes the local `main` ref, but the release commit is created on the *current* checked-out branch. If the user runs `make release` from a branch other than `main`, the tag will point to the release commit but `origin/main` will not receive that commit (and could even push an outdated local `main`). Consider either enforcing/releases from `main` (fail if not on `main` and `git pull --ff-only`), or push `HEAD:main` alongside the tag so the commit you just made is what gets pushed.
The The `release` recipe uses bash-only syntax (`[[ ... ]]` / `=~`) and GNU `sed -i` semantics. Since the Makefile doesn’t set `SHELL := bash`, this target can fail on systems where `/bin/sh` is `dash` (common on Ubuntu) or where `sed -i` requires a backup suffix (macOS/BSD). Consider setting `SHELL := /usr/bin/env bash` (or rewriting to POSIX sh) and using a portable in-place edit approach for `manifest.json`.
|
|||||||
go mod tidy
|
go mod tidy
|
||||||
@if [ -n "`git status -s`" ]; then echo "\n\nThere are pending changes. Please commit or stash first"; exit 1; fi
|
@if [ -n "`git status -s`" ]; then echo "\n\nThere are pending changes. Please commit or stash first"; exit 1; fi
|
||||||
|
@# Update version in manifest.json
|
||||||
|
@sed -i 's/"version": *"[^"]*"/"version": "${V}"/' manifest.json
|
||||||
|
git add manifest.json
|
||||||
|
git commit -m "Release v${V}" --allow-empty --no-verify
|
||||||
git tag v${V}
|
git tag v${V}
|
||||||
git push origin v${V} --no-verify
|
git push origin main v${V} --no-verify
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
|
|||||||
MANIFEST_VERSIONis extracted viagrep -oPwith a PCRE-specific\K, which is brittle for JSON (and can fail if GNU grep isn’t built with PCRE support or if formatting changes). Consider parsingmanifest.jsonwith a JSON-aware tool (e.g.,jq -r .version manifest.jsonor a short Python snippet) to make this guard reliable.