Skip to content

Commit 5c5383f

Browse files
bartvenemanclaude
andauthored
Automate package.json version bumping in release workflow (#190)
## Summary Updated the NPM publish workflow to automatically bump the version in `package.json` when a release is created, ensuring the published package version matches the git release tag. ## Key Changes - Updated permissions to allow writing to repository contents (required for pushing commits) - Removed outdated workflow comments - Added automated version bumping step that extracts version from release tag and updates `package.json` - Added commit and push step to persist version changes back to the main branch using GitHub Actions bot credentials - Version bump occurs before the build and publish steps to ensure consistency ## Implementation Details - Version is extracted from `github.event.release.tag_name` and the `v` prefix is stripped before applying to npm version command - Uses `npm version` with `--no-git-tag-version` flag to update version without creating duplicate git tags - Commits both `package.json` and `package-lock.json` to maintain lockfile consistency - Pushes changes directly to main branch after release creation https://claude.ai/code/session_01CAvVi3i1zrJrf1B7KsRj8o Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0832959 commit 5c5383f

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3-
41
name: NPM Publish
52

63
on:
@@ -9,7 +6,7 @@ on:
96

107
permissions:
118
id-token: write # Required for OIDC
12-
contents: read
9+
contents: write # Required to push version bump commit
1310

1411
jobs:
1512
publish-npm:
@@ -23,5 +20,16 @@ jobs:
2320
- run: npm install -g npm@latest
2421
- run: npm ci --ignore-scripts --no-audit --no-fund
2522
- run: npm test
23+
- name: Bump version in package.json
24+
run: |
25+
VERSION="${{ github.event.release.tag_name }}"
26+
npm version "${VERSION#v}" --no-git-tag-version
27+
- name: Commit and push version bump
28+
run: |
29+
git config user.name "github-actions[bot]"
30+
git config user.email "github-actions[bot]@users.noreply.github.com"
31+
git add package.json package-lock.json
32+
git commit -m "chore: bump version to ${{ github.event.release.tag_name }}"
33+
git push origin HEAD:main
2634
- run: npm run build
2735
- run: npm publish --access public

0 commit comments

Comments
 (0)