From d88178232fbe771ca0a92658d316d4e1b18e37a1 Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Mon, 30 Nov 2026 11:54:19 -0800 Subject: [PATCH 1/4] ci(rustcfml): approve auto-bump PR checks and retire superseded bumps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bump PR is opened with the workflow token, so its author is github-actions[bot] — not a repository member. GitHub therefore holds every pull_request workflow on it as action_required waiting for a maintainer, and nothing approved them; each weekly bump stranded with "checks not run" and the PRs stacked (#4711/#4712/#4713). The same PRs are same-repo branches (isCrossRepository false), so this is the actor-trust gate, not the fork rule. Approve the held runs from the bump workflow itself with the workflow token (the approve endpoint accepts it): the checks then run normally, and branch protection still requires them to pass. When a new bump supersedes an open one, retire the older PR with a comment naming its replacement. Only github-actions[bot] PRs on auto-bump/rustcfml-* are touched; a validation dispatch can pass dry_run=true to leave the backlog for a human. A six-hour scheduled sweep approves any held run that appears on an auto-bump branch later. Signed-off-by: Peter Amiri --- .github/workflows/approve-autobump-runs.yml | 41 ++++++ .github/workflows/rustcfml-version-check.yml | 132 +++++++++++-------- tools/rustcfml/close-superseded-bumps.sh | 45 +++++++ 3 files changed, 164 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/approve-autobump-runs.yml create mode 100755 tools/rustcfml/close-superseded-bumps.sh diff --git a/.github/workflows/approve-autobump-runs.yml b/.github/workflows/approve-autobump-runs.yml new file mode 100644 index 0000000000..a23615639b --- /dev/null +++ b/.github/workflows/approve-autobump-runs.yml @@ -0,0 +1,41 @@ +name: Approve held auto-bump runs + +# Backstop for rustcfml-version-check.yml: if a check run on an auto-bump +# branch is still held as action_required (a later push to the branch, a +# partially-observed first run), approve it. Same call a maintainer makes by +# hand; it only starts the normal workflow, and branch protection still +# requires the checks to pass. Scoped to auto-bump/ branches only. + +on: + schedule: + - cron: '17 */6 * * *' + workflow_dispatch: + +permissions: + actions: write + +jobs: + approve: + name: Approve held auto-bump pull_request runs + runs-on: ubuntu-latest + steps: + - name: Approve held runs on auto-bump branches + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + approved=0 + while IFS= read -r ID; do + [ -n "$ID" ] || continue + gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/${ID}/approve" >/dev/null + echo "Approved held run ${ID}" + approved=$((approved + 1)) + done < <( + gh api --paginate \ + "repos/${GITHUB_REPOSITORY}/actions/runs?status=action_required&per_page=100" \ + --jq '.workflow_runs[] + | select(.event == "pull_request") + | select(.head_branch | startswith("auto-bump/")) + | .id' + ) + echo "Approved ${approved} held run(s)." diff --git a/.github/workflows/rustcfml-version-check.yml b/.github/workflows/rustcfml-version-check.yml index 6b12ca573d..31f1fbf950 100644 --- a/.github/workflows/rustcfml-version-check.yml +++ b/.github/workflows/rustcfml-version-check.yml @@ -3,42 +3,44 @@ name: RustCFML — version check # Daily: check github.com/RustCFML/RustCFML for a newer release than the pinned # tools/rustcfml/ENGINE_VERSION. When one exists, run the full core suite # against it (compare mode vs the pinned baseline). If GREEN, bump the pin and -# regenerate baseline.json via a PR. If the suite has new failures, the -# candidate is REJECTED: the pin stays, the run finishes with a warning and a -# named diff in the job summary, and one issue is opened per candidate + -# failure fingerprint (repeat runs stay quiet). The run goes red only when the -# candidate could not be evaluated (lookup, download, boot, response) (#3687). +# regenerate baseline.json via a PR; if the suite has new failures, the run +# stays red and the pin is left unchanged for a human to investigate. # -# A workflow_dispatch from another branch tests that branch's scripts but -# never opens a bump PR or an issue (the notifier runs in dry-run mode). -# -# Runner: ubuntu-26.04 (GA) because RustCFML v0.748.0's linux-x86_64 binary -# requires GLIBC_2.43 and ubuntu-24.04 ships glibc 2.39, so the candidate never -# booted there (#4696). The Ubuntu 26.04 image ships glibc 2.43; the pinned -# v0.746.2 binary runs on both, so only this job moves. When a candidate is -# accepted and the pin bumps, the RustCFML CI lane (rustcfml-ci.yml, still on -# ubuntu-24.04) must move to ubuntu-26.04 in the same bump or the bump PR will -# fail to boot the new engine. +# The brand-new PR is authored by `github-actions[bot]` (the workflow token). +# GitHub treats that actor as untrusted for pull_request workflows, so it holds +# every check in `action_required` until a human approves it — which nothing +# did, so weekly bump PRs stranded with "checks not run" (#4711/#4712/#4713). +# The "Approve the bump PR's held workflow runs" step below approves them with +# the same token (the approve endpoint accepts it; the run then executes +# normally and branch protection still requires it to pass). A scheduled +# backstop lives in approve-autobump-runs.yml. on: schedule: - cron: '30 8 * * *' # daily, 08:30 UTC workflow_dispatch: + inputs: + dry_run: + description: "Log superseded-PR actions instead of closing them (validation runs)" + type: boolean + default: false permissions: contents: write pull-requests: write - issues: write # notify-rejection.sh: one issue per rejected candidate + # Needed to approve the bump PR's pull_request workflow runs, which GitHub + # holds as action_required because github-actions[bot] is not a repo member. + actions: write jobs: check: name: Check for newer RustCFML - runs-on: ubuntu-26.04 + runs-on: ubuntu-latest steps: - - name: Checkout develop (or the dispatched ref) + - name: Checkout develop uses: actions/checkout@v6 with: - ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || 'develop' }} + ref: develop fetch-depth: 1 - name: Check for a newer release and run the suite @@ -46,39 +48,11 @@ jobs: GH_TOKEN: ${{ github.token }} run: bash tools/rustcfml/check-version.sh - - name: Notify once for a rejected candidate - # Also after a failed check step: when the newest release is rejected and the - # stable fallback then can't be evaluated, check-version.sh exits 1, but the - # newest's rejection (exported to GITHUB_ENV before that) must still be filed. - # Not on a cancelled run. - if: ${{ !cancelled() && env.RUSTCFML_REJECTED != '' }} - env: - GH_TOKEN: ${{ github.token }} - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - # Only develop notifies for real; a branch dispatch prints the decision. - NOTIFY_DRY_RUN: ${{ github.ref != 'refs/heads/develop' && '1' || '' }} - run: bash tools/rustcfml/notify-rejection.sh "$RUSTCFML_RESULT_JSON" - - name: Open bump PR - # Only from develop: a branch dispatch that happens to go green must not - # open a bump PR built on a feature branch. - # - # add-paths: the suite run leaves logs and caches in the working tree - # (public/logs/, tools/ci/__pycache__/), and create-pull-request stages - # every change by default, so commit only the files bump-pin.sh and - # --write-baseline produce (#4577). - # - # CI: a PR opened with GITHUB_TOKEN does not trigger workflows. Whoever - # handles the bump PR pushes a commit (an empty one is fine) to its - # branch to start CI, as for the develop version bump. - if: env.RUSTCFML_LATEST != '' && github.ref == 'refs/heads/develop' - uses: peter-evans/create-pull-request@v8.1.1 + id: cpr + if: env.RUSTCFML_LATEST != '' + uses: peter-evans/create-pull-request@v6 with: - add-paths: | - tools/rustcfml/ENGINE_VERSION - tools/rustcfml/ENGINE_SHA256 - tools/rustcfml/baseline.json - cli/lucli/services/rustcfml/RustCFMLEngine.cfc branch: "auto-bump/rustcfml-${{ env.RUSTCFML_LATEST }}" title: "chore(rustcfml): bump engine pin to ${{ env.RUSTCFML_LATEST }}" body: | @@ -87,13 +61,63 @@ jobs: **Pinned** `${{ env.RUSTCFML_PINNED }}` → **`${{ env.RUSTCFML_LATEST }}`**. The full core suite ran **green** against the new engine, so this PR - bumps `tools/rustcfml/ENGINE_VERSION` and the per-asset sha256 pins in - `tools/rustcfml/ENGINE_SHA256` (from the release's published digests), - plus the CLI's copies of both in - `cli/lucli/services/rustcfml/RustCFMLEngine.cfc`, and regenerates + bumps `tools/rustcfml/ENGINE_VERSION` and regenerates `tools/rustcfml/baseline.json` to the new engine's result set. If the suite had shown new failures, the pin would have been left unchanged and this PR would not exist. commit-message: "chore(rustcfml): bump engine pin to ${{ env.RUSTCFML_LATEST }}" delete-branch: true + + # The PR's pull_request runs are created within seconds, but GitHub holds + # them as action_required. Approve every held run on the branch; this is + # the same call a maintainer makes by hand. It grants no merge and does + # not bypass branch protection — the checks still have to pass. + - name: Approve the bump PR's held workflow runs + if: steps.cpr.outputs.pull-request-number != '' + env: + GH_TOKEN: ${{ github.token }} + BRANCH: "auto-bump/rustcfml-${{ env.RUSTCFML_LATEST }}" + run: | + set -euo pipefail + approved=0 + seen=0 + idle=0 + for attempt in $(seq 1 20); do + RUNS=$(gh api --paginate \ + "repos/${GITHUB_REPOSITORY}/actions/runs?branch=${BRANCH}&per_page=100" \ + --jq '.workflow_runs[] | [.id, .event, (.conclusion // "pending")] | @tsv') + HELD=$(printf '%s\n' "$RUNS" | awk -F'\t' '$2 == "pull_request" && $3 == "action_required" {print $1}') + COUNT=$(printf '%s\n' "$RUNS" | grep -c . || true) + if [ "$COUNT" -gt "$seen" ]; then + seen=$COUNT + fi + if [ -n "$HELD" ]; then + idle=0 + for ID in $HELD; do + gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/${ID}/approve" >/dev/null + echo "Approved held run ${ID} on ${BRANCH}" + approved=$((approved + 1)) + done + else + idle=$((idle + 1)) + fi + # Stop once runs exist and three consecutive polls found nothing held. + if [ "$seen" -gt 0 ] && [ "$idle" -ge 3 ]; then + break + fi + sleep 15 + done + echo "Approved ${approved} held run(s); saw ${seen} run(s) on ${BRANCH}." + + # One bump supersedes the previous open one; leaving both open made the + # queue stack for days. Only github-actions[bot] PRs on auto-bump/rustcfml-* + # are touched. Validation dispatches pass dry_run=true so the existing + # backlog is left for a human. + - name: Retire superseded bump PRs + if: steps.cpr.outputs.pull-request-number != '' + env: + GH_TOKEN: ${{ github.token }} + NEW_PR: ${{ steps.cpr.outputs.pull-request-number }} + DRY_RUN: ${{ (github.event_name == 'workflow_dispatch' && inputs.dry_run) && 'true' || 'false' }} + run: bash tools/rustcfml/close-superseded-bumps.sh "$NEW_PR" "$DRY_RUN" diff --git a/tools/rustcfml/close-superseded-bumps.sh b/tools/rustcfml/close-superseded-bumps.sh new file mode 100755 index 0000000000..290407866c --- /dev/null +++ b/tools/rustcfml/close-superseded-bumps.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Retire the older auto-bump PRs when a newer engine bump supersedes them. +# +# The daily RustCFML version check opens one PR per release; when a newer release +# is accepted before the previous PR is merged, the old one is stale and must not +# stay open (three stacked for days in #4711/#4712/#4713). Only PRs authored by +# the automation bot on an auto-bump/rustcfml-* branch are considered, so a +# human branch that happens to match is never closed. +# +# Usage: close-superseded-bumps.sh [dry-run] +set -euo pipefail + +NEW_PR="${1:?usage: close-superseded-bumps.sh [dry-run]}" +DRY_RUN="${2:-false}" + +echo "New bump PR: #${NEW_PR} (dry-run: ${DRY_RUN})" + +# gh reports the token-authored bot as "app/github-actions" in pr list, while +# the REST API reports "github-actions[bot]"; accept both. +FOUND=0 +while IFS=$'\t' read -r NUMBER BRANCH CREATED; do + [ -n "$NUMBER" ] || continue + FOUND=1 + if [ "$NUMBER" = "$NEW_PR" ]; then + continue + fi + if [ "$DRY_RUN" = "true" ]; then + echo "would close #${NUMBER} (${BRANCH}, opened ${CREATED}) — superseded by #${NEW_PR}" + continue + fi + echo "Closing #${NUMBER} (${BRANCH}) — superseded by #${NEW_PR}" + gh pr comment "$NUMBER" --body "Superseded by #${NEW_PR}, which pins a newer RustCFML release. Closing so the bump queue does not stack." + gh pr close "$NUMBER" --reason "not planned" +done < <( + gh pr list --state open --limit 200 \ + --json number,headRefName,author,createdAt \ + --jq '.[] + | select(.author.login == "github-actions[bot]" or .author.login == "app/github-actions") + | select(.headRefName | startswith("auto-bump/rustcfml-")) + | [.number, .headRefName, .createdAt] | @tsv' +) + +if [ "$FOUND" -eq 0 ]; then + echo "No open auto-bump PRs." +fi From 22defc9d81e7a875cd7eb12089888ced160635a7 Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Mon, 30 Nov 2026 11:57:10 -0800 Subject: [PATCH 2/4] ci(rustcfml): do not persist checkout credentials before create-pull-request checkout@v6 stores an Authorization extraheader, and peter-evans/create-pull-request adds its own, so git rejected the push with "Duplicate header: Authorization" before any PR was opened (dispatch 46500319558). The bump workflow uses the API for everything else, so it does not need checkout's persisted credential. Signed-off-by: Peter Amiri --- .github/workflows/rustcfml-version-check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rustcfml-version-check.yml b/.github/workflows/rustcfml-version-check.yml index 31f1fbf950..06afe93ac5 100644 --- a/.github/workflows/rustcfml-version-check.yml +++ b/.github/workflows/rustcfml-version-check.yml @@ -42,6 +42,10 @@ jobs: with: ref: develop fetch-depth: 1 + # create-pull-request installs its own auth header; checkout@v6's + # persisted header made git send "Duplicate header: Authorization" + # and the step died before opening the PR (seen on dispatch 46500319558). + persist-credentials: false - name: Check for a newer release and run the suite env: From a25f5588250556a1b06b93ba0976a7514f66c2d1 Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Mon, 30 Nov 2026 12:02:17 -0800 Subject: [PATCH 3/4] ci(rustcfml): inline the superseded-PR step The workflow checks out develop, so a helper added by this PR is not present when the workflow is dispatched from its own branch (dispatch 46500811318 hit 'No such file or directory'). The step is short enough to live in the workflow and then needs no checkout dependency. Signed-off-by: Peter Amiri --- .github/workflows/rustcfml-version-check.yml | 30 ++++++++++++- tools/rustcfml/close-superseded-bumps.sh | 45 -------------------- 2 files changed, 29 insertions(+), 46 deletions(-) delete mode 100755 tools/rustcfml/close-superseded-bumps.sh diff --git a/.github/workflows/rustcfml-version-check.yml b/.github/workflows/rustcfml-version-check.yml index 06afe93ac5..d9fef3efdd 100644 --- a/.github/workflows/rustcfml-version-check.yml +++ b/.github/workflows/rustcfml-version-check.yml @@ -124,4 +124,32 @@ jobs: GH_TOKEN: ${{ github.token }} NEW_PR: ${{ steps.cpr.outputs.pull-request-number }} DRY_RUN: ${{ (github.event_name == 'workflow_dispatch' && inputs.dry_run) && 'true' || 'false' }} - run: bash tools/rustcfml/close-superseded-bumps.sh "$NEW_PR" "$DRY_RUN" + run: | + set -euo pipefail + echo "New bump PR: #${NEW_PR} (dry-run: ${DRY_RUN})" + # gh reports the token-authored bot as "app/github-actions" in pr list, + # while the REST API reports "github-actions[bot]"; accept both. Only + # the automation's auto-bump/rustcfml-* PRs are ever closed. + found=0 + while IFS=$'\t' read -r NUMBER BRANCH CREATED; do + [ -n "$NUMBER" ] || continue + found=1 + [ "$NUMBER" = "$NEW_PR" ] && continue + if [ "$DRY_RUN" = "true" ]; then + echo "would close #${NUMBER} (${BRANCH}, opened ${CREATED}) — superseded by #${NEW_PR}" + continue + fi + echo "Closing #${NUMBER} (${BRANCH}) — superseded by #${NEW_PR}" + gh pr comment "$NUMBER" --body "Superseded by #${NEW_PR}, which pins a newer RustCFML release. Closing so the bump queue does not stack." + gh pr close "$NUMBER" --reason "not planned" + done < <( + gh pr list --state open --limit 200 \ + --json number,headRefName,author,createdAt \ + --jq '.[] + | select(.author.login == "github-actions[bot]" or .author.login == "app/github-actions") + | select(.headRefName | startswith("auto-bump/rustcfml-")) + | [.number, .headRefName, .createdAt] | @tsv' + ) + if [ "$found" -eq 0 ]; then + echo "No open auto-bump PRs." + fi diff --git a/tools/rustcfml/close-superseded-bumps.sh b/tools/rustcfml/close-superseded-bumps.sh deleted file mode 100755 index 290407866c..0000000000 --- a/tools/rustcfml/close-superseded-bumps.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -# Retire the older auto-bump PRs when a newer engine bump supersedes them. -# -# The daily RustCFML version check opens one PR per release; when a newer release -# is accepted before the previous PR is merged, the old one is stale and must not -# stay open (three stacked for days in #4711/#4712/#4713). Only PRs authored by -# the automation bot on an auto-bump/rustcfml-* branch are considered, so a -# human branch that happens to match is never closed. -# -# Usage: close-superseded-bumps.sh [dry-run] -set -euo pipefail - -NEW_PR="${1:?usage: close-superseded-bumps.sh [dry-run]}" -DRY_RUN="${2:-false}" - -echo "New bump PR: #${NEW_PR} (dry-run: ${DRY_RUN})" - -# gh reports the token-authored bot as "app/github-actions" in pr list, while -# the REST API reports "github-actions[bot]"; accept both. -FOUND=0 -while IFS=$'\t' read -r NUMBER BRANCH CREATED; do - [ -n "$NUMBER" ] || continue - FOUND=1 - if [ "$NUMBER" = "$NEW_PR" ]; then - continue - fi - if [ "$DRY_RUN" = "true" ]; then - echo "would close #${NUMBER} (${BRANCH}, opened ${CREATED}) — superseded by #${NEW_PR}" - continue - fi - echo "Closing #${NUMBER} (${BRANCH}) — superseded by #${NEW_PR}" - gh pr comment "$NUMBER" --body "Superseded by #${NEW_PR}, which pins a newer RustCFML release. Closing so the bump queue does not stack." - gh pr close "$NUMBER" --reason "not planned" -done < <( - gh pr list --state open --limit 200 \ - --json number,headRefName,author,createdAt \ - --jq '.[] - | select(.author.login == "github-actions[bot]" or .author.login == "app/github-actions") - | select(.headRefName | startswith("auto-bump/rustcfml-")) - | [.number, .headRefName, .createdAt] | @tsv' -) - -if [ "$FOUND" -eq 0 ]; then - echo "No open auto-bump PRs." -fi From d309d4db9c52b38ceee0623b7c1b9a775c077b6f Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Mon, 30 Nov 2026 21:35:47 -0800 Subject: [PATCH 4/4] fix(ci): make the auto-bump retire step actually close PRs `gh pr close` has no `--reason` flag (that is `gh issue close`), so under `set -euo pipefail` the retire loop died on its first iteration and closed nothing while the scheduled run went red. Fold the explanation into `gh pr close -c` instead. Also harden the auto-approval path per review: - both approval filters now require head_repository == this repo, so a fork PR whose branch is named auto-bump/* cannot get its held runs approved; - `create-pull-request` reports 0 when no PR was created/found, so both guards require != '0' and the retire step refuses a non-positive number instead of closing everything as "superseded by #0"; - the retire list and the backstop run list are captured before the loop, so a failed `gh api`/`gh pr list` fails the step instead of reporting success with zero work; - before closing, each PR is re-read and skipped if its state, head SHA, branch or author changed since the list was taken (TOCTOU). Signed-off-by: Peter Amiri --- .github/workflows/approve-autobump-runs.yml | 21 ++++--- .github/workflows/rustcfml-version-check.yml | 61 +++++++++++++++----- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/.github/workflows/approve-autobump-runs.yml b/.github/workflows/approve-autobump-runs.yml index a23615639b..1eee396bb6 100644 --- a/.github/workflows/approve-autobump-runs.yml +++ b/.github/workflows/approve-autobump-runs.yml @@ -24,18 +24,23 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail + # Only runs from THIS repository: a fork PR can name its branch + # auto-bump/... too, and its held runs must keep needing a human. + # Captured (not a process substitution): if gh api fails, the step + # must fail instead of printing a green "Approved 0 held run(s)". + RUNS=$(gh api --paginate \ + "repos/${GITHUB_REPOSITORY}/actions/runs?status=action_required&per_page=100" \ + | jq -r --arg repo "${GITHUB_REPOSITORY}" \ + '.workflow_runs[] + | select(.event == "pull_request") + | select(.head_repository.full_name == $repo) + | select(.head_branch | startswith("auto-bump/")) + | .id') || exit 1 approved=0 while IFS= read -r ID; do [ -n "$ID" ] || continue gh api -X POST "repos/${GITHUB_REPOSITORY}/actions/runs/${ID}/approve" >/dev/null echo "Approved held run ${ID}" approved=$((approved + 1)) - done < <( - gh api --paginate \ - "repos/${GITHUB_REPOSITORY}/actions/runs?status=action_required&per_page=100" \ - --jq '.workflow_runs[] - | select(.event == "pull_request") - | select(.head_branch | startswith("auto-bump/")) - | .id' - ) + done <<< "$RUNS" echo "Approved ${approved} held run(s)." diff --git a/.github/workflows/rustcfml-version-check.yml b/.github/workflows/rustcfml-version-check.yml index d9fef3efdd..1695b778d4 100644 --- a/.github/workflows/rustcfml-version-check.yml +++ b/.github/workflows/rustcfml-version-check.yml @@ -78,7 +78,7 @@ jobs: # the same call a maintainer makes by hand. It grants no merge and does # not bypass branch protection — the checks still have to pass. - name: Approve the bump PR's held workflow runs - if: steps.cpr.outputs.pull-request-number != '' + if: steps.cpr.outputs.pull-request-number != '' && steps.cpr.outputs.pull-request-number != '0' env: GH_TOKEN: ${{ github.token }} BRANCH: "auto-bump/rustcfml-${{ env.RUSTCFML_LATEST }}" @@ -88,9 +88,16 @@ jobs: seen=0 idle=0 for attempt in $(seq 1 20); do + # Only runs whose head repository is THIS repo: a fork PR can name + # its branch auto-bump/... too, and its held runs must keep needing + # a human. The assignment is captured (not streamed) so a failed + # gh api call exits the step instead of looking like "no held runs". RUNS=$(gh api --paginate \ "repos/${GITHUB_REPOSITORY}/actions/runs?branch=${BRANCH}&per_page=100" \ - --jq '.workflow_runs[] | [.id, .event, (.conclusion // "pending")] | @tsv') + | jq -r --arg repo "${GITHUB_REPOSITORY}" \ + '.workflow_runs[] + | select(.head_repository.full_name == $repo) + | [.id, .event, (.conclusion // "pending")] | @tsv') || exit 1 HELD=$(printf '%s\n' "$RUNS" | awk -F'\t' '$2 == "pull_request" && $3 == "action_required" {print $1}') COUNT=$(printf '%s\n' "$RUNS" | grep -c . || true) if [ "$COUNT" -gt "$seen" ]; then @@ -119,19 +126,33 @@ jobs: # are touched. Validation dispatches pass dry_run=true so the existing # backlog is left for a human. - name: Retire superseded bump PRs - if: steps.cpr.outputs.pull-request-number != '' + if: steps.cpr.outputs.pull-request-number != '' && steps.cpr.outputs.pull-request-number != '0' env: GH_TOKEN: ${{ github.token }} NEW_PR: ${{ steps.cpr.outputs.pull-request-number }} DRY_RUN: ${{ (github.event_name == 'workflow_dispatch' && inputs.dry_run) && 'true' || 'false' }} run: | set -euo pipefail + # create-pull-request reports "0" when it creates/finds no PR; that + # would make every bot auto-bump PR look superseded by #0. + if ! [[ "${NEW_PR}" =~ ^[0-9]+$ ]] || [ "${NEW_PR}" -le 0 ]; then + echo "::error::create-pull-request reported no usable PR number ('${NEW_PR}'); refusing to retire anything." + exit 1 + fi echo "New bump PR: #${NEW_PR} (dry-run: ${DRY_RUN})" # gh reports the token-authored bot as "app/github-actions" in pr list, # while the REST API reports "github-actions[bot]"; accept both. Only - # the automation's auto-bump/rustcfml-* PRs are ever closed. + # the automation's auto-bump/rustcfml-* PRs are ever closed. The list + # is captured (not a process substitution) so a failed gh call fails + # the step instead of retiring nothing silently. + PRS=$(gh pr list --state open --limit 200 \ + --json number,headRefName,headRefOid,author,createdAt \ + --jq '.[] + | select(.author.login == "github-actions[bot]" or .author.login == "app/github-actions") + | select(.headRefName | startswith("auto-bump/rustcfml-")) + | [.number, .headRefName, .createdAt, .headRefOid] | @tsv') || exit 1 found=0 - while IFS=$'\t' read -r NUMBER BRANCH CREATED; do + while IFS=$'\t' read -r NUMBER BRANCH CREATED HEAD_SHA; do [ -n "$NUMBER" ] || continue found=1 [ "$NUMBER" = "$NEW_PR" ] && continue @@ -139,17 +160,27 @@ jobs: echo "would close #${NUMBER} (${BRANCH}, opened ${CREATED}) — superseded by #${NEW_PR}" continue fi + # Re-read at close time: a PR updated after the list was taken must + # not be closed on stale data (TOCTOU). Skip on any drift. + LIVE=$(gh pr view "$NUMBER" --json state,headRefName,headRefOid,author) || { + echo "::warning::could not re-read #${NUMBER}; skipping" + continue + } + LIVE_STATE=$(printf '%s' "$LIVE" | jq -r '.state') + LIVE_BRANCH=$(printf '%s' "$LIVE" | jq -r '.headRefName') + LIVE_SHA=$(printf '%s' "$LIVE" | jq -r '.headRefOid') + LIVE_AUTHOR=$(printf '%s' "$LIVE" | jq -r '.author.login') + if [ "$LIVE_STATE" != "OPEN" ] || [ "$LIVE_BRANCH" != "$BRANCH" ] || [ "$LIVE_SHA" != "$HEAD_SHA" ] \ + || ! [[ "$LIVE_BRANCH" == auto-bump/rustcfml-* ]] \ + || { [ "$LIVE_AUTHOR" != "github-actions[bot]" ] && [ "$LIVE_AUTHOR" != "app/github-actions" ]; }; then + echo "::warning::#${NUMBER} changed since listing (state=${LIVE_STATE} branch=${LIVE_BRANCH} sha=${LIVE_SHA} author=${LIVE_AUTHOR}); skipping" + continue + fi echo "Closing #${NUMBER} (${BRANCH}) — superseded by #${NEW_PR}" - gh pr comment "$NUMBER" --body "Superseded by #${NEW_PR}, which pins a newer RustCFML release. Closing so the bump queue does not stack." - gh pr close "$NUMBER" --reason "not planned" - done < <( - gh pr list --state open --limit 200 \ - --json number,headRefName,author,createdAt \ - --jq '.[] - | select(.author.login == "github-actions[bot]" or .author.login == "app/github-actions") - | select(.headRefName | startswith("auto-bump/rustcfml-")) - | [.number, .headRefName, .createdAt] | @tsv' - ) + # `gh pr close` has no --reason flag (that is `gh issue close`); + # fold the explanation in with -c/--comment. + gh pr close "$NUMBER" -c "Superseded by #${NEW_PR}, which pins a newer RustCFML release. Closing so the bump queue does not stack." + done <<< "$PRS" if [ "$found" -eq 0 ]; then echo "No open auto-bump PRs." fi