pre_commit_check.yml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. name: Check pre-commit rules
  2. on:
  3. pull_request:
  4. types: [opened, reopened, synchronize]
  5. permissions:
  6. contents: read
  7. jobs:
  8. pre_commit_check:
  9. runs-on: ubuntu-latest
  10. steps:
  11. - name: Checkout
  12. uses: actions/checkout@v2
  13. - name: Fetch head and base refs
  14. # This is necessary for pre-commit to check the changes in the PR branch
  15. run: |
  16. git fetch origin ${{ github.base_ref }}:base_ref
  17. git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_ref
  18. - name: Set up Python environment
  19. uses: actions/setup-python@master
  20. with:
  21. python-version: v3.8
  22. - name: Install python packages
  23. run: |
  24. pip install pre-commit
  25. pre-commit install-hooks
  26. - name: Run pre-commit and check for any changes
  27. run: |
  28. echo "Commits being checked:"
  29. git log --oneline --no-decorate base_ref..pr_ref
  30. echo ""
  31. if ! pre-commit run --from-ref base_ref --to-ref pr_ref --show-diff-on-failure ; then
  32. echo ""
  33. echo "::notice::It looks like the commits in this PR have been made without having pre-commit hooks installed."
  34. echo "::notice::Please see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/contribute/install-pre-commit-hook.html for instructions."
  35. echo ""
  36. exit 1
  37. fi