pre-commit/action and pre-commit.ci behaviour in CI
The official pre-commit/action installs pre-commit, restores its cache, and runs the hooks on GitHub Actions. The separate hosted pre-commit.ci service runs hooks on pull requests and auto-commits fixes instead of leaving the check red.
What this error means
Teams are unsure whether to fail on formatting changes in Actions or let pre-commit.ci auto-fix them, and how the action handles caching and installation for you.
# .github/workflows/pre-commit.yml
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1Common causes
The action already handles install and cache
pre-commit/action installs pre-commit and caches ~/.cache/pre-commit for you, so a manual pip install and cache step are redundant with it.
pre-commit.ci changes the failure model
The hosted bot auto-commits formatter fixes to the PR branch, so the "files were modified" failure becomes an automatic commit instead of a red check.
How to fix it
Use the action for a self-managed workflow
- Check out the repo and set up Python.
- Add
pre-commit/action, which installs, caches, and runs the hooks. - Fail the job on any modification so contributors format before pushing.
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1Enable pre-commit.ci to auto-fix PRs
Configure the ci block so the hosted bot autoupdates and auto-commits fixes on pull requests.
ci:
autofix_prs: true
autoupdate_schedule: weeklyHow to prevent it
- Pick one model: fail-and-fix-locally with the action, or auto-fix with pre-commit.ci.
- Do not double up manual install/cache steps with
pre-commit/action. - Pin the action and hook revs so runs stay reproducible.