Skip to content

Commit

Permalink
Merge pull request #10 from minrk/pre-commit-ci
Browse files Browse the repository at this point in the history
run pre-commit on ci
  • Loading branch information
minrk authored Feb 5, 2024
2 parents c996fa5 + 6865c7b commit 7a3db73
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# run pre-commit
name: lint

on:
pull_request:

jobs:
lint:
permissions:
contents: read
pull-requests: write
runs-on: "ubuntu-22.04"
defaults:
run:
shell: /usr/bin/bash -o pipefail -u -e {0}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: "3.11"

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

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: setup pre-commit
run: |
pre-commit install-hooks
- name: run pre-commit
run: |
pre-commit run --color=always --from-ref '${{ github.event.pull_request.base.sha }}' --to-ref '${{ github.event.pull_request.head.sha }}' 2>&1 | tee pre-commit-output
- name: pre-commit tip
if: failure()
run: |
echo 'run `pre-commit run --all-files` and commit the resulting changes'
- name: render report (click Summary to view)
if: failure()
run: |
cat <<EOF >> report
## pre-commit failed
Run \`pre-commit run --all-files\` to check for errors.
Usually, these will just be auto-formatting changes,
which you can commit and push.
You can install the pre-commit hooks with:
\`\`\`
pip install pre-commit
pre-commit install
\`\`\`
pre-commit output:
\`\`\`\`
$(cat pre-commit-output | sed 's/\x1b\[[0-9;?]*[mh]//g')
\`\`\`\`
<details>
<summary>diff produced by auto-formatters:</summary>
\`\`\`diff
$(git diff HEAD)
\`\`\`
</details>
EOF
cat report
cat report >> $GITHUB_STEP_SUMMARY

0 comments on commit 7a3db73

Please sign in to comment.