diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index 01572ee0834..453346214eb 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -6,7 +6,7 @@ # Triggers: # - Push to main when a base- or managed-image input changes # - Manual dispatch for ad-hoc rebuilds -# E2E publication verification accepts push builds, not manual rebuilds. +# Trusted manual publications require complete managed-image promotion. # # Base images contain the expensive, rarely-changing layers. Complete image # publication consumes exact base digests from the same trusted workflow run. diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 42a3321149b..869df9cec83 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -203,11 +203,16 @@ jobs: run: | set -euo pipefail case "${REPOSITORY}:${REF}:${EVENT_NAME}:${CHECKOUT_SHA:+controller}" in - NVIDIA/NemoClaw:refs/heads/main:push:|NVIDIA/NemoClaw:refs/heads/main:workflow_dispatch:) + NVIDIA/NemoClaw:refs/heads/main:push:) expected_sha="$WORKFLOW_SHA" allow_non_head=0 select_nearest_successful=0 ;; + NVIDIA/NemoClaw:refs/heads/main:workflow_dispatch:) + expected_sha="$WORKFLOW_SHA" + allow_non_head=0 + select_nearest_successful=1 + ;; NVIDIA/NemoClaw:refs/heads/*:workflow_dispatch:controller) [[ "$BASE_SHA" =~ ^[a-f0-9]{40}$ ]] || { echo "::error::manual PR publication selection requires an exact base SHA" >&2 diff --git a/test/e2e/support/base-image-publication-workflow-boundary.test.ts b/test/e2e/support/base-image-publication-workflow-boundary.test.ts index 7d22400500c..2689e6974a0 100644 --- a/test/e2e/support/base-image-publication-workflow-boundary.test.ts +++ b/test/e2e/support/base-image-publication-workflow-boundary.test.ts @@ -113,7 +113,7 @@ describe("base-image publication workflow boundary (#7372)", () => { it.each([ ["push to main", "push", "", "refs/heads/main", "0", "c".repeat(40), "0"], - ["manual main", "workflow_dispatch", "", "refs/heads/main", "0", "c".repeat(40), "0"], + ["manual main", "workflow_dispatch", "", "refs/heads/main", "0", "c".repeat(40), "1"], [ "controller-selected PR", "workflow_dispatch", diff --git a/test/e2e/support/base-image-publication.test.ts b/test/e2e/support/base-image-publication.test.ts index 86c8f839d5b..fbc18343ca9 100644 --- a/test/e2e/support/base-image-publication.test.ts +++ b/test/e2e/support/base-image-publication.test.ts @@ -34,6 +34,8 @@ const RUN_ID = 29891942278; const WORKFLOW_ID = 251475843; const RUN_URL_ROOT = "https://github.com/NVIDIA/NemoClaw/actions/runs"; const RUN_URL = `https://github.com/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`; +const MANAGED_IMAGE_PROMOTION_JOB = + "Publish complete managed images / Promote complete multi-platform managed image cohort"; const WORKFLOW_SOURCE = `on: push: branches: [main] @@ -120,6 +122,7 @@ function selectedRun(overrides: Partial = {}): PublicationRun { return { id: RUN_ID, attempt: 1, + event: "push", workflowId: WORKFLOW_ID, headSha: RELEVANT_SHA, status: "completed", @@ -163,6 +166,10 @@ function successfulJobs(overrides: { runAttempt?: number } = {}): Record[] { + return [...successfulJobs(), publisherJob(MANAGED_IMAGE_PROMOTION_JOB, { id: 4 })]; +} + describe("base-image publication evidence", () => { it("publishes after a root package manifest changes", () => { const workflowSource = fs.readFileSync( @@ -467,26 +474,85 @@ describe("base-image publication evidence", () => { }); }); - it("selects the nearest fully successful trusted run for branch reuse", () => { - const failedRunId = RUN_ID + 1; + it.each([ + ["push", "completed", "failure", true], + ["workflow_dispatch", "completed", "failure", false], + ["workflow_dispatch", "completed", "cancelled", false], + ["workflow_dispatch", "completed", "timed_out", false], + ["workflow_dispatch", "in_progress", null, false], + ] as const)( + "keeps a valid publication when a newer %s rebuild is %s/%s", + (event, status, conclusion, completedSuccessOnly) => { + const newerRunId = RUN_ID + 1; + const selection = selectPublicationRun( + runsPayload([ + workflowRun({ + id: newerRunId, + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${newerRunId}`, + event, + status, + conclusion, + }), + workflowRun(), + ]), + history(), + WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly }, + ); + + expect(selection).toMatchObject({ + state: "selected", + run: { id: RUN_ID, headSha: RELEVANT_SHA, conclusion: "success" }, + }); + }, + ); + + it("accepts an exact successful manual main publication for branch reuse", () => { + const selection = selectPublicationRun( + runsPayload([workflowRun({ event: "workflow_dispatch" })]), + history(), + WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, + ); + + expect(selection).toMatchObject({ + state: "selected", + run: { + id: RUN_ID, + event: "workflow_dispatch", + headSha: RELEVANT_SHA, + conclusion: "success", + }, + }); + expect(() => + selectPublicationRun( + runsPayload([workflowRun({ event: "workflow_dispatch" })]), + history(), + WORKFLOW_ID, + ), + ).toThrow(/event must be push/u); + }); + + it("prefers a successful push over a successful manual publication at the same commit", () => { + const manualRunId = RUN_ID + 1; const selection = selectPublicationRun( runsPayload([ workflowRun({ - id: failedRunId, - head_sha: DESCENDANT_SHA, - conclusion: "failure", - html_url: `${RUN_URL_ROOT}/${failedRunId}`, + id: manualRunId, + html_url: `${RUN_URL_ROOT}/${manualRunId}`, + event: "workflow_dispatch", }), workflowRun(), ]), history(), WORKFLOW_ID, - { completedSuccessOnly: true }, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, ); expect(selection).toMatchObject({ state: "selected", - run: { id: RUN_ID, headSha: RELEVANT_SHA, conclusion: "success" }, + run: { id: RUN_ID, event: "push", headSha: RELEVANT_SHA }, }); }); @@ -587,6 +653,7 @@ describe("base-image publication evidence", () => { ]), history(), WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, ), ).toThrow(/multiple trusted/u); expect(() => @@ -621,6 +688,23 @@ describe("base-image publication evidence", () => { ).toThrow(/provenance does not match/u); }); + it("requires exact managed-image promotion from a manual publication", () => { + const manualRun = selectedRun({ event: "workflow_dispatch" }); + + expect(() => + validatePublisherJobs( + { total_count: successfulJobs().length, jobs: successfulJobs() }, + manualRun, + ), + ).toThrow(/missing required Publish complete managed images/u); + expect( + validatePublisherJobs( + { total_count: successfulManualJobs().length, jobs: successfulManualJobs() }, + manualRun, + ), + ).toBe("ready"); + }); + it("accepts the renamed trusted publisher jobs", () => { const jobs = [ publisherJob("Manifests / OpenClaw", { id: 1 }), @@ -753,10 +837,10 @@ describe("base-image publication evidence", () => { expect(run.id).toBe(RUN_ID); expect(requests).toEqual([ "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", - "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", - "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, - "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`, ]); @@ -846,6 +930,208 @@ describe("base-image publication evidence", () => { ).resolves.toEqual(selectedRun()); }); + it.each([ + { context: "automatic main", selectNearestSuccessfulRun: false }, + { context: "manual main", selectNearestSuccessfulRun: true }, + ])( + "uses a successful manual publication for $context E2E", + async ({ selectNearestSuccessfulRun }) => { + const manualRun = workflowRun({ event: "workflow_dispatch" }); + const responses = [ + workflowMetadata(), + runsPayload([manualRun]), + { total_count: 4, jobs: successfulManualJobs() }, + manualRun, + ]; + const requests: string[] = []; + + await expect( + waitForBaseImagePublication({ + history: history(), + request: async (requestPath) => { + requests.push(requestPath); + return responses.shift(); + }, + requireWorkflowSuccess: true, + selectNearestSuccessfulRun, + waitMs: 100, + pollMs: 10, + }), + ).resolves.toEqual(selectedRun({ event: "workflow_dispatch" })); + expect(requests).toEqual([ + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`, + ]); + }, + ); + + it("selects the newest tied manual publication deterministically (#11289)", () => { + const olderManualRunId = RUN_ID + 1; + const newerManualRunId = RUN_ID + 2; + + expect( + selectPublicationRun( + runsPayload([ + workflowRun({ + id: olderManualRunId, + event: "workflow_dispatch", + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${olderManualRunId}`, + }), + workflowRun({ + id: newerManualRunId, + event: "workflow_dispatch", + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${newerManualRunId}`, + }), + ]), + history(), + WORKFLOW_ID, + { allowWorkflowDispatch: true, completedSuccessOnly: true }, + ), + ).toMatchObject({ + state: "selected", + run: { id: newerManualRunId, event: "workflow_dispatch" }, + }); + }); + + it("falls back through multiple ineligible manual publications to an older push (#11289)", async () => { + const olderManualRunId = RUN_ID + 1; + const newerManualRunId = RUN_ID + 2; + const manualRun = (id: number) => + workflowRun({ + id, + event: "workflow_dispatch", + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${id}`, + }); + const manualJobs = (runId: number) => + successfulJobs().map((job) => ({ ...job, run_id: runId, head_sha: DESCENDANT_SHA })); + const olderManualRun = manualRun(olderManualRunId); + const newerManualRun = manualRun(newerManualRunId); + const pushRun = workflowRun(); + const responses = [ + workflowMetadata(), + runsPayload([olderManualRun, newerManualRun, pushRun]), + { total_count: manualJobs(newerManualRunId).length, jobs: manualJobs(newerManualRunId) }, + { total_count: manualJobs(olderManualRunId).length, jobs: manualJobs(olderManualRunId) }, + { total_count: successfulJobs().length, jobs: successfulJobs() }, + pushRun, + ]; + const requests: string[] = []; + + await expect( + waitForBaseImagePublication({ + history: history(), + request: async (requestPath) => { + requests.push(requestPath); + return responses.shift(); + }, + requireWorkflowSuccess: true, + selectNearestSuccessfulRun: true, + waitMs: 100, + pollMs: 10, + }), + ).resolves.toEqual(selectedRun()); + expect(requests).toEqual([ + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + `/repos/NVIDIA/NemoClaw/actions/runs/${newerManualRunId}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${olderManualRunId}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`, + ]); + }); + + it("selects an older eligible push after skipping a newer manual run without managed-image promotion (#11289)", async () => { + const manualRunId = RUN_ID + 1; + const manualRun = workflowRun({ + id: manualRunId, + event: "workflow_dispatch", + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${manualRunId}`, + }); + const manualJobs = successfulJobs().map((job) => ({ + ...job, + run_id: manualRunId, + head_sha: DESCENDANT_SHA, + })); + const pushRun = workflowRun(); + const responses = [ + workflowMetadata(), + runsPayload([manualRun, pushRun]), + { total_count: manualJobs.length, jobs: manualJobs }, + { total_count: successfulJobs().length, jobs: successfulJobs() }, + pushRun, + ]; + const requests: string[] = []; + + await expect( + waitForBaseImagePublication({ + history: history(), + request: async (requestPath) => { + requests.push(requestPath); + return responses.shift(); + }, + requireWorkflowSuccess: true, + selectNearestSuccessfulRun: true, + waitMs: 100, + pollMs: 10, + }), + ).resolves.toEqual(selectedRun()); + expect(requests).toEqual([ + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + `/repos/NVIDIA/NemoClaw/actions/runs/${manualRunId}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/1/jobs?per_page=100&page=1`, + `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}`, + ]); + }); + + it("rejects malformed manual promotion evidence instead of falling back to a push (#11289)", async () => { + const manualRunId = RUN_ID + 1; + const manualRun = workflowRun({ + id: manualRunId, + event: "workflow_dispatch", + head_sha: DESCENDANT_SHA, + html_url: `${RUN_URL_ROOT}/${manualRunId}`, + }); + const malformedManualJobs = successfulManualJobs().map((job) => ({ + ...job, + run_id: manualRunId, + head_sha: DESCENDANT_SHA, + ...(job.name === MANAGED_IMAGE_PROMOTION_JOB ? { conclusion: "not-a-conclusion" } : {}), + })); + const pushRun = workflowRun(); + const responses = [ + workflowMetadata(), + runsPayload([manualRun, pushRun]), + { total_count: malformedManualJobs.length, jobs: malformedManualJobs }, + ]; + const requests: string[] = []; + + await expect( + waitForBaseImagePublication({ + history: history(), + request: async (requestPath) => { + requests.push(requestPath); + return responses.shift(); + }, + requireWorkflowSuccess: true, + selectNearestSuccessfulRun: true, + waitMs: 100, + pollMs: 10, + }), + ).rejects.toThrow(/conclusion is invalid/u); + expect(requests).toEqual([ + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", + `/repos/NVIDIA/NemoClaw/actions/runs/${manualRunId}/attempts/1/jobs?per_page=100&page=1`, + ]); + }); + it("rejects failed managed-image publication before E2E consumers start", async () => { const failedRun = workflowRun({ conclusion: "failure" }); const responses = [ @@ -901,7 +1187,7 @@ describe("base-image publication evidence", () => { ).resolves.toMatchObject({ id: RUN_ID, attempt: 1, conclusion: "success" }); expect(requests).toEqual([ "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", - "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", ...Array.from( { length: 11 }, (_, index) => `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/${11 - index}`, @@ -935,7 +1221,7 @@ describe("base-image publication evidence", () => { ).rejects.toThrow(/selected base-image workflow changed while evidence was verified/u); expect(requests).toEqual([ "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml", - "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", + "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", `/repos/NVIDIA/NemoClaw/actions/runs/${RUN_ID}/attempts/2`, ]); }); @@ -973,7 +1259,7 @@ describe("base-image publication evidence", () => { budgetMs: 100, }, { - path: "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&event=push&per_page=100&page=1", + path: "/repos/NVIDIA/NemoClaw/actions/workflows/base-image.yaml/runs?branch=main&per_page=100&page=1", budgetMs: 100, }, { diff --git a/tools/e2e/base-image-publication.mts b/tools/e2e/base-image-publication.mts index d010fd6a718..5c431e3fbde 100644 --- a/tools/e2e/base-image-publication.mts +++ b/tools/e2e/base-image-publication.mts @@ -87,15 +87,32 @@ export const REQUIRED_PUBLISHER_JOBS = [ "Build and push Hermes base image", "Build and push Deep Agents Code base image", ] as const; -const PUBLISHER_JOB_ALIASES = new Map([ +const REQUIRED_MANUAL_MANAGED_IMAGE_JOB = + "Publish complete managed images / Promote complete multi-platform managed image cohort"; +type RequiredPublisherJob = + | (typeof REQUIRED_PUBLISHER_JOBS)[number] + | typeof REQUIRED_MANUAL_MANAGED_IMAGE_JOB; +const PUBLISHER_JOB_ALIASES = new Map([ ["Build and push OpenClaw base image", "Build and push OpenClaw base image"], ["Manifests / OpenClaw", "Build and push OpenClaw base image"], ["Build and push Hermes base image", "Build and push Hermes base image"], ["Manifests / Hermes", "Build and push Hermes base image"], ["Build and push Deep Agents Code base image", "Build and push Deep Agents Code base image"], ["Manifests / Deep Agents Code", "Build and push Deep Agents Code base image"], + [REQUIRED_MANUAL_MANAGED_IMAGE_JOB, REQUIRED_MANUAL_MANAGED_IMAGE_JOB], ]); +class IneligibleManualManagedImagePromotionError extends Error {} + +function requiredPublisherIneligibilityError( + requiredName: RequiredPublisherJob, + message: string, +): Error { + return requiredName === REQUIRED_MANUAL_MANAGED_IMAGE_JOB + ? new IneligibleManualManagedImagePromotionError(message) + : new Error(message); +} + type JsonRecord = Record; export interface FirstParentHistory { @@ -108,6 +125,7 @@ export interface FirstParentHistory { export interface PublicationRun { id: number; attempt: number; + event: "push" | "workflow_dispatch"; workflowId: number; headSha: string; status: string; @@ -429,7 +447,12 @@ export function validateWorkflow(payload: unknown): number { return workflowId; } -function validateRun(value: unknown, index: number, expectedWorkflowId: number): PublicationRun { +function validateRun( + value: unknown, + index: number, + expectedWorkflowId: number, + allowWorkflowDispatch = false, +): PublicationRun { const run = asRecord(value); const id = positiveSafeInteger(run.id, `workflow run ${index} id`); const attempt = positiveSafeInteger(run.run_attempt, `workflow run ${index} attempt`); @@ -439,7 +462,12 @@ function validateRun(value: unknown, index: number, expectedWorkflowId: number): throw new Error(`workflow run ${index} workflow id does not match the base-image workflow`); } const headSha = sha(run.head_sha, `workflow run ${index} head SHA`); - exactString(run.event, "push", `workflow run ${index} event`); + const event = run.event; + if (event !== "push" && !(allowWorkflowDispatch && event === "workflow_dispatch")) { + throw new Error( + `workflow run ${index} event must be push${allowWorkflowDispatch ? " or workflow_dispatch" : ""}`, + ); + } exactString(run.head_branch, MAIN_BRANCH, `workflow run ${index} branch`); exactString(run.path, WORKFLOW_PATH, `workflow run ${index} path`); trustedWorkflowName(run.name, `workflow run ${index} name`); @@ -468,6 +496,7 @@ function validateRun(value: unknown, index: number, expectedWorkflowId: number): return { id, attempt, + event, workflowId: expectedWorkflowId, headSha, status, @@ -480,7 +509,11 @@ export function selectPublicationRun( payload: unknown, history: FirstParentHistory, workflowId: number, - options: { readonly completedSuccessOnly?: boolean } = {}, + options: { + readonly allowWorkflowDispatch?: boolean; + readonly completedSuccessOnly?: boolean; + readonly excludedRunIds?: ReadonlySet; + } = {}, ): PublicationSelection { positiveSafeInteger(workflowId, "base-image workflow id"); const response = asRecord(payload); @@ -495,29 +528,37 @@ export function selectPublicationRun( const runs = response.workflow_runs.flatMap((value, index) => { const run = asRecord(value); return typeof run.head_sha === "string" && history.distanceBySha.has(run.head_sha) - ? [validateRun(run, index, workflowId)] + ? [validateRun(run, index, workflowId, options.allowWorkflowDispatch === true)] : []; }); if (new Set(runs.map((run) => run.id)).size !== runs.length) { throw new Error("workflow run listing contains duplicate run ids"); } const eligible = runs.flatMap((run) => { + if (options.excludedRunIds?.has(run.id)) return []; const distance = history.distanceBySha.get(run.headSha); return distance === undefined ? [] : [{ run, distance }]; }); - const selectable = options.completedSuccessOnly - ? eligible.filter(({ run }) => run.status === "completed" && run.conclusion === "success") - : eligible; + const selectable = eligible.filter(({ run }) => { + if (options.completedSuccessOnly || run.event === "workflow_dispatch") { + return run.status === "completed" && run.conclusion === "success"; + } + return true; + }); if (selectable.length === 0) return { state: "missing" }; const nearestDistance = Math.min(...selectable.map(({ distance }) => distance)); const nearest = selectable.filter(({ distance }) => distance === nearestDistance); - if (nearest.length !== 1) { + const preferredEvent = nearest.some(({ run }) => run.event === "push") + ? "push" + : "workflow_dispatch"; + const preferred = nearest.filter(({ run }) => run.event === preferredEvent); + if (preferredEvent === "push" && preferred.length !== 1) { throw new Error( - `multiple trusted base-image workflow runs match ${nearest[0]?.run.headSha ?? history.relevantSha}`, + `multiple trusted ${preferredEvent} base-image workflow runs match ${preferred[0]?.run.headSha ?? history.relevantSha}: ${preferred.map(({ run }) => run.url).join(", ")}`, ); } - const run = nearest[0].run; + const run = [...preferred].sort((left, right) => right.run.id - left.run.id)[0].run; return { state: "selected", run }; } @@ -566,11 +607,16 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p } let pending = false; - for (const requiredName of REQUIRED_PUBLISHER_JOBS) { + const requiredJobs: readonly RequiredPublisherJob[] = + run.event === "workflow_dispatch" + ? [...REQUIRED_PUBLISHER_JOBS, REQUIRED_MANUAL_MANAGED_IMAGE_JOB] + : REQUIRED_PUBLISHER_JOBS; + for (const requiredName of requiredJobs) { const current = jobsByName.get(requiredName); if (!current) { if (run.status === "completed") { - throw new Error( + throw requiredPublisherIneligibilityError( + requiredName, `missing required ${requiredName} job in attempt ${run.attempt}; ${run.url}`, ); } @@ -579,7 +625,8 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p } if (current.status !== "completed") { if (run.status === "completed") { - throw new Error( + throw requiredPublisherIneligibilityError( + requiredName, `${requiredName} job is not complete in terminal attempt ${run.attempt}; ${run.url}`, ); } @@ -587,7 +634,8 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p continue; } if (current.conclusion !== "success") { - throw new Error( + throw requiredPublisherIneligibilityError( + requiredName, `${requiredName} job did not complete successfully in attempt ${run.attempt}; ${run.url}`, ); } @@ -596,10 +644,16 @@ export function validatePublisherJobs(payload: unknown, run: PublicationRun): "p } export function validateBoundRun(payload: unknown, expected: PublicationRun): PublicationRun { - const actual = validateRun(payload, 0, expected.workflowId); + const actual = validateRun( + payload, + 0, + expected.workflowId, + expected.event === "workflow_dispatch", + ); if ( actual.id !== expected.id || actual.attempt !== expected.attempt || + actual.event !== expected.event || actual.headSha !== expected.headSha ) { throw new Error( @@ -753,13 +807,18 @@ export async function waitForBaseImagePublication( const workflowId = validateWorkflow( await request(`/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}`), ); - const runsPath = `/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}/runs?branch=${MAIN_BRANCH}&event=push&per_page=100`; + const runsPath = `/repos/${REPOSITORY}/actions/workflows/${WORKFLOW_FILE}/runs?branch=${MAIN_BRANCH}&per_page=100`; while (true) { const runs = await collectPaginated(request, runsPath, "workflow_runs"); - const selection = selectPublicationRun(runs, options.history, workflowId, { - completedSuccessOnly: options.selectNearestSuccessfulRun === true, - }); - if (selection.state === "selected") { + const excludedRunIds = new Set(); + const select = () => + selectPublicationRun(runs, options.history, workflowId, { + allowWorkflowDispatch: true, + completedSuccessOnly: options.selectNearestSuccessfulRun === true, + excludedRunIds, + }); + let selection = select(); + while (selection.state === "selected") { if (now() > deadline) { throw new Error( `timed out validating base-image publication for ${selection.run.headSha}; ${selection.run.url}`, @@ -804,6 +863,14 @@ export async function waitForBaseImagePublication( } } } catch (error) { + if ( + selection.run.event === "workflow_dispatch" && + error instanceof IneligibleManualManagedImagePromotionError + ) { + excludedRunIds.add(selection.run.id); + selection = select(); + continue; + } throw publicationEvidenceError(error, selection.run); } if (publisherState === "ready") { @@ -814,6 +881,7 @@ export async function waitForBaseImagePublication( } return validatedRun; } + break; } if (now() >= deadline) { @@ -825,7 +893,7 @@ export async function waitForBaseImagePublication( notice( selection.state === "selected" ? `Required base image publishers are not complete for ${selection.run.headSha}; selected workflow run status ${selection.run.status}; ${selection.run.url}` - : `Waiting for a trusted base-image push run covering ${options.history.relevantSha}`, + : `Waiting for a trusted base-image publication run covering ${options.history.relevantSha}`, ); await sleep(Math.min(options.pollMs, Math.max(1, deadline - now()))); } diff --git a/tools/e2e/operations-workflow-boundary.mts b/tools/e2e/operations-workflow-boundary.mts index 45f49507829..5d4c7a64014 100644 --- a/tools/e2e/operations-workflow-boundary.mts +++ b/tools/e2e/operations-workflow-boundary.mts @@ -81,11 +81,16 @@ const PUBLICATION_CLASSIFIER_SCRIPT = [ "set -euo pipefail", 'case "${REPOSITORY}:${REF}:${EVENT_NAME}:${CHECKOUT_SHA:+controller}" in', - " NVIDIA/NemoClaw:refs/heads/main:push:|NVIDIA/NemoClaw:refs/heads/main:workflow_dispatch:)", + " NVIDIA/NemoClaw:refs/heads/main:push:)", ' expected_sha="$WORKFLOW_SHA"', " allow_non_head=0", " select_nearest_successful=0", " ;;", + " NVIDIA/NemoClaw:refs/heads/main:workflow_dispatch:)", + ' expected_sha="$WORKFLOW_SHA"', + " allow_non_head=0", + " select_nearest_successful=1", + " ;;", " NVIDIA/NemoClaw:refs/heads/*:workflow_dispatch:controller)", ' [[ "$BASE_SHA" =~ ^[a-f0-9]{40}$ ]] || {', ' echo "::error::manual PR publication selection requires an exact base SHA" >&2',