From 14b86d50bd706cb4e45c1e971018883aad380a49 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 18 Apr 2026 20:27:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8PR=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/style-check.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/style-check.yml b/.github/workflows/style-check.yml index 61ee72b..8b7fe8c 100644 --- a/.github/workflows/style-check.yml +++ b/.github/workflows/style-check.yml @@ -12,6 +12,8 @@ permissions: jobs: clang-format: runs-on: ubuntu-latest + env: + STYLE_FIX_BRANCH: codex/style-autofix-${{ github.run_id }}-${{ github.run_attempt }} steps: - name: Checkout @@ -80,10 +82,12 @@ jobs: git diff -- "${files[@]}" - name: Create auto-fix PR + id: cpr if: steps.format.outputs.changed == 'true' && steps.capability.outputs.can_fix == 'true' + continue-on-error: true uses: peter-evans/create-pull-request@v7 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.STYLE_PR_TOKEN != '' && secrets.STYLE_PR_TOKEN || secrets.GITHUB_TOKEN }} commit-message: "style: auto-format C/C++ sources with clang-format" title: "style: auto-format C/C++ sources" body: | @@ -92,13 +96,28 @@ jobs: - Trigger: `${{ github.event_name }}` - Base branch: `${{ steps.base.outputs.base_ref }}` - Formatter: `clang-format` - branch: codex/style-autofix-${{ github.run_id }}-${{ github.run_attempt }} + branch: ${{ env.STYLE_FIX_BRANCH }} base: ${{ steps.base.outputs.base_ref }} delete-branch: true labels: | automated style + - name: Report auto-fix PR result + if: steps.format.outputs.changed == 'true' && steps.capability.outputs.can_fix == 'true' + shell: bash + run: | + if [[ "${{ steps.cpr.outcome }}" == "success" ]]; then + echo "Auto-fix PR created: ${{ steps.cpr.outputs.pull-request-url }}" + exit 0 + fi + + echo "::warning::Auto-fix branch was pushed, but PR creation is blocked by repository policy." + echo "::warning::Enable 'Allow GitHub Actions to create and approve pull requests' OR set secret STYLE_PR_TOKEN (PAT with repo scope)." + echo "Manual PR URL:" + echo "https://github.com/${{ github.repository }}/compare/${{ steps.base.outputs.base_ref }}...${{ env.STYLE_FIX_BRANCH }}?expand=1" + exit 0 + - name: Fail when style drift cannot be auto-fixed if: steps.format.outputs.changed == 'true' && steps.capability.outputs.can_fix != 'true' shell: bash