mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The merge-queue Docker workflow (`.github/workflows/docker-merge-group.yml`) pre-builds the production image on `merge_group` so `docker.yml` can promote it on `master` > - #22993 routed `amd64` merge-queue builds to `cloud-release-32`, which does not admit `docker-merge-group.yml`, leaving every merge-queue build queued forever > - While those builds sat queued, `docker.yml` waited 3 minutes in `Find the merge-queue build of this commit` before falling back to its fast AWS release runner > - This pull request moves `docker-merge-group.yml` back to standard GitHub-hosted `matrix.runner` runners and sets `MERGE_GROUP_FIND_WAIT_MS=0` when `CORE_RELEASE_AWS_ENABLED=true` > - The benefit is that merge-queue builds actually execute and promote when ready, while fast AWS `master` builds never lose 3 minutes waiting behind slower GitHub-hosted merge-queue legs ## Linked Issues or Issue Description Refs #22993, Refs #23000 **Describe the bug** Every `docker-merge-group.yml` run stayed queued forever on `build (linux/amd64)` because the `cloud-release-32` runner group does not admit that workflow. In addition, `docker.yml` waited 3 minutes polling unfinished merge-queue runs even when running on the faster AWS release fleet (`CORE_RELEASE_AWS_ENABLED=true`). **Steps to reproduce** 1. Merge a PR through the GitHub Merge Queue on `master`. 2. Inspect the triggered `Docker merge-queue build` run and see `build (linux/amd64)` queued indefinitely. 3. Inspect the subsequent `Docker` run on `master` and see `Find the merge-queue build of this commit` spend 3 minutes waiting before falling back to a source build. **Expected behavior** `docker-merge-group.yml` starts on standard GitHub-hosted runners (`ubuntu-latest` / `ubuntu-24.04-arm`), and `docker.yml` promotes an already-completed merge-queue build immediately without stalling 3 minutes when running on the AWS release fleet. ## What Changed - `.github/workflows/docker-merge-group.yml`: restore `runs-on: ${{ matrix.runner }}` for `build` so `amd64` runs on `ubuntu-latest` instead of queueing on `cloud-release-32`. - `.github/workflows/docker.yml`: pass `MERGE_GROUP_FIND_WAIT_MS: ${{ vars.CORE_RELEASE_AWS_ENABLED == 'true' && '0' || '180000' }}` to `Find the merge-queue build of this commit`. - `scripts/merge-group-image.mjs`: add `resolveFindWaitMs(env)` (clamped to `[0, 180000]`, defaulting to `180000`) and use it in `find`. - `server/src/__tests__/docker-runner-workflows.test.ts` & `scripts/merge-group-image.test.mjs`: add guard tests for standard runner placement and `resolveFindWaitMs` / `MERGE_GROUP_FIND_WAIT_MS`. ## Verification - `vitest run server/src/__tests__/docker-runner-workflows.test.ts`: 15/15 passed. - `node --test scripts/merge-group-image.test.mjs`: 10/10 passed. ## Risks - Low risk. Restores standard runner placement (matching #23000) and keeps the exact promotion verification contract unchanged; fail-open fallback to source build is preserved. ## Model Used - Google Antigravity agent (Gemini / Antigravity coding harness with shell execution and tool use). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
338 lines
19 KiB
TypeScript
338 lines
19 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { describe, expect, it } from "vitest";
|
|
import { RUNNER_IMAGE_WAIT_MINUTES } from "../../../scripts/runner-image-resolve.mjs";
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
const read = (name: string) => readFileSync(path.join(repoRoot, ".github", "workflows", name), "utf8");
|
|
const jobsOf = (workflow: string) => Object.fromEntries(workflow.slice(workflow.indexOf("\njobs:\n")).split(/\n(?= {2}[a-z_-]+:\n)/).slice(1)
|
|
.map((text) => [/^ {2}([a-z_-]+):/.exec(text)![1], text]));
|
|
const permissions = (job: string) =>
|
|
[.../\n {4}permissions:\n((?: {6}.+\n)+)/.exec(job)![1].matchAll(/^ {6}([a-z-]+): (\w+)/gm)].map((match) => `${match[1]}: ${match[2]}`);
|
|
const steps = (job: string) => job.slice(job.indexOf("\n steps:\n")).split(/\n(?= {6}- )/).slice(1);
|
|
const scripts = (text: string) => [...text.matchAll(/^( +)run: (\|\n((?:\1 {2,}.*\n|\n)+)|.+\n)/gm)].map((match) => match[3] ?? match[2]);
|
|
const credential = /github\.token|secrets\.|GITHUB_TOKEN|GH_TOKEN|REGISTRY_PASSWORD/;
|
|
const registryWrite = /docker\/login-action|skopeo|imagetools create|actions\/attest|--push|push=true|cache-to/;
|
|
|
|
function expectPinnedAndExpressionFree(text: string) {
|
|
const uses = [...text.matchAll(/^\s*(?:- )?uses: (\S+)/gm)].map((match) => match[1]);
|
|
expect(uses.length).toBeGreaterThanOrEqual(4);
|
|
for (const action of uses) expect(action).toMatch(/^[\w.-]+\/[\w./-]+@[0-9a-f]{40}$/);
|
|
const shell = scripts(text);
|
|
expect(shell.length).toBeGreaterThanOrEqual(2);
|
|
for (const script of shell) expect(script).not.toContain("${{");
|
|
}
|
|
|
|
const named = (job: string, name: string) => {
|
|
const found = steps(job).filter((step) => step.startsWith(` - name: ${name}\n`));
|
|
expect(found, name).toHaveLength(1);
|
|
return found[0];
|
|
};
|
|
const shell = (step: string) => scripts(`${step}\n`)[0].trimEnd();
|
|
const condition = (text: string, indent: number) => new RegExp(`^ {${indent}}if: (.+)$`, "m").exec(text)?.[1] ?? "";
|
|
const minutes = (text: string, indent: number) => Number(new RegExp(`^ {${indent}}timeout-minutes: (\\d+)$`, "m").exec(text)![1]);
|
|
function runStep(step: string, env: Record<string, string>, stubs: Record<string, string>) {
|
|
const directory = mkdtempSync(path.join(os.tmpdir(), "docker-runner-workflows-"));
|
|
try {
|
|
for (const [name, body] of Object.entries(stubs)) writeFileSync(path.join(directory, name), `#!/bin/sh\n${body}\n`, { mode: 0o755 });
|
|
for (const file of ["output", "summary", "calls"]) writeFileSync(path.join(directory, file), "");
|
|
const run = spawnSync("bash", ["--noprofile", "--norc", "-eo", "pipefail", "-c", shell(step)], {
|
|
cwd: directory,
|
|
encoding: "utf8",
|
|
env: {
|
|
PATH: `${directory}${path.delimiter}${process.env.PATH}`, RUNNER_TEMP: directory, CALLS: path.join(directory, "calls"),
|
|
GITHUB_OUTPUT: path.join(directory, "output"), GITHUB_STEP_SUMMARY: path.join(directory, "summary"), ...env,
|
|
},
|
|
});
|
|
const text = (file: string) => readFileSync(path.join(directory, file), "utf8");
|
|
return { status: run.status, stdout: run.stdout, stderr: run.stderr, output: text("output"), calls: text("calls").trimEnd().split("\n").filter(Boolean) };
|
|
} finally {
|
|
rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
}
|
|
function outputs(text: string) {
|
|
const values: Record<string, string> = {};
|
|
const lines = text.split("\n");
|
|
for (let index = 0; index < lines.length; index += 1) {
|
|
const block = /^([a-z_]+)<<(.+)$/.exec(lines[index]);
|
|
if (block) {
|
|
const end = lines.indexOf(block[2], index + 1);
|
|
values[block[1]] = lines.slice(index + 1, end).join("\n");
|
|
index = end;
|
|
} else if (lines[index].includes("=")) {
|
|
values[lines[index].slice(0, lines[index].indexOf("="))] = lines[index].slice(lines[index].indexOf("=") + 1);
|
|
}
|
|
}
|
|
return values;
|
|
}
|
|
function listInputs(step: string, source: string, resolved: Record<string, string>) {
|
|
const rendered = `${step}\n`.replace(new RegExp(`\\$\\{\\{ ${source.replaceAll(".", "\\.")}\\.([a-z_]+) \\}\\}`, "g"), (_match, name: string) =>
|
|
(resolved[name] ?? "").split("\n").join(`\n${" ".repeat(12)}`));
|
|
const list = (input: string) => {
|
|
const found = new RegExp(`^ {10}${input}: (?:\\|\\n((?: {12}.*\\n)+)|(.*)\\n)`, "m").exec(rendered);
|
|
return (found?.[1] ?? found?.[2] ?? "").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
};
|
|
return { buildArgs: list("build-args"), buildContexts: list("build-contexts"), labels: list("labels") };
|
|
}
|
|
const IMAGE = `ghcr.io/paperclipai/paperclip-runner@sha256:${"c".repeat(64)}`;
|
|
const INPUTS = "1".repeat(64);
|
|
const LABELS = `io.paperclip.runner.image=${IMAGE}\nio.paperclip.runner.inputs-digest=${INPUTS}`;
|
|
const BUILD_ARGS = `PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST=${INPUTS}`;
|
|
const published = { mode: "published", inputs_digest: INPUTS, build_contexts: `runner-artifacts=docker-image://${IMAGE}`, labels: LABELS, build_args: BUILD_ARGS };
|
|
const canonical = "github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064'";
|
|
const VERIFY = "Verify the attestation of the Runner image";
|
|
|
|
describe("the Runner image an application image build copies in docker.yml", () => {
|
|
const workflow = read("docker.yml");
|
|
const jobs = jobsOf(workflow);
|
|
const resolver = jobs.runner_image;
|
|
const legs = jobs["build-and-push"];
|
|
const masterPush = "github.event_name == 'push' && github.ref == 'refs/heads/master'";
|
|
const buildInputs = (resolved: Record<string, string>) => listInputs(named(legs, "Build and push by digest"), "needs.runner_image.outputs", resolved);
|
|
const inlineBuild = {
|
|
buildArgs: [
|
|
"PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}",
|
|
"PAPERCLIP_BUILD_COMMIT=${{ github.sha }}",
|
|
"PAPERCLIP_MACOS_RUNTIME_INPUTS_DIGEST=${{ needs.macos_runner_runtime.outputs.inputs_digest }}",
|
|
"CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}",
|
|
],
|
|
buildContexts: [],
|
|
labels: [
|
|
"${{ steps.meta.outputs.labels }}",
|
|
"${{ steps.cache-policy.outputs.cache_label }}",
|
|
],
|
|
};
|
|
|
|
it("runs only when the repository variable has the enabling value, in the canonical repository, and not otherwise", () => {
|
|
expect(condition(resolver, 4)).toBe(`vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true' && ${canonical}`);
|
|
expect(workflow.match(/RUNNER_IMAGE_CONSUME_ENABLED/g)).toHaveLength(1);
|
|
expect(Object.keys(jobs).filter((name) => jobs[name].includes("runner-image-resolve.mjs"))).toEqual(["runner_image"]);
|
|
expect(read("docker-app-check.yml")).not.toMatch(/runner-image-resolve|RUNNER_IMAGE_CONSUME_ENABLED|build-contexts|--build-context|io\.paperclip\.runner|runner_image/);
|
|
});
|
|
|
|
it("keeps inline Runner arguments and includes the macOS runtime identity without a published Runner", () => {
|
|
expect(buildInputs({})).toEqual(inlineBuild);
|
|
expect(buildInputs({ mode: "inline" })).toEqual(inlineBuild);
|
|
});
|
|
|
|
it("gives both architectures the one answer: the context, the labels and the expected inputs of the verified image", () => {
|
|
expect(/^ {4}needs: \[(.+)\]$/m.exec(legs)![1].split(", ")).toContain("runner_image");
|
|
const reads = [...legs.matchAll(/needs\.runner_image\.[a-z_.]+/g)].map((match) => match[0]);
|
|
expect(new Set(reads)).toEqual(new Set(["mode", "inputs_digest", "build_args", "build_contexts", "labels"].map((name) => `needs.runner_image.outputs.${name}`)));
|
|
for (const line of legs.split("\n").filter((entry) => entry.includes("needs.runner_image"))) expect(line).not.toContain("matrix.");
|
|
expect(buildInputs(published)).toEqual({
|
|
buildArgs: [...inlineBuild.buildArgs, BUILD_ARGS],
|
|
buildContexts: [`runner-artifacts=docker-image://${IMAGE}`],
|
|
labels: [...inlineBuild.labels, ...LABELS.split("\n")],
|
|
});
|
|
});
|
|
|
|
it("hands a build only what the attestation step wrote, and that step fails and writes nothing for an image that does not verify", () => {
|
|
const declared = /\n {4}outputs:\n((?: {6}.+\n)+)/.exec(resolver)![1].trimEnd().split("\n").map((line) => line.trim());
|
|
expect(declared).toEqual([
|
|
"mode: ${{ steps.verify.outputs.mode || 'inline' }}",
|
|
"inputs_digest: ${{ steps.verify.outputs.inputs_digest }}",
|
|
"build_contexts: ${{ steps.verify.outputs.build_contexts }}",
|
|
"labels: ${{ steps.verify.outputs.labels }}",
|
|
"build_args: ${{ steps.verify.outputs.build_args }}",
|
|
]);
|
|
const verify = named(resolver, VERIFY);
|
|
expect(verify).toContain("\n id: verify\n");
|
|
expect(condition(verify, 8)).toBe("steps.resolve.outputs.mode == 'published'");
|
|
const env = { IMAGE, INPUTS_DIGEST: INPUTS, LABELS, BUILD_ARGS, GH_TOKEN: "token-for-the-test" };
|
|
const gh = (status: number) => ({ gh: `printf '%s\\n' "$*" >> "$CALLS"\nexit ${status}` });
|
|
|
|
const verified = runStep(verify, env, gh(0));
|
|
expect(verified.status, verified.stderr).toBe(0);
|
|
expect(verified.calls).toEqual([
|
|
`attestation verify oci://${IMAGE} --repo paperclipai/paperclip --signer-workflow paperclipai/paperclip/.github/workflows/runner-image.yml --source-ref refs/heads/master`,
|
|
]);
|
|
expect(outputs(verified.output)).toEqual(published);
|
|
expect(verified.stdout).not.toContain("::warning");
|
|
|
|
for (const status of [1, 4]) {
|
|
const refused = runStep(verify, env, gh(status));
|
|
expect(refused.status, refused.stderr).toBe(1);
|
|
expect(refused.calls).toHaveLength(1);
|
|
expect(refused.output).toBe("");
|
|
expect(refused.stdout).toContain("::warning title=Runner image not verified::");
|
|
}
|
|
expect(verify).not.toMatch(/continue-on-error/);
|
|
expect(resolver).toContain("\n continue-on-error: true\n");
|
|
expect(condition(legs, 4)).not.toMatch(/runner_image|success\(\)/);
|
|
});
|
|
|
|
it("builds the committed lockfile when it copies the published Runner, and refreshes it for every other build", () => {
|
|
const refresh = named(legs, "Refresh lockfile for Docker build context");
|
|
expect(condition(refresh, 8)).toBe("needs.runner_image.outputs.mode != 'published'");
|
|
expect(legs.match(/pnpm install/g)).toHaveLength(1);
|
|
expect(refresh).toContain("pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile");
|
|
const order = ["Refresh lockfile for Docker build context", "Build and push by digest"].map((name) => steps(legs).indexOf(named(legs, name)));
|
|
expect(order[0]).toBeLessThan(order[1]);
|
|
});
|
|
|
|
it("waits only for a master push, and gives the token to the lookup only then", () => {
|
|
const resolve = named(resolver, "Find the published Runner image of these inputs");
|
|
expect(resolve).toContain("\n id: resolve\n");
|
|
expect(resolve).toContain(` WAIT: \${{ ${masterPush} }}\n`);
|
|
expect(resolve).toContain(` GITHUB_TOKEN: \${{ ${masterPush} && github.token || '' }}\n`);
|
|
const node = { node: `printf '%s\\n' "$*" >> "$CALLS"` };
|
|
const command = (wait: string) => runStep(resolve, { WAIT: wait }, node).calls;
|
|
const waiting = command("true");
|
|
expect(waiting).toHaveLength(1);
|
|
expect(waiting[0]).toMatch(/^scripts\/runner-image-resolve\.mjs resolve --dir \S+\/runner-image-resolve --wait$/);
|
|
for (const wait of ["false", ""]) {
|
|
const once = command(wait);
|
|
expect(once).toHaveLength(1);
|
|
expect(once[0]).toMatch(/^scripts\/runner-image-resolve\.mjs resolve --dir \S+\/runner-image-resolve$/);
|
|
}
|
|
});
|
|
|
|
it("holds no credential where it builds, can write nothing, and reads only what the wait and the verification need", () => {
|
|
expect(workflow).toMatch(/^permissions: \{\}$/m);
|
|
expect(permissions(resolver)).toEqual(["contents: read", "actions: read", "attestations: read"]);
|
|
expect(resolver.slice(0, resolver.indexOf("\n steps:\n"))).not.toMatch(credential);
|
|
expect(steps(resolver).filter((step) => credential.test(step)).map((step) => /- name: (.+)/.exec(step)![1])).toEqual([
|
|
"Find the published Runner image of these inputs",
|
|
"Verify the attestation of the Runner image",
|
|
]);
|
|
const building = steps(resolver).filter((step) => /runner-image-resolve\.mjs inputs|docker buildx|setup-buildx/.test(step));
|
|
expect(building).toHaveLength(2);
|
|
for (const step of building) expect(step).not.toMatch(/\n {8}env:\n/);
|
|
expect(resolver).not.toMatch(/github\.actor|REGISTRY_USERNAME|REGISTRY_PASSWORD/);
|
|
expect(resolver).not.toMatch(registryWrite);
|
|
expect(resolver).toContain("persist-credentials: false");
|
|
expectPinnedAndExpressionFree(resolver);
|
|
});
|
|
|
|
it("promotes a verified merge-queue image only when its Runner inputs digest matches master", () => {
|
|
const find = named(legs, "Find the merge-queue build of this commit");
|
|
expect(condition(find, 8)).toBe(`${canonical} && ${masterPush}`);
|
|
for (const name of ["Download the merge-queue image", "Promote the merge-queue image"]) {
|
|
expect(condition(named(legs, name), 8)).toBe("steps.find.outputs.run_id != ''");
|
|
}
|
|
expect(legs.match(/steps\.find\.outputs\.run_id/g)).toHaveLength(3);
|
|
expect(named(legs, "Promote the merge-queue image")).toContain("RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}");
|
|
expect(condition(named(legs, "Build and push by digest"), 8)).toBe("steps.promote.outputs.digest == ''");
|
|
});
|
|
|
|
it("cannot fail or block an image build, and ends its own wait before any time limit of the workflow", () => {
|
|
expect(resolver).toContain("\n continue-on-error: true\n");
|
|
expect(condition(legs, 4).startsWith("${{ !cancelled() && ")).toBe(true);
|
|
expect(condition(legs, 4)).not.toContain("runner_image");
|
|
const limits = ["Compute the Runner inputs of this commit", "Find the published Runner image of these inputs", "Verify the attestation of the Runner image"]
|
|
.map((name) => minutes(named(resolver, name), 8));
|
|
expect(limits[1]).toBeGreaterThanOrEqual(RUNNER_IMAGE_WAIT_MINUTES + 15);
|
|
expect(minutes(resolver, 4)).toBeGreaterThanOrEqual(limits.reduce((sum, limit) => sum + limit, 0) + 5);
|
|
});
|
|
});
|
|
|
|
describe("the merge-queue build's Runner image in docker-merge-group.yml", () => {
|
|
const workflow = read("docker-merge-group.yml");
|
|
const jobs = jobsOf(workflow);
|
|
const resolver = jobs.runner_image;
|
|
const buildJob = jobs.build;
|
|
const buildInputs = (resolved: Record<string, string>) =>
|
|
listInputs(named(buildJob, "Build image archive"), "needs.runner_image.outputs", resolved);
|
|
const inlineBuild = {
|
|
buildArgs: [
|
|
"PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}",
|
|
"PAPERCLIP_BUILD_COMMIT=${{ github.sha }}",
|
|
"PAPERCLIP_MACOS_RUNTIME_INPUTS_DIGEST=${{ needs.macos_runner_runtime.outputs.inputs_digest }}",
|
|
"CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}",
|
|
],
|
|
buildContexts: [],
|
|
labels: ["${{ steps.meta.outputs.labels }}"],
|
|
};
|
|
|
|
it("gates resolution to canonical master merge groups when RUNNER_IMAGE_CONSUME_ENABLED is true and stays read-only", () => {
|
|
expect(condition(resolver, 4)).toBe(
|
|
`vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true' && ${canonical} && github.event.merge_group.base_ref == 'refs/heads/master'`,
|
|
);
|
|
expect(permissions(resolver)).toEqual(["contents: read", "actions: read", "attestations: read"]);
|
|
expect(resolver).toContain("\n continue-on-error: true\n");
|
|
expect(resolver).toContain("persist-credentials: false");
|
|
expect(resolver).not.toMatch(registryWrite);
|
|
expectPinnedAndExpressionFree(resolver);
|
|
// Non-blocking lookup in the merge queue: never passes --wait.
|
|
expect(named(resolver, "Find the published Runner image of these inputs")).not.toContain("--wait");
|
|
});
|
|
|
|
it("hands build only attested published outputs and falls back cleanly on inline or failed attestation", () => {
|
|
const declared = /\n {4}outputs:\n((?: {6}.+\n)+)/.exec(resolver)![1].trimEnd().split("\n").map((line) => line.trim());
|
|
expect(declared).toEqual([
|
|
"mode: ${{ steps.verify.outputs.mode || 'inline' }}",
|
|
"inputs_digest: ${{ steps.verify.outputs.inputs_digest }}",
|
|
"build_contexts: ${{ steps.verify.outputs.build_contexts }}",
|
|
"labels: ${{ steps.verify.outputs.labels }}",
|
|
"build_args: ${{ steps.verify.outputs.build_args }}",
|
|
]);
|
|
|
|
const verify = named(resolver, VERIFY);
|
|
expect(condition(verify, 8)).toBe("steps.resolve.outputs.mode == 'published'");
|
|
const env = { IMAGE, INPUTS_DIGEST: INPUTS, LABELS, BUILD_ARGS, GH_TOKEN: "token-for-the-test" };
|
|
const gh = (status: number) => ({ gh: `printf '%s\\n' "$*" >> "$CALLS"\nexit ${status}` });
|
|
|
|
const verified = runStep(verify, env, gh(0));
|
|
expect(verified.status, verified.stderr).toBe(0);
|
|
expect(outputs(verified.output)).toEqual(published);
|
|
expect(verified.stdout).not.toContain("::warning");
|
|
|
|
for (const status of [1, 4]) {
|
|
const refused = runStep(verify, env, gh(status));
|
|
expect(refused.status, refused.stderr).toBe(1);
|
|
expect(refused.output).toBe("");
|
|
expect(refused.stdout).toContain("::warning title=Runner image not verified::");
|
|
}
|
|
|
|
expect(buildInputs({})).toEqual(inlineBuild);
|
|
expect(buildInputs({ mode: "inline" })).toEqual(inlineBuild);
|
|
expect(buildInputs(published)).toEqual({
|
|
buildArgs: [...inlineBuild.buildArgs, BUILD_ARGS],
|
|
buildContexts: [`runner-artifacts=docker-image://${IMAGE}`],
|
|
labels: [...inlineBuild.labels, ...LABELS.split("\n")],
|
|
});
|
|
});
|
|
|
|
it("records the attested Runner inputs digest for master promotion verification", () => {
|
|
expect(condition(named(buildJob, "Refresh lockfile for Docker build context"), 8)).toBe("needs.runner_image.outputs.mode != 'published'");
|
|
const record = named(buildJob, "Record the verified image");
|
|
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", () => {
|
|
const workflow = read("docker-app-check.yml");
|
|
const jobs = jobsOf(workflow);
|
|
|
|
it("runs a contributor's code with no credential and no way to publish", () => {
|
|
expect(workflow).toMatch(/^permissions: \{\}$/m);
|
|
expect(workflow).toMatch(/^on:\n {2}pull_request:\n/m);
|
|
expect(workflow).not.toMatch(/pull_request_target|workflow_run|workflow_dispatch|\n {2}push:/);
|
|
expect(Object.keys(jobs)).toEqual(["runner_path"]);
|
|
expect(permissions(jobs.runner_path)).toEqual(["contents: read"]);
|
|
expect(workflow).not.toMatch(credential);
|
|
expect(workflow).not.toMatch(registryWrite);
|
|
expect(workflow).toContain("persist-credentials: false");
|
|
expectPinnedAndExpressionFree(workflow);
|
|
});
|
|
|
|
it("bounds every image build and exports nothing from it", () => {
|
|
const building = steps(jobs.runner_path).filter((step) => step.includes("docker buildx build"));
|
|
expect(building).toHaveLength(1);
|
|
expect(building[0]).toMatch(/^ {8}timeout-minutes: \d+$/m);
|
|
expect(building[0].match(/--output /g)).toEqual(["--output "]);
|
|
expect(building[0]).toContain("--output type=cacheonly");
|
|
});
|
|
});
|