Skip to the content.

GitHub Actions Integration

Basic: Lint changed migrations on pull requests

This workflow detects changed SQL migration files, runs pg-migration-lint, and uploads SARIF results so that findings appear as inline annotations on the pull request.

Copy this file to .github/workflows/migration-lint.yml in your repository:

name: Migration Lint

on:
  pull_request:
    paths:
      - 'db/migrations/**'

jobs:
  lint:
    runs-on: ubuntu-latest
    permissions:
      security-events: write  # Required for uploading SARIF to GitHub Code Scanning
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Full history so git diff can compare against the base branch

      - name: Get changed migration files
        id: changes
        run: |
          files=$(git diff --name-only origin/$...HEAD -- 'db/migrations/*.sql' | tr '\n' ',')
          echo "files=$files" >> "$GITHUB_OUTPUT"

      - name: Download pg-migration-lint
        run: |
          curl -LO https://github.com/robert-sjoblom/pg-migration-lint/releases/latest/download/pg-migration-lint-x86_64-linux.tar.gz
          tar xzf pg-migration-lint-x86_64-linux.tar.gz
          chmod +x pg-migration-lint

      - name: Run linter
        if: steps.changes.outputs.files != ''
        run: |
          ./pg-migration-lint \
            --changed-files "$" \
            --format sarif \
            --fail-on critical

      - name: Upload SARIF
        if: always() && steps.changes.outputs.files != ''
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: build/reports/migration-lint/findings.sarif

What each step does