From 8d978a5823af849f40e17f998986dc49b96d9c74 Mon Sep 17 00:00:00 2001 From: Duncan Horn Date: Wed, 14 Jan 2026 09:25:08 -0800 Subject: [PATCH 1/2] Allow PR input for CI pipeline --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83435ee12..1fe596bed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,11 @@ permissions: on: pull_request: workflow_dispatch: + inputs: + pr_number: + description: 'PR number to test (leave empty to use current branch)' + required: false + type: number push: branches: - master @@ -15,7 +20,16 @@ jobs: name: Format Check runs-on: windows-latest steps: - - uses: actions/checkout@v4 + - name: Checkout input branch + if: github.event.inputs.pr_number + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: refs/pull/${{ github.event.inputs.pr_number }}/merge + + - name: Checkout trigger branch + if: ${{ !github.event.inputs.pr_number }} + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -66,7 +80,15 @@ jobs: runs-on: ${{matrix.host}} steps: - - uses: actions/checkout@v4 + - name: Checkout input branch + if: github.event.inputs.pr_number + uses: actions/checkout@v4 + with: + ref: refs/pull/${{ github.event.inputs.pr_number }}/merge + + - name: Checkout trigger branch + if: ${{ !github.event.inputs.pr_number }} + uses: actions/checkout@v4 - name: Install/Update Clang if: matrix.compiler == 'clang' From 10e0eafe2ac57e59995b4327bc58ce9889eb321d Mon Sep 17 00:00:00 2001 From: Duncan Horn Date: Thu, 15 Jan 2026 13:42:16 -0800 Subject: [PATCH 2/2] Checkout/push to the right branches and update format workflow to trigger CI --- .github/workflows/ci.yml | 4 ++-- .github/workflows/format.yml | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fe596bed..75ef75dc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,10 @@ permissions: on: pull_request: - workflow_dispatch: + workflow_call: inputs: pr_number: - description: 'PR number to test (leave empty to use current branch)' + description: 'PR number to test' required: false type: number push: diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index b4d14e94c..2cd9351c4 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -26,6 +26,7 @@ jobs: outputs: pr-ref: ${{ steps.pr.outputs.ref }} pr-sha: ${{ steps.pr.outputs.sha }} + pr-repo: ${{ steps.pr.outputs.repo }} has-changes: ${{ steps.format.outputs.has-changes }} steps: @@ -41,6 +42,7 @@ jobs: }); core.setOutput('ref', pr.data.head.ref); core.setOutput('sha', pr.data.head.sha); + core.setOutput('repo', pr.data.head.repo.full_name); return pr.data.head.ref; - name: Checkout base repository @@ -51,8 +53,8 @@ jobs: - name: Fetch PR branch shell: cmd run: | - git fetch origin ${{ steps.pr.outputs.ref }} - git checkout ${{ steps.pr.outputs.ref }} + git fetch origin pull/${{ github.event.issue.number }}/head:pr-head + git checkout pr-head - name: Run clang-format id: format @@ -98,10 +100,12 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Fetch PR branch + env: + PR_NUMBER: ${{ github.event.issue.number }} shell: cmd run: | - git fetch origin ${{ needs.format-code.outputs.pr-ref }} - git checkout ${{ needs.format-code.outputs.pr-ref }} + git fetch origin pull/%PR_NUMBER%/head:pr-head + git checkout pr-head - name: Download patch uses: actions/download-artifact@v4 @@ -115,15 +119,28 @@ jobs: del format-changes.patch - name: Commit and push changes - shell: cmd + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_REPO: ${{ needs.format-code.outputs.pr-repo }} + PR_REF: ${{ needs.format-code.outputs.pr-ref }} + shell: pwsh run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add -A git commit -m "Run clang-format on PR changes" - git push origin HEAD:${{ needs.format-code.outputs.pr-ref }} - - # Job 3: Comment on PR with results + + # Try to push to fork repo (works if maintainer edits allowed) + git push https://x-access-token:$env:GITHUB_TOKEN@github.com/$env:PR_REPO HEAD:$env:PR_REF + + # Job 3: Run CI workflow + run-ci: + needs: apply-changes + uses: ./.github/workflows/ci.yml + with: + pr_number: ${{ github.event.issue.number }} + + # Job 4: Comment on PR with results comment-result: needs: [format-code, apply-changes] if: always() && needs.format-code.result != 'cancelled'