a GitHub action to run pre-commit
To use this action, make a file .github/workflows/pre-commit.yml
. Here's a
template to get started:
name: pre-commit
on:
pull_request:
push:
branches: [main]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: andrewaylett/pre-commit-action@a975c0a22b967c4d0f8b70a01aadb01b50a1f2eb # v4
This does a few things:
- clones the code
- sets up the
pre-commit
cache
By default, this action runs all the hooks against all the files. extra_args
lets users specify a single hook id and/or options to pass to pre-commit run
.
Here's a sample step configuration that only runs the flake8
hook against all
the files (use the template above except for the pre-commit
action):
- uses: andrewaylett/pre-commit-action@a975c0a22b967c4d0f8b70a01aadb01b50a1f2eb # v4
with:
extra_args: flake8 --all-files
Note that the --all-files
flag is specified as a default extra argument,
and needs to be re-added if the default is overridden.
This repository is forked from pre-commit/action, which was maintained by the authors of pre-commit until they started their own CI service.
Having not found https://pre-commit.ci to be suitable for my use-cases, I have continued to use the out-of-support GitHub Action. It still works, but the warnings (and outdated dependencies) make me prefer to maintain my own fork.
Renovate will bump versions of tools that this project depends on.
Once that's working properly, it includes bumping the default pre-commit version in actions.yaml.
The main GitHub actions workflow tags each commit to main
with the version of pre-commit that's in use
and a counter to keep track of releases of that version number.
I recommend consumers use Mend Renovate or similar to pin to specific commits, but the Actions workflow will maintain a major version tag that you may use if you prefer.