From a1fc7f1a5799eefa984a4e46e672f34be1ce63f1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 02:22:11 +0000 Subject: [PATCH] chore: publish from staged --- .github/workflows/check-pr-target.yml | 79 +++++++++++++++++++++------ 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check-pr-target.yml b/.github/workflows/check-pr-target.yml index 05f24fa7..058e6da1 100644 --- a/.github/workflows/check-pr-target.yml +++ b/.github/workflows/check-pr-target.yml @@ -2,8 +2,11 @@ name: Check PR Target Branch on: pull_request_target: - branches: [main] - types: [opened] + types: [opened, edited, reopened, synchronize] + +concurrency: + group: check-pr-target-${{ github.event.pull_request.number }} + cancel-in-progress: true permissions: pull-requests: write @@ -16,20 +19,62 @@ jobs: uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 with: script: | - const body = [ - '⚠️ **This PR targets `main`, but PRs should target `staged`.**', - '', - 'The `main` branch is auto-published from `staged` and should not receive direct PRs.', - 'Please close this PR and re-open it against the `staged` branch.', - '', - 'You can change the base branch using the **Edit** button at the top of this PR,', - 'or run: `gh pr edit ${{ github.event.pull_request.number }} --base staged`' - ].join('\n'); + const pull = context.payload.pull_request; + const owner = context.repo.owner; + const repo = context.repo.repo; + const pullNumber = context.issue.number; + const botLogin = 'github-actions[bot]'; - await github.rest.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - event: 'REQUEST_CHANGES', - body + const { data: reviews } = await github.rest.pulls.listReviews({ + owner, + repo, + pull_number: pullNumber, + per_page: 100 }); + + const latestBotReview = reviews + .filter((review) => review.user?.login === botLogin) + .sort((a, b) => new Date(a.submitted_at ?? a.created_at) - new Date(b.submitted_at ?? b.created_at)) + .at(-1); + + const latestBotState = latestBotReview?.state; + + if (pull.base.ref === 'main') { + if (latestBotState !== 'CHANGES_REQUESTED') { + const requestChangesBody = [ + '⚠️ **This PR targets `main`, but PRs should target `staged`.**', + '', + 'The `main` branch is auto-published from `staged` and should not receive direct PRs.', + 'Please close this PR and re-open it against the `staged` branch.', + '', + 'You can change the base branch using the **Edit** button at the top of this PR,', + 'or run: `gh pr edit ${{ github.event.pull_request.number }} --base staged`' + ].join('\n'); + + await github.rest.pulls.createReview({ + owner, + repo, + pull_number: pullNumber, + event: 'REQUEST_CHANGES', + body: requestChangesBody + }); + } + + return; + } + + if (latestBotState === 'CHANGES_REQUESTED') { + const approveBody = [ + '✅ Base branch is now set correctly.', + '', + 'Removing the prior block because this PR no longer targets `main`.' + ].join('\n'); + + await github.rest.pulls.createReview({ + owner, + repo, + pull_number: pullNumber, + event: 'APPROVE', + body: approveBody + }); + }