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 (lib/, webpack/, dist/) require package.json + CHANGELOG.md.
3+ # Skips for: test-only, docs, .github (workflows/config).
24name : Check Version Bump
35
46on :
57 pull_request :
6- paths :
7- - ' package.json'
8- - ' CHANGELOG.md'
98
109jobs :
1110 version-bump :
@@ -17,12 +16,44 @@ jobs:
1716 with :
1817 fetch-depth : 0
1918
19+ - name : Detect changed files and version bump
20+ id : detect
21+ run : |
22+ if git rev-parse HEAD^2 >/dev/null 2>&1; then
23+ FILES=$(git diff --name-only HEAD^1 HEAD^2)
24+ else
25+ FILES=$(git diff --name-only HEAD~1 HEAD)
26+ fi
27+ VERSION_FILES_CHANGED=false
28+ echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true
29+ echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true
30+ echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT
31+ # Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not
32+ CODE_CHANGED=false
33+ echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true
34+ echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true
35+ echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT
36+
37+ - name : Skip when only test/docs/.github changed
38+ if : steps.detect.outputs.code_changed != 'true'
39+ run : |
40+ echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check."
41+ exit 0
42+
43+ - name : Fail when version bump was missed
44+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
45+ run : |
46+ 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."
47+ exit 1
48+
2049 - name : Setup Node
50+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
2151 uses : actions/setup-node@v4
2252 with :
2353 node-version : ' 22.x'
2454
2555 - name : Check version bump
56+ if : steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
2657 run : |
2758 set -e
2859 PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')")
0 commit comments