Skip to content
Latchkey

pre-commit/action

Run your repo's pre-commit hooks in CI, with the hook environments cached.

Official actionCategory: Code Quality & LintingLatest v3View on GitHub

What it does

pre-commit/action is a small composite action: it pip-installs pre-commit, restores a cache of hook environments, and runs pre-commit run --show-diff-on-failure --color=always --all-files.

It reuses the exact same hook configuration developers run locally, so CI and local checks cannot drift apart.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-python@v5
    with:
      python-version: '3.12'
  - uses: pre-commit/action@v3.0.1

Inputs

InputDescriptionDefaultRequired
extra_argsOptions to pass to pre-commit run.--all-filesNo

Notes

The project publishes exact version tags (v3.0.1), not a floating major tag, reference the full version or a commit SHA.

The project describes this action as being in maintenance-only mode and recommends pre-commit.ci for richer behavior like auto-fixing PRs.

Run actions/setup-python first so the cache key (which includes the Python location) is stable and hooks get a predictable interpreter.

Common errors

  • A failing run that ends with a diff is a hook that modified files (formatters like black or trailing-whitespace). Run pre-commit run --all-files locally and commit the result.
  • A failure resolving a hook's Python version means the runner lacks that interpreter, add actions/setup-python with the version your hooks declare in language_version.

Security and pinning

  • Hooks execute arbitrary code from the repos pinned in .pre-commit-config.yaml, pin hook revs to tags or SHAs and review changes to that file like code.

Alternatives and related

Frequently asked questions

Should I use this action or pre-commit.ci?
This action just runs your hooks in CI and fails on findings. pre-commit.ci additionally auto-fixes PRs and auto-updates hook versions, and is what the pre-commit project recommends; the action remains fine for a simple check gate.
How do I run hooks only on changed files in CI?
Override extra_args, e.g. --from-ref origin/main --to-ref HEAD, instead of the default --all-files. You need enough git history checked out for both refs.

References

Running pre-commit/action? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card