diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..226ab52 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -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 <> 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') + \`\`\`\` + +
+ diff produced by auto-formatters: + + \`\`\`diff + $(git diff HEAD) + \`\`\` + +
+ + EOF + + cat report + cat report >> $GITHUB_STEP_SUMMARY