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:
parent
e4a9766592
commit
1728617194
2 changed files with 31 additions and 2 deletions
29
.github/workflows/ci.yml
vendored
29
.github/workflows/ci.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue