Skip to content

Commit 90d5fdd

Browse files
Refine version bump workflow to utilize three-dot diff for accurate change detection, ensuring only relevant production changes trigger version checks.
1 parent e756bd1 commit 90d5fdd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

.github/workflows/check-version-bump.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,23 @@ jobs:
2929
BASE_SHA: ${{ github.event.pull_request.base.sha }}
3030
run: |
3131
set -e
32-
# Skip version bump check when only test/docs/config files changed (no production code)
33-
if [ -n "$BASE_SHA" ]; then
34-
CHANGED=$(git diff --name-only "$BASE_SHA" HEAD 2>/dev/null || true)
32+
# Use three-dot diff so we only see changes introduced by the PR branch (works with merge commit checkout)
33+
DIFF_REF="${BASE_SHA}...HEAD"
34+
if [ -n "$BASE_SHA" ] && git rev-parse --verify "$BASE_SHA" >/dev/null 2>&1; then
35+
CHANGED=$(git diff --name-only "$DIFF_REF" 2>/dev/null || true)
3536
PROD_CHANGES=$(echo "$CHANGED" | grep -v -e '^test/' -e '^package\.json$' -e '^CHANGELOG\.md$' -e '^\.github/' -e '^README' -e '^\.' -e '^docs/' -e '^jest\.config' -e '^\.eslintrc' -e '^\.prettierrc' || true)
3637
PROD_CHANGES=$(echo "$PROD_CHANGES" | sed '/^$/d')
3738
if [ -z "$PROD_CHANGES" ]; then
3839
echo "Only test/docs/config files changed. Skipping version bump check."
3940
exit 0
4041
fi
4142
# Skip when only comments changed in production files (//, /*, *, */, #)
42-
if git diff "$BASE_SHA" HEAD | node -e "
43-
const lines = require('fs').readFileSync(0,'utf8').split('\n').filter(l=>l.startsWith('+')||l.startsWith('-'));
44-
const isComment = (s) => { const t=(s||'').slice(1).replace(/^\s+|\s+$/g,''); return !t || /^\/\//.test(t) || /^\/\*/.test(t) || /^\*\//.test(t) || /^\s*\*/.test(t) || /^#/.test(t); };
45-
const hasCode = lines.some(l => !isComment(l));
46-
process.exit(hasCode ? 1 : 0);
43+
if git diff "$DIFF_REF" 2>/dev/null | node -e "
44+
try {
45+
const lines = require('fs').readFileSync(0,'utf8').split('\n').filter(l=>l.startsWith('+')||l.startsWith('-'));
46+
const isComment = (s) => { const t=(s||'').slice(1).replace(/^\s+|\s+$/g,''); return !t || /^\/\//.test(t) || /^\/\*/.test(t) || /^\*\//.test(t) || /^\s*\*/.test(t) || /^#/.test(t); };
47+
process.exit(lines.length > 0 && !lines.some(l => !isComment(l)) ? 0 : 1);
48+
} catch(e) { process.exit(1); }
4749
" 2>/dev/null; then
4850
echo "Only comments changed in code. Skipping version bump check."
4951
exit 0

0 commit comments

Comments
 (0)