diff --git a/.github/workflows/docker-merge-group.yml b/.github/workflows/docker-merge-group.yml index cefaa46d0c4..cfbb96ff251 100644 --- a/.github/workflows/docker-merge-group.yml +++ b/.github/workflows/docker-merge-group.yml @@ -120,11 +120,9 @@ jobs: - platform: linux/arm64 runner: ubuntu-24.04-arm arch: arm64 - # GitHub-hosted runners: the protected release fleets admit only - # docker.yml on master. amd64 merge-queue builds for canonical master use - # the larger GitHub-hosted runner (cloud-release-32) so pre-merge builds - # finish quickly while commits wait in the queue. - runs-on: ${{ matrix.arch == 'amd64' && (vars.CORE_PUBLICATION_RUNNER || 'cloud-release-32') || matrix.runner }} + # GitHub-hosted runners: the protected release fleets and larger release + # runner groups admit only docker.yml on master. + runs-on: ${{ matrix.runner }} timeout-minutes: 60 permissions: contents: read diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 014e35f1589..2576a7e6394 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -371,6 +371,10 @@ jobs: GITHUB_TOKEN: ${{ github.token }} BEFORE: ${{ github.event.before }} ARCH: ${{ matrix.arch }} + # When master runs on the fast AWS release fleet, promote an already- + # completed merge-queue build immediately instead of stalling 3 minutes + # behind a slower GitHub-hosted merge-queue runner. + MERGE_GROUP_FIND_WAIT_MS: ${{ vars.CORE_RELEASE_AWS_ENABLED == 'true' && '0' || '180000' }} # Master's copy from before this push selects the run; see the promote # step below. run: | diff --git a/scripts/merge-group-image.mjs b/scripts/merge-group-image.mjs index 1d610bb7857..16dba6d0160 100644 --- a/scripts/merge-group-image.mjs +++ b/scripts/merge-group-image.mjs @@ -22,10 +22,20 @@ const architectures = ["amd64", "arm64"]; const indexTypes = ["application/vnd.oci.image.index.v1+json", "application/vnd.docker.distribution.manifest.list.v2+json"]; const manifestTypes = ["application/vnd.oci.image.manifest.v1+json", "application/vnd.docker.distribution.manifest.v2+json"]; // How long a master push waits for a merge-queue build that is still running. -// Capped at 3 minutes so a master push on a fast AWS runner falls back to -// building from source instead of stalling behind a slower merge-group leg. +// Capped at 3 minutes so a master push falls back to building from source +// instead of stalling behind a slower merge-group leg; callers on fast AWS +// release runners pass MERGE_GROUP_FIND_WAIT_MS=0 to promote completed builds +// immediately with zero wait penalty. const findWaitMs = 3 * 60_000; const findPollMs = 15_000; + +export function resolveFindWaitMs(env = process.env) { + const raw = env?.MERGE_GROUP_FIND_WAIT_MS; + if (raw === undefined || raw === "") return findWaitMs; + const parsed = Number(raw); + if (!Number.isInteger(parsed) || parsed < 0) return findWaitMs; + return Math.min(parsed, findWaitMs); +} const fullSha = /^[a-f0-9]{40}$/; const hex64 = /^[a-f0-9]{64}$/; const digestPattern = /^sha256:[a-f0-9]{64}$/; @@ -215,7 +225,8 @@ async function main(command) { // Publication waits for the exact-source gate in any case, so waiting here // briefly for an almost-finished build costs nothing; past the deadline the // push builds from source. - const deadline = Date.now() + findWaitMs; + const waitMs = resolveFindWaitMs(process.env); + const deadline = Date.now() + waitMs; let run; for (;;) { const { workflow_runs: runs } = await api(`/actions/workflows/docker-merge-group.yml/runs?event=merge_group&head_sha=${sha}&per_page=20`); diff --git a/scripts/merge-group-image.test.mjs b/scripts/merge-group-image.test.mjs index 89c3f537e92..f372efb92d4 100644 --- a/scripts/merge-group-image.test.mjs +++ b/scripts/merge-group-image.test.mjs @@ -7,7 +7,7 @@ import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { - archiveImageDigest, assertPipelineUnchanged, changedSince, createRecord, repositoryId, selectArtifact, selectVerifiedRun, verifyRecord, workflowPath, + archiveImageDigest, assertPipelineUnchanged, changedSince, createRecord, repositoryId, resolveFindWaitMs, selectArtifact, selectVerifiedRun, verifyRecord, workflowPath, } from "./merge-group-image.mjs"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); @@ -208,6 +208,14 @@ test("master promotes only after proof and otherwise builds exactly as before", const order = name => steps.indexOf(step(name)); assert.match(step("Find the merge-queue build of this commit"), /if: github.repository == 'paperclipai\/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs\/heads\/master'/); + assert.match(step("Find the merge-queue build of this commit"), + /MERGE_GROUP_FIND_WAIT_MS: \$\{\{ vars\.CORE_RELEASE_AWS_ENABLED == 'true' && '0' \|\| '180000' \}\}/); + assert.equal(resolveFindWaitMs({}), 180_000); + assert.equal(resolveFindWaitMs({ MERGE_GROUP_FIND_WAIT_MS: "0" }), 0); + assert.equal(resolveFindWaitMs({ MERGE_GROUP_FIND_WAIT_MS: "45000" }), 45_000); + assert.equal(resolveFindWaitMs({ MERGE_GROUP_FIND_WAIT_MS: "999999" }), 180_000); + assert.equal(resolveFindWaitMs({ MERGE_GROUP_FIND_WAIT_MS: "-1" }), 180_000); + assert.equal(resolveFindWaitMs({ MERGE_GROUP_FIND_WAIT_MS: "invalid" }), 180_000); for (const name of ["Find the merge-queue build of this commit", "Download the merge-queue image", "Promote the merge-queue image"]) { assert.match(step(name), /continue-on-error: true/, `${name} must fall back to the build`); } diff --git a/server/src/__tests__/docker-runner-workflows.test.ts b/server/src/__tests__/docker-runner-workflows.test.ts index 4d8ea887652..405166aa3ea 100644 --- a/server/src/__tests__/docker-runner-workflows.test.ts +++ b/server/src/__tests__/docker-runner-workflows.test.ts @@ -303,6 +303,12 @@ describe("the merge-queue build's Runner image in docker-merge-group.yml", () => expect(record).toContain("RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}"); expect(record).toContain('--runner-inputs-digest "$RUNNER_INPUTS_DIGEST"'); }); + + it("keeps merge-queue build jobs on standard GitHub-hosted matrix runners", () => { + const runsOn = /\n {4}runs-on: (.+)\n/.exec(buildJob)?.[1]; + expect(runsOn).toBe("${{ matrix.runner }}"); + expect(buildJob).not.toMatch(/cloud-release-32|CORE_PUBLICATION_RUNNER|runs-on\/fleet=/); + }); }); describe("the pull-request check of the application image's Runner path", () => {