diff --git a/.github/workflows/approve-autobump-runs.yml b/.github/workflows/approve-autobump-runs.yml new file mode 100644 index 0000000000..1eee396bb6 --- /dev/null +++ b/.github/workflows/approve-autobump-runs.yml @@ -0,0 +1,46 @@ +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 + # 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 <<< "$RUNS" + echo "Approved ${approved} held run(s)." diff --git a/.github/workflows/rustcfml-version-check.yml b/.github/workflows/rustcfml-version-check.yml index 6b12ca573d..1695b778d4 100644 --- a/.github/workflows/rustcfml-version-check.yml +++ b/.github/workflows/rustcfml-version-check.yml @@ -3,82 +3,60 @@ 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 + # 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: 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 +65,122 @@ 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 != '' && steps.cpr.outputs.pull-request-number != '0' + 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 + # 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 -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 + 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 != '' && 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 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 HEAD_SHA; 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 + # 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 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