1- # Ensures package.json and CHANGELOG.md are bumped compared to the latest tag when relevant files change.
1+ # Catches when developers forget to add a version bump for their changes.
2+ # Code changes (e.g. lib/) require package.json + CHANGELOG.md; test-only or comment-only in lib/ skip.
23name : Check Version Bump
34
45on :
56 pull_request :
6- paths :
7- - ' package.json'
8- - ' CHANGELOG.md'
97
108jobs :
119 version-bump :
@@ -17,12 +15,43 @@ jobs:
1715 with :
1816 fetch-depth : 0
1917
18+ - name : Detect changed files and version bump
19+ id : detect
20+ run : |
21+ if git rev-parse HEAD^2 >/dev/null 2>&1; then
22+ FILES=$(git diff --name-only HEAD^1 HEAD^2)
23+ else
24+ FILES=$(git diff --name-only HEAD~1 HEAD)
25+ fi
26+ VERSION_FILES_CHANGED=false
27+ echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true
28+ echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true
29+ echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT
30+ CODE_CHANGED=false
31+ echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true
32+ echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true
33+ echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT
34+
35+ - name : Skip when only test/docs/config changed
36+ if : steps.detect.outputs.code_changed != 'true'
37+ run : |
38+ echo "No release-affecting files changed (e.g. only test/docs). Skipping version-bump check."
39+ exit 0
40+
41+ - name : Fail when version bump was missed
42+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
43+ run : |
44+ echo "::error::This PR has code changes but no version bump. Please bump the version in package.json and add an entry in CHANGELOG.md."
45+ exit 1
46+
2047 - name : Setup Node
48+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
2149 uses : actions/setup-node@v4
2250 with :
2351 node-version : ' 22.x'
2452
2553 - name : Check version bump
54+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
2655 run : |
2756 set -e
2857 PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')")
0 commit comments