Skip to content

Commit 1728617

Browse files
ochafikclaude
andauthored
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>
1 parent e4a9766 commit 1728617

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ permissions:
1010
contents: read
1111

1212
jobs:
13+
prettier-fix:
14+
name: Auto-fix formatting
15+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
steps:
20+
- uses: actions/checkout@v6
21+
with:
22+
ref: ${{ github.head_ref }}
23+
token: ${{ github.token }}
24+
25+
- uses: actions/setup-node@v6
26+
with:
27+
node-version: "20"
28+
29+
- run: npm ci
30+
31+
- run: npm run prettier:fix
32+
33+
- name: Commit formatting changes
34+
run: |
35+
git diff --quiet && exit 0
36+
git config user.name "github-actions[bot]"
37+
git config user.email "github-actions[bot]@users.noreply.github.com"
38+
git add -A
39+
git commit -m "style: auto-fix prettier formatting"
40+
git push
41+
1342
build:
1443
strategy:
1544
fail-fast: false

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ fi
1717
npm run build:all
1818
npm run prettier:fix
1919

20-
# Stage any changes to generated files (they may have been reformatted by prettier)
21-
git add src/generated/
20+
# Stage any files reformatted by prettier (generated files, source, docs, etc.)
21+
git diff --name-only --diff-filter=M | xargs -r git add

0 commit comments

Comments
 (0)