From 34913ce477a3dec2f11ebc6658136fa0c4bee934 Mon Sep 17 00:00:00 2001 From: "dayuan.jiang" Date: Fri, 26 Dec 2025 12:10:35 +0900 Subject: [PATCH] fix: handle fork PRs in auto-format workflow - Use head.sha instead of head_ref for checkout (works for forks) - For fork PRs: fail with helpful message if formatting needed - For same-repo PRs: auto-commit and push as before --- .github/workflows/auto-format.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-format.yml b/.github/workflows/auto-format.yml index bbe997e..42fb75a 100644 --- a/.github/workflows/auto-format.yml +++ b/.github/workflows/auto-format.yml @@ -14,7 +14,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.sha }} token: ${{ secrets.GITHUB_TOKEN }} - name: Setup Node.js @@ -37,11 +37,21 @@ jobs: echo "has_changes=true" >> $GITHUB_OUTPUT fi + # For fork PRs, just fail if formatting is needed (can't push to forks) + - name: Fail if fork PR needs formatting + if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name != github.repository + run: | + echo "::error::This PR has formatting issues. Please run 'npx @biomejs/biome check --write .' locally and push the changes." + git diff --stat + exit 1 + + # For same-repo PRs, commit and push the changes - name: Commit changes - if: steps.changes.outputs.has_changes == 'true' + if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} git add . git commit -m "style: auto-format with Biome" - git push + git push origin HEAD:${{ github.head_ref }}