Skip to content
Latchkey

How to Run a pre-commit Check Script in GitHub Actions

Running pre-commit run --all-files in CI enforces the same hooks locally and in the pipeline, so nothing slips through unhooked machines.

Install pre-commit, then run it against every file. The hooks are defined once in .pre-commit-config.yaml, so CI and local checks cannot drift apart.

Steps

  • Keep hook definitions in .pre-commit-config.yaml.
  • Set up Python and pip install pre-commit.
  • Run pre-commit run --all-files as the gate.

Workflow

.github/workflows/ci.yml
jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - run: pip install pre-commit
      - run: pre-commit run --all-files

Gotchas

  • Cache ~/.cache/pre-commit keyed on the config hash so hook environments are not rebuilt every run.
  • Some hooks reformat files; in CI they fail the job to signal the change rather than committing it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →