This GitHub Action runs sqlfluff via pre-commit on a ref range and reports:
- Lint diagnostics (JSON → RDJSON) as inline comments
- Optional fix suggestions (diff of
sqlfluff-fix) as a review
using reviewdog.
It uses:
sqlfluff-lint-json-outputfor parseable JSON outputsqlfluff-fixfor autofixes (optional, controlled byrun_fixinput)
Add the sqlfluff hooks to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.5.0
hooks:
- id: sqlfluff-lint
alias: sqlfluff-lint-only
stages: [manual]
- id: sqlfluff-lint
alias: sqlfluff-lint-json-output
name: sqlfluff-lint (json output)
args: ["--format", "json"]
stages: [manual]
- id: sqlfluff-fixYou also need:
- GitHub Actions enabled on the repository
secrets.GITHUB_TOKENavailable (default on GitHub-hosted runners)- A runner with
jqavailable – onubuntu-latest, this action installsjqviaapt - The jq filter file at
lib/sqlfluff-json-to-rdjson.jqin this action repository 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) |
run_fix |
❌ | true |
Whether to also run sqlfluff-fix and comment the resulting diff (true/false) |
| Name | Description |
|---|---|
lint_exitcode |
Exit code from the sqlfluff-lint-json-output hook |
fix_exitcode |
Exit code from sqlfluff-fix (if run_fix is true) |
Example workflow for pull requests:
name: Lint SQL with sqlfluff
on:
pull_request:
jobs:
sqlfluff:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run sqlfluff lint/fix via pre-commit + reviewdog
uses: leinardi/gha-pre-commit-sqlfluff-reviewdog@v1
with:
from-ref: ${{ github.event.pull_request.base.sha }}
to-ref: ${{ github.event.pull_request.head.sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}
# Optional:
# run_fix: "false"This will:
- Run
sqlfluff-lint-json-outputon SQL files changed betweenfrom-refandto-ref. - Convert the JSON output to RDJSON via the jq script and report diagnostics via reviewdog.
- If
run_fixistrue, runsqlfluff-fixon the same range and post the resulting diff as a review (sqlfluff-fix). - Fail the job if either lint or fix reports issues.
It’s recommended to pin to the major version:
uses: leinardi/gha-pre-commit-sqlfluff-reviewdog@v1For fully reproducible behavior, pin to an exact tag:
uses: leinardi/gha-pre-commit-sqlfluff-reviewdog@v1.0.0