ci: run pre-commit in GitHub Actions

This commit is contained in:
Dafydd Jones 2024-11-28 19:46:16 +00:00
parent fd8430b203
commit a989b9bf73

45
.github/workflows/main.yml vendored Normal file
View file

@ -0,0 +1,45 @@
---
name: Test & release
'on':
- pull_request
- push
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# yamllint disable-line rule:line-length
cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
jobs:
should-run:
name: Should run
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
should-run: ${{ steps.action.outputs.should-run }}
steps:
- id: action
uses:
# yamllint disable-line rule:comments rule:line-length
techneg-it/should-workflow-run@dcbb88600d59ec2842778ef1e2d41f680f876329 # v1.0.0
pre-commit:
name: Run `pre-commit`
needs: should-run
if: fromJSON(needs.should-run.outputs.should-run)
container: techneg/ci-pre-commit:v2.2.29
runs-on: ubuntu-latest
steps:
# yamllint disable-line rule:comments rule:line-length
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Export Python package hash for caching
run: echo "PYTHON_SHA256=$PYTHON_SHA256" >> $GITHUB_ENV
# yamllint disable-line rule:comments rule:line-length
- uses: actions/cache@v4.1.2
with:
path: ~/.cache/pre-commit
key: "pre-commit-4|${{ env.PYTHON_SHA256 }}|\
${{ hashFiles('.pre-commit-config.yaml') }}"
- name: Run `pre-commit`
run: |
git config --global --add safe.directory $(pwd)
pre-commit run --all-files --color always --verbose