ci: auto-fix prettier formatting in pre-commit hook and CI (#498)

Pre-commit hook:
- Stage all files modified by prettier:fix, not just src/generated/

CI (GitHub Actions):
- Add prettier-fix job that runs on PRs from the same repo
- Auto-commits formatting fixes back to the PR branch
- Skips fork PRs (no write access to fork branches)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Olivier Chafik 2026-02-24 18:37:57 +00:00 • committed by GitHub
commit 1728617194
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View file

@ -10,6 +10,35 @@ permissions:
contents: read
jobs:
prettier-fix:
name: Auto-fix formatting
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
token: ${{ github.token }}
- uses: actions/setup-node@v6
with:
node-version: "20"
- run: npm ci
- run: npm run prettier:fix
- name: Commit formatting changes
run: |
git diff --quiet && exit 0
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "style: auto-fix prettier formatting"
git push
build:
strategy:
fail-fast: false

View file

@ -17,5 +17,5 @@ fi
npm run build:all
npm run prettier:fix
# Stage any changes to generated files (they may have been reformatted by prettier)
git add src/generated/
# Stage any files reformatted by prettier (generated files, source, docs, etc.)
git diff --name-only --diff-filter=M | xargs -r git add