Automate manifest.json version updates during release #9

Merged
deluan merged 6 commits from claude/automate-manifest-versioning-MJ9WM into main 2026-02-07 18:17:09 -07:00
3 changed files with 76 additions and 5 deletions
+63
View File
@@ -0,0 +1,63 @@
name: Create Release
copilot-pull-request-reviewer[bot] commented 2026-02-07 15:53:34 -07:00 (Migrated from github.com)
Review

git commit -m "Release v..." will fail the workflow if manifest.json already contains the requested version (nothing to commit), which can happen if the workflow is re-run or the input matches the current version. Consider guarding with a diff check and skipping the commit when unchanged, or adding --allow-empty if an empty release commit is acceptable.

                  git commit --allow-empty -m "Release v${{ inputs.version }}"
`git commit -m "Release v..."` will fail the workflow if `manifest.json` already contains the requested version (nothing to commit), which can happen if the workflow is re-run or the input matches the current version. Consider guarding with a diff check and skipping the commit when unchanged, or adding `--allow-empty` if an empty release commit is acceptable. ```suggestion git commit --allow-empty -m "Release v${{ inputs.version }}" ```
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 1.2.3, without the 'v' prefix)"
required: true
type: string
permissions:
contents: write
jobs:
create-release:
name: Create Release Tag
runs-on: ubuntu-latest
steps:
- name: Validate version format
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "::error::Invalid version format '$VERSION'. Use X.X.X (e.g., 1.2.3)"
exit 1
fi
- name: Check out code
uses: actions/checkout@v5
- name: Check tag does not already exist
env:
VERSION: ${{ inputs.version }}
run: |
if git ls-remote --tags origin "refs/tags/v${VERSION}" | grep -q .; then
echo "::error::Tag v${VERSION} already exists"
exit 1
fi
copilot-pull-request-reviewer[bot] commented 2026-02-07 15:53:33 -07:00 (Migrated from github.com)
Review

This step runs git ls-remote ... origin ... before the repository is checked out, so it will fail with “not a git repository” / no origin remote. Move the “Check out code” step before this, or use the GitHub API to check for an existing tag.

This step runs `git ls-remote ... origin ...` before the repository is checked out, so it will fail with “not a git repository” / no `origin` remote. Move the “Check out code” step before this, or use the GitHub API to check for an existing tag.
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: go test -race ./...
- name: Update manifest.json version
env:
VERSION: ${{ inputs.version }}
run: |
jq --arg v "$VERSION" '.version = $v' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
- name: Commit, tag, and push
env:
VERSION: ${{ inputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add manifest.json
git commit --allow-empty -m "Release v${VERSION}"
git tag "v${VERSION}"
git push origin main "v${VERSION}"
+9
View File
@@ -16,6 +16,15 @@ jobs:
- name: Check out code
copilot-pull-request-reviewer[bot] commented 2026-02-07 15:53:33 -07:00 (Migrated from github.com)
Review

MANIFEST_VERSION is extracted via grep -oP with 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 parsing manifest.json with a JSON-aware tool (e.g., jq -r .version manifest.json or a short Python snippet) to make this guard reliable.

                  MANIFEST_VERSION=$(jq -r '.version' manifest.json)
`MANIFEST_VERSION` is extracted via `grep -oP` with 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 parsing `manifest.json` with a JSON-aware tool (e.g., `jq -r .version manifest.json` or a short Python snippet) to make this guard reliable. ```suggestion MANIFEST_VERSION=$(jq -r '.version' manifest.json) ```
uses: actions/checkout@v5
- name: Verify manifest version matches tag
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
MANIFEST_VERSION=$(jq -r .version 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
uses: actions/setup-go@v5
with:
+4 -5
View File
@@ -1,3 +1,4 @@
SHELL := /usr/bin/env bash
.PHONY: test build package clean
PLUGIN_NAME := discord-rich-presence
@@ -15,10 +16,8 @@ package: build
clean:
rm -f $(WASM_FILE) $(PLUGIN_NAME).ndp
release: test
release:
gemini-code-assist[bot] commented 2026-02-07 15:50:48 -07:00 (Migrated from github.com)
Review

critical

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
![critical](https://www.gstatic.com/codereviewagent/critical.svg) 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 ```
copilot-pull-request-reviewer[bot] commented 2026-02-07 15:53:32 -07:00 (Migrated from github.com)
Review

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.

`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.
copilot-pull-request-reviewer[bot] commented 2026-02-07 15:53:33 -07:00 (Migrated from github.com)
Review

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.

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`.
@if [[ ! "${V}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "Usage: make release V=X.X.X"; exit 1; fi
go mod tidy
@if [ -n "`git status -s`" ]; then echo "\n\nThere are pending changes. Please commit or stash first"; exit 1; fi
git tag v${V}
git push origin v${V} --no-verify
gh workflow run create-release.yml -f version=${V}
@echo "Release v${V} workflow triggered. Check progress: gh run list --workflow=create-release.yml"
.PHONY: release