Skip to content

Commit 9be1afb

Browse files
bartvenemanclaude
andauthored
Automate version bumping in release workflow (#169)
## Summary This PR updates the release workflow to automatically bump the package version during the release process, ensuring that version numbers in `package.json` and `package-lock.json` stay in sync with git tags. ## Key Changes - **Permission update**: Changed `contents` permission from `read` to `write` to allow the workflow to commit and push changes - **Version bumping**: Added a step to extract the version from the git tag (removing the `v` prefix) and update it in `package.json` - **Git commit**: Added a step to configure git user credentials and commit the version bump changes back to the main branch with a descriptive commit message ## Implementation Details - The version is extracted from `GITHUB_REF_NAME` environment variable using bash parameter expansion (`${GITHUB_REF_NAME#v}`) - Git configuration uses the GitHub Actions bot identity for commits - Both `package.json` and `package-lock.json` are committed to maintain lockfile consistency - The version bump occurs after tests pass but before the build and publish steps https://claude.ai/code/session_01MwzSa6WMkR5d7xy1nptdHZ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2558337 commit 9be1afb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
permissions:
1111
id-token: write # Required for OIDC
12-
contents: read
12+
contents: write
1313

1414
jobs:
1515
publish-npm:
@@ -23,5 +23,16 @@ jobs:
2323
- run: npm install -g npm@latest
2424
- run: npm ci --ignore-scripts --no-fund --no-audit
2525
- run: npm test
26+
- name: Bump version
27+
run: |
28+
VERSION=${GITHUB_REF_NAME#v}
29+
npm version $VERSION --no-git-tag-version
30+
- name: Commit and push version bump
31+
run: |
32+
git config user.name "github-actions[bot]"
33+
git config user.email "github-actions[bot]@users.noreply.github.com"
34+
git add package.json package-lock.json
35+
git commit -m "chore: bump version to ${GITHUB_REF_NAME#v}"
36+
git push origin HEAD:main
2637
- run: npm run build
2738
- run: npm publish --access public

0 commit comments

Comments
 (0)