Skip to content

Commit c839299

Browse files
committed
fix(ci): run prek over all files when a push has no base commit
1 parent adeace4 commit c839299

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/prek-check.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ jobs:
4949

5050
- name: Run prek checks (push)
5151
if: github.event_name == 'push'
52-
run: prek run --from-ref ${{ github.event.before }} --to-ref ${{ github.event.after }} --show-diff-on-failure
52+
env:
53+
BEFORE: ${{ github.event.before }}
54+
AFTER: ${{ github.event.after }}
55+
run: |
56+
# A push that creates a branch reports an all-zero "before", and a
57+
# force-push can name one this clone no longer has. Neither is a commit,
58+
# so the range would be invalid; check every file instead.
59+
if git rev-parse --verify --quiet "$BEFORE^{commit}" >/dev/null; then
60+
prek run --from-ref "$BEFORE" --to-ref "$AFTER" --show-diff-on-failure
61+
else
62+
echo "no usable base commit ($BEFORE); checking all files"
63+
prek run --all-files --show-diff-on-failure
64+
fi

0 commit comments

Comments
 (0)