Skip to content

Commit 9454b4a

Browse files
committed
fix: commitlint breaks on force push commits
1 parent c01d223 commit 9454b4a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

.github/workflows/commitlint.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ jobs:
2424

2525
- if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags')
2626
name: commitlint (push)
27-
run: commitlint --from ${{ github.event.before }}
2827
# use .before instead of HEAD~1 so that pushes with multiple commits are completely covered as well
29-
# --from is not inclusive, so HEAD~1 will only analyze HEAD
28+
# --from is not inclusive, so HEAD~1 will only analyze HEAD
29+
# BUT:
30+
# check if commit exists first (e.g. it doesn't if it was force pushed)
31+
# or fall back to HEAD~1
32+
run: |
33+
git cat-file -t ${{ github.event.before }} > /dev/null
34+
if [[ $? -eq "0" ]]; then
35+
commitlint --from ${{ github.event.before }}
36+
else
37+
commitlint --from HEAD~1
38+
fi
39+

0 commit comments

Comments
 (0)