Skip to content

Add a little check to make sure the pre-commit hooks ran as expected #2

Add a little check to make sure the pre-commit hooks ran as expected

Add a little check to make sure the pre-commit hooks ran as expected #2

name: Check pre-commit hooks ran
on:
- pull_request
- push
jobs:
check-precommit-hook:
runs-on: ubuntu-latest
steps:
- name: Check that the pre-commit hook has been run
id: check
run: |
output=$(pre-commit run --from-ref origin/HEAD --to-ref HEAD 2>&1)
exit_code=$?
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