@@ -14,24 +14,26 @@ jobs:
1414 fetch-depth : 0
1515 - uses : actions/setup-node@v6
1616 with :
17- node-version : " 22"
18- - run : sudo npm install --global @commitlint/{config-conventional,cli}@20
17+ node-version : " lts/*"
18+ # Local node_modules so "@..." in .commitlintrc.json resolves (global install does not).
19+ - name : Install commitlint
20+ run : npm install --no-package-lock @commitlint/cli@17 @commitlint/config-conventional@17
1921 - if : github.event_name == 'pull_request'
2022 name : commitlint (pr)
21- run : commitlint -V --from HEAD~${{ github.event.pull_request.commits }}
23+ run : npx commitlint -V --from HEAD~${{ github.event.pull_request.commits }}
2224 - if : github.event_name == 'push' && !startsWith(github.ref, 'refs/tags')
2325 name : commitlint (push)
24- # use .before instead of HEAD~1 so that pushes with multiple commits are completely covered as well
25- # --from is not inclusive, so HEAD~1 will only analyze HEAD
26- # BUT:
27- # check if commit exists first (e.g. it doesn't if it was force pushed)
28- # or fall back to HEAD~1
26+ # Prefer github.event.before so multi-commit pushes are all checked; if that ref is gone
27+ # (force push, or all-zero before on new branch), fall back to HEAD~1.
2928 run : |
30- git cat-file -t ${{ github.event.before }} > /dev/null || COMMIT_NOT_FOUND=true
31- if [[ -z "$COMMIT_NOT_FOUND" ]]; then
32- commitlint -V --from ${{ github.event.before }}
29+ set -euo pipefail
30+ BEFORE="${{ github.event.before }}"
31+ if [[ "$BEFORE" =~ ^0+$ ]]; then
32+ npx commitlint -V --from HEAD~1
33+ elif git rev-parse --verify "${BEFORE}^{commit}" >/dev/null 2>&1; then
34+ npx commitlint -V --from "$BEFORE"
3335 else
34- commitlint -V --from HEAD~1
36+ npx commitlint -V --from HEAD~1
3537 fi
3638
3739 release :
0 commit comments