This GitHub Action runs one or more pre-commit hooks on a ref range and, if any of them fail or modify files, posts the
resulting diff to the pull request as a review using reviewdog.
It’s designed as a lightweight “core hygiene” action for things like whitespace, merge conflicts, config checks, and large file detection.
By default, this action expects the following hooks to be configured in your .pre-commit-config.yaml:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-filesIf you don’t override the hooks input, these hook IDs will be used.
You need:
- GitHub Actions enabled on the repository
secrets.GITHUB_TOKENavailable (default on GitHub-hosted runners)actions/checkoutfetching enough history to include bothfrom-refandto-ref, for example:
- uses: actions/checkout@v4
with:
fetch-depth: 0| Name | Required | Default | Description |
|---|---|---|---|
from-ref |
✅ | – | Base git ref (e.g. PR base SHA) |
to-ref |
✅ | – | Head git ref (e.g. PR head SHA) |
github-token |
✅ | – | GitHub token for reviewdog (secrets.GITHUB_TOKEN) |
hooks |
❌ | The default list of core hooks shown above (newline-separated hook IDs) | Newline-separated list of pre-commit hook IDs to run. Empty lines and # comments are ignored. |
You can override the default list and provide your own set of hooks:
- name: Run pre-commit hooks + reviewdog diff
uses: leinardi/gha-pre-commit-hooks-reviewdog@v1
with:
from-ref: ${{ github.event.pull_request.base.sha }}
to-ref: ${{ github.event.pull_request.head.sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}
hooks: |
check-merge-conflict
end-of-file-fixer
trailing-whitespace
check-yaml
check-json
# Custom extra hook:
detect-private-keyThe action will:
- Run each listed hook ID via
pre-commit run <hook>on the diff betweenfrom-refandto-ref.
| Name | Description |
|---|---|
exitcode |
1 if any hook failed or modified files, 0 otherwise |
Basic example for pull requests using the default hook list:
name: pre-commit hooks
on:
pull_request:
jobs:
pre-commit-hooks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run pre-commit hooks + reviewdog diff
uses: leinardi/gha-pre-commit-hooks-reviewdog@v1
with:
from-ref: ${{ github.event.pull_request.base.sha }}
to-ref: ${{ github.event.pull_request.head.sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}This will:
- Run all configured hooks on files changed between
from-refandto-ref. - If any hook fails or fixes files, capture the resulting
git diff. - Post the diff as a review (
pre-commit (fixes)) via reviewdog. - Fail the job if any hooks reported issues or made changes.
It’s recommended to pin to the major version:
uses: leinardi/gha-pre-commit-hooks-reviewdog@v1For fully reproducible behavior, pin to an exact tag:
uses: leinardi/[email protected]