Skip to content

Cached Pre-Commit

Actions
Validates that your commit passes all its pre-commit rules, with caching from uv
v4.5.1-22
Latest
Star (4)

andrewaylett/pre-commit-action

a GitHub action to run pre-commit

using this action

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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
    - uses: andrewaylett/pre-commit-action@3f75ed8368ed894f65c30dea2b3c673157f109fe # v4

This does a few things:

  • clones the code
  • sets up the pre-commit cache

using this action with custom invocations

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@3f75ed8368ed894f65c30dea2b3c673157f109fe # 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.

History

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.

Maintenance

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.

Cached Pre-Commit is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Validates that your commit passes all its pre-commit rules, with caching from uv
v4.5.1-22
Latest

Cached Pre-Commit is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.