Skip to content

Commit

Permalink
Add a little check to make sure the pre-commit hooks ran as expected
Browse files Browse the repository at this point in the history
I've made this into a comment rather than a failing check, because
I've noticed instances where the pre-commit hook doesn't do the right
thing.

For example, djhtml refuses to process templates/navigation.html,
because it contains a long line. This is because the crown logo SVG from
the header contains a very long path attribute.
  • Loading branch information
MatMoore committed Jun 26, 2024
1 parent 3ce1b39 commit afc4810
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/check-pre-commit-has-been-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check pre-commit hooks ran

on:
- push

jobs:
check-precommit-hook:
runs-on: ubuntu-latest

steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.11.1

- name: Install pre-commit
run: pip install pre-commit

- name: Check that the pre-commit hook has been run
id: check
run: |
set +e
output=$(pre-commit run --from-ref origin/HEAD --to-ref HEAD 2>&1)
exit_code=$?
set -e
if [[ $exit_code -eq 0 ]]; then
echo "Pre-commit hook ran successfully"
else
PR_NUMBER=${{ github.event.pull_request.number }}
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
COMMENT="⚠️ Make sure you have [pre-commit](https://pre-commit.com]) installed.\n\npre-commit output: ${output}"
echo $output
gh pr comment $COMMENT_URL "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}" -b $COMMENT
fi

0 comments on commit afc4810

Please sign in to comment.