diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 469f8339cd5..12a24e22ec7 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -1,3 +1,7 @@ +self-hosted-runner: + # The host's merge queue runner (kixelated/nixos modules/ci-runners.nix). + labels: + - moq-queue paths: # GitHub's `queue: max` on the shared Pages writers. actionlint learns it in # https://github.com/rhysd/actionlint/pull/661, unreleased after 1.7.12. diff --git a/.github/actions/rust-cache/action.yml b/.github/actions/rust-cache/action.yml index 2cf2bb358be..87cc9958ddb 100644 --- a/.github/actions/rust-cache/action.yml +++ b/.github/actions/rust-cache/action.yml @@ -12,14 +12,16 @@ inputs: runs: using: composite steps: - - name: Require the landing gate on self-hosted runners - if: runner.environment == 'self-hosted' && (github.workflow != 'Land' || github.ref != 'refs/heads/main') + # Only main's merge queue builds on the self-hosted runner: a maintainer + # picked each group's PR, so nothing unreviewed writes its persistent caches. + - name: Require main's merge queue on self-hosted runners + if: runner.environment == 'self-hosted' && !(github.workflow == 'Queue' && github.event_name == 'merge_group' && startsWith(github.ref, 'refs/heads/gh-readonly-queue/main/')) shell: bash run: | - echo "::error::Persistent self-hosted caches require Land on main." >&2 + echo "::error::Persistent self-hosted caches require Queue on main's merge queue." >&2 exit 1 - # Hosted runs on `main` write; everything else reads. The landing worker + # Hosted runs on `main` write; everything else reads. The merge queue # uses only its local store and receives no remote credentials. # # The write key is the boundary. It lives in the `cache-write` diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 250b5662827..ea92d9af1c6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -3,7 +3,7 @@ name: Check permissions: contents: read -# Main PRs report Check as skipped; Land tests their combined prefix. +# Main PRs report Check as skipped; the merge queue tests each one (queue.yml). # Release PRs run the same gate over every package. on: pull_request: diff --git a/.github/workflows/queue.yml b/.github/workflows/queue.yml new file mode 100644 index 00000000000..b4cb104eb18 --- /dev/null +++ b/.github/workflows/queue.yml @@ -0,0 +1,71 @@ +name: Queue + +# GitHub's merge queue tests each picked PR on top of main, one at a time, on +# the host's self-hosted runner, and merges exactly the tree it tested. When the +# queue drops a PR, moq-dev/quest's queue watcher on the host runs the land +# fixer and re-enqueues it (quest/m0/ci/land.md). +# +# `main`'s ruleset requires this job's `Queue` context. GitHub admits a PR to +# the queue only once its required checks pass on the PR itself, so the job +# also runs, as skipped, on main pull requests; a skipped job satisfies the +# requirement. Only the merge group build runs code, and only a maintainer's +# pick enters the queue. +on: + pull_request: + branches: [main] + # `edited` covers a PR retargeted to main, which needs the context too. + types: [opened, synchronize, reopened, edited] + merge_group: + types: [checks_requested] + +permissions: + contents: read + +# Each group has its own ref, so a group never cancels another; a pull request's +# skipped runs replace their own. +concurrency: + group: queue-${{ github.ref }} + cancel-in-progress: true + +jobs: + queue: + name: Queue + if: github.event_name == 'merge_group' + runs-on: [self-hosted, moq-queue] + # A merge group is one PR at build concurrency 1; `just ci` takes about 5-15 + # minutes. Backstop a hang instead of holding the queue. + timeout-minutes: 90 + env: + # The diff the dispatcher selects from: the group's base, as the host gate + # passed its own BASE. + BASE: ${{ github.event.merge_group.base_sha }} + # A failure goes to the fixer whatever else fails, so stop at the first + # failed module (moq-dev/moq#7466). + CHECK_FAIL_FAST: "1" + NEXTEST_TEST_THREADS: 24 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # Full history for the dispatcher's base comparison. + fetch-depth: 0 + + - uses: ./.github/actions/just + + # Local storage only: a self-hosted runner gets no remote cache key. + - name: Rust cache + uses: ./.github/actions/rust-cache + + - name: Check + run: | + rm -rf target/cargo-timings + nix develop --command just ci "$BASE" + + - name: Upload build timings + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: cargo-timings + path: target/cargo-timings/cargo-timing-*.html + if-no-files-found: ignore + retention-days: 14 diff --git a/quest/m0/ci/land.md b/quest/m0/ci/land.md index f84301d9a14..055eb6a3ebf 100644 --- a/quest/m0/ci/land.md +++ b/quest/m0/ci/land.md @@ -68,11 +68,12 @@ Baselines: Remaining: -- **Workflow.** A `merge_group` workflow runs `just ci` against the group's - base on `runs-on: [self-hosted, moq-queue]`, read-only, with no secrets. -- **Ruleset.** `main` requires that check and the merge queue (squash, build - concurrency 1, merge limit 1), drops the unreported `quest land` - requirement, and keeps only the administrator bypass. +- **Ruleset.** `main` requires the `Queue` context, which + `.github/workflows/queue.yml` reports from its `merge_group` build on + `[self-hosted, moq-queue]` (skipped on pull requests, so a PR can enter + the queue), and the merge queue (squash, build concurrency 1, merge limit + 1). It drops the unreported `quest land` requirement and keeps only the + administrator bypass. - **Host.** The host config stops serving moq from `quest land` (`services.quest-land.repositories.moq.enable = false`) at the cutover, while the watcher and fixer keep serving moq. diff --git a/sh/gh/queue.test.ts b/sh/gh/queue.test.ts index 12a79f301d4..68a6541e1dd 100644 --- a/sh/gh/queue.test.ts +++ b/sh/gh/queue.test.ts @@ -1,4 +1,4 @@ -// Main PRs land through the host's batched gate; release PRs retain their own checks. +// Main PRs land through GitHub's merge queue (queue.yml); release PRs retain their own checks. import assert from "node:assert/strict"; import { readdir } from "node:fs/promises"; @@ -38,15 +38,34 @@ for (const step of check.jobs.check.steps) assert.equal(step.env?.CI_BASE, undef assert.equal(check.concurrency.group, "check-${{ github.ref }}"); assert.equal(check.concurrency["cancel-in-progress"], true); -// The land gate runs on the maintainer's host (`quest land serve`), not in Actions. -assert.equal(await Bun.file(".github/workflows/land.yml").exists(), false, "no workflow may land around the host gate"); +// No workflow lands around the merge queue. +assert.equal(await Bun.file(".github/workflows/land.yml").exists(), false, "no workflow may land around the merge queue"); + +// Queue is the one merge group build: main's ruleset requires its context, so +// it reports (skipped) on main PRs and runs only in the merge queue, on the +// host's runner, read-only and without secrets. +const queue = await workflow("queue"); +assert.deepEqual(queue.on.merge_group, { types: ["checks_requested"] }); +assert.deepEqual(queue.on.pull_request.branches, ["main"]); +assert.ok(queue.on.pull_request.types.includes("edited"), "retargeting to main must report the context"); +assert.equal(queue.on.pull_request.paths, undefined, "the required context must always report"); +assert.deepEqual(queue.permissions, { contents: "read" }); +assert.equal(queue.jobs.queue.name, "Queue"); +assert.equal(queue.jobs.queue.if, "github.event_name == 'merge_group'"); +assert.deepEqual(queue.jobs.queue["runs-on"], ["self-hosted", "moq-queue"]); +assert.equal(queue.jobs.queue.permissions, undefined, "the job keeps the workflow's read-only token"); +assert.ok(!JSON.stringify(queue).includes("secrets."), "the merge queue build gets no secrets"); +const checkout = queue.jobs.queue.steps.find((step: { uses?: string }) => step.uses?.startsWith("actions/checkout@")); +assert.equal(checkout.with["persist-credentials"], false); +// biome-ignore lint/suspicious/noTemplateCurlyInString: GitHub expression is literal YAML. +assert.equal(queue.jobs.queue.env.BASE, "${{ github.event.merge_group.base_sha }}"); // Every other workflow stays out of main PRs and main's merge groups: optional // checks run nightly on main, and on release PRs through the Release gate. const files = (await readdir(".github/workflows")).filter((file) => file.endsWith(".yml")); for (const file of files) { const name = file.replace(/\.yml$/, ""); - if (name === "check" || name === "release-gate") continue; + if (name === "check" || name === "release-gate" || name === "queue") continue; const config = await workflow(name); assert.equal(config.on.merge_group, undefined, `${file} must not run in the merge queue`); assert.equal(config.on.pull_request, undefined, `${file} must run on release PRs through release-gate.yml`); diff --git a/sh/gh/setup.test.ts b/sh/gh/setup.test.ts index 9472f446577..2bf8471d5b6 100644 --- a/sh/gh/setup.test.ts +++ b/sh/gh/setup.test.ts @@ -60,12 +60,19 @@ test("self-hosted queue jobs use local caches without R2 credentials", async () .replaceAll("inputs.secret-access-key", 'inputs["secret-access-key"]') .replace(/^\$\{\{\s*|\s*\}\}$/g, ""); const backend = new Function("runner", "inputs", `return (${expression});`); - const guard = new Function("runner", "github", `return (${action.runs.steps[0].if});`); - for (const name of ["Land", "Check", "Untrusted"]) { - for (const ref of ["refs/heads/main", "refs/heads/feature", "refs/pull/1/merge"]) { - const github = { workflow: name, ref }; - expect(guard({ environment: "self-hosted" }, github)).toBe(name !== "Land" || ref !== "refs/heads/main"); - expect(guard({ environment: "github-hosted" }, github)).toBe(false); + // GitHub's expression `startsWith`, so the guard evaluates as written. + const startsWith = (value: string, prefix: string) => value.startsWith(prefix); + const guard = new Function("runner", "github", "startsWith", `return (${action.runs.steps[0].if});`); + const queue = "refs/heads/gh-readonly-queue/main/pr-1-0123456789abcdef0123456789abcdef01234567"; + const refs = ["refs/heads/main", "refs/heads/feature", "refs/pull/1/merge", queue, "refs/heads/gh-readonly-queue/release/pr-1-0"]; + for (const name of ["Queue", "Land", "Check", "Untrusted"]) { + for (const event of ["merge_group", "pull_request", "push"]) { + for (const ref of refs) { + const github = { workflow: name, event_name: event, ref }; + const trusted = name === "Queue" && event === "merge_group" && ref === queue; + expect(guard({ environment: "self-hosted" }, github, startsWith)).toBe(!trusted); + expect(guard({ environment: "github-hosted" }, github, startsWith)).toBe(false); + } } } for (const credentials of [