Skip to content

Commit 7d9daba

Browse files
author
ben
authored
ci: build and deploy only affected products (#6694)
Resolve per-product inputs from workspace dependencies and explicit build-time source reads instead of treating every dev merge as a full product change. Keep unknown comparisons conservative and preserve the required checks and daily/manual backstops. Use successfully published image fingerprints and target-level locks so skipped or failed work is not mistaken for a successful baseline. Preserve release builds and exercise changed image recipes on infrastructure PRs. Version native Render filters behind an explicit preview/apply operator workflow; this commit does not edit live services. Keep real dev CodeQL scans until their complete-baseline accounting can be changed separately.
1 parent b227353 commit 7d9daba

29 files changed

Lines changed: 3496 additions & 290 deletions

‎.github/actionlint.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ self-hosted-runner:
22
labels:
33
- blacksmith-2vcpu-ubuntu-2404
44
- blacksmith-4vcpu-ubuntu-2404
5+
- blacksmith-4vcpu-ubuntu-2204
56
- blacksmith-16vcpu-ubuntu-2204
67
- blacksmith-12vcpu-macos-15
78
- blacksmith-8vcpu-windows-2025
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import assert from "node:assert/strict";
2+
import { readFileSync } from "node:fs";
3+
import { test } from "node:test";
4+
import { defaultSetupBaseline, missingLanguages } from "../../scripts/ci/check-codeql-results.mjs";
5+
6+
const workflow = readFileSync(new URL("../workflows/codeql.yml", import.meta.url), "utf8");
7+
const classifier = workflow.split(" script: |\n")[1]?.split("\n\n analyze:\n")[0];
8+
assert.ok(classifier, "Missing Swift input classifier");
9+
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
10+
11+
async function classify(eventName, { files = [], failure } = {}) {
12+
const outputs = new Map();
13+
const warnings = [];
14+
let comparisons = 0;
15+
await new AsyncFunction("context", "core", "github", classifier)(
16+
{
17+
eventName,
18+
repo: { owner: "example", repo: "repo" },
19+
payload: { pull_request: { number: 1 } },
20+
},
21+
{
22+
setOutput: (key, value) => outputs.set(key, value),
23+
info: () => {},
24+
warning: (value) => warnings.push(value),
25+
},
26+
{
27+
rest: { pulls: { listFiles: "listFiles" } },
28+
paginate: async () => {
29+
comparisons++;
30+
if (failure) throw failure;
31+
return files;
32+
},
33+
},
34+
);
35+
return { swift: outputs.get("swift"), comparisons, warnings };
36+
}
37+
38+
for (const event of ["push", "schedule", "workflow_dispatch"]) {
39+
test(`CodeQL keeps the real Swift category on ${event}, including source-unchanged dev pushes`, async () => {
40+
// The dev code_scanning rule and the coverage monitor expect all categories
41+
// from a full baseline. Do not optimize away these scans or replace their
42+
// existing alerts with an empty upload without proving the rule's behavior.
43+
const result = await classify(event);
44+
assert.equal(result.swift, "true");
45+
assert.equal(result.comparisons, 0);
46+
});
47+
}
48+
49+
test("only unchanged-source PRs can use an empty Swift result", async () => {
50+
const unchanged = await classify("pull_request", { files: [
51+
{ filename: "ee/apps/landing/app/page.tsx" },
52+
{ filename: "packages/docs/images/screenshot.png" },
53+
] });
54+
assert.equal(unchanged.swift, "false");
55+
for (const file of [
56+
{ filename: "packages/computer-use/native/Package.swift" },
57+
{ filename: "packages/computer-use/native/Sources/ComputerUse/main.swift" },
58+
{ filename: ".github/workflows/codeql.yml" },
59+
{ filename: ".github/codeql/codeql-config.yml" },
60+
{ filename: "moved/main.swift", previous_filename: "packages/computer-use/native/Sources/ComputerUse/main.swift" },
61+
]) {
62+
assert.equal((await classify("pull_request", { files: [file] })).swift, "true", file.filename);
63+
}
64+
const emptyResultConditions = [...workflow.matchAll(/- name: (?:Write|Upload) empty Swift result\n if: ([^\n]+)/g)].map((match) => match[1]);
65+
assert.deepEqual(emptyResultConditions, [
66+
"github.event_name == 'pull_request' && env.RUN_ANALYSIS != 'true'",
67+
"github.event_name == 'pull_request' && env.RUN_ANALYSIS != 'true'",
68+
], "Empty SARIF must never clear Swift alerts on dev");
69+
});
70+
71+
test("an unavailable or capped PR comparison runs real Swift, never publishes an empty result", async () => {
72+
for (const options of [
73+
{ failure: new Error("comparison unavailable") },
74+
{ files: null },
75+
{ files: Array.from({ length: 3000 }, () => ({ filename: "unrelated.txt" })) },
76+
]) {
77+
const result = await classify("pull_request", options);
78+
assert.equal(result.swift, "true");
79+
assert.ok(result.warnings.length);
80+
}
81+
});
82+
83+
test("the Swift scope does not remove no-build security scans or change upload categories", () => {
84+
assert.match(workflow, /pull_request:\n branches:\n - dev/);
85+
assert.match(workflow, /push:\n branches:\n - dev/);
86+
assert.match(workflow, /schedule:\n - cron:/);
87+
assert.match(workflow, /workflow_dispatch:/);
88+
assert.doesNotMatch(workflow.split("\nconcurrency:\n")[0], /^\s+paths(?:-ignore)?:/m);
89+
for (const language of ["actions", "javascript-typescript", "python"]) {
90+
assert.ok(workflow.includes(`- language: ${language}\n build-mode: none`));
91+
}
92+
assert.match(workflow, /- language: swift\n build-mode: manual/);
93+
assert.ok(workflow.includes("RUN_ANALYSIS: ${{ matrix.language != 'swift' || needs.changes.outputs.swift == 'true' }}"));
94+
assert.match(workflow, /category: \/language:swift/);
95+
assert.ok(workflow.includes("category: /language:${{ matrix.language }}"));
96+
assert.match(workflow, /config-file: \.\/\.github\/codeql\/codeql-config\.yml/);
97+
assert.match(workflow, /run: swift build --package-path packages\/computer-use\/native --product ComputerUse/);
98+
assert.doesNotMatch(workflow, /continue-on-error: true/);
99+
});
100+
101+
test("coverage still requires successful current-head or merge results for all four categories", () => {
102+
const languages = ["actions", "javascript-typescript", "python", "swift"];
103+
const key = ".github/workflows/codeql.yml:analyze";
104+
const head = "a".repeat(40);
105+
const merge = "b".repeat(40);
106+
const older = "c".repeat(40);
107+
const upload = (language, overrides = {}) => ({
108+
analysis_key: key,
109+
category: `/language:${language}`,
110+
commit_sha: head,
111+
error: "",
112+
tool: { name: "CodeQL" },
113+
...overrides,
114+
});
115+
const baseline = defaultSetupBaseline(languages.map((language) => upload(language)));
116+
assert.deepEqual(baseline, { commitSha: head, analysisKey: key, languages });
117+
assert.deepEqual(missingLanguages(baseline.languages, languages.slice(0, -1).map((language) => upload(language)), [head, merge]), ["swift"]);
118+
for (const language of languages) {
119+
for (const overrides of [
120+
{ commit_sha: older },
121+
{ error: "Analysis failed" },
122+
{ analysis_key: "unrelated/workflow:analyze" },
123+
{ tool: { name: "Other tool" } },
124+
]) {
125+
const analyses = languages.map((current) => upload(current, current === language ? overrides : {}));
126+
assert.deepEqual(missingLanguages(baseline.languages, analyses, [head, merge]), [language]);
127+
}
128+
}
129+
assert.deepEqual(missingLanguages(baseline.languages, languages.map((language) => upload(language, { commit_sha: merge })), [head, merge]), []);
130+
});
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
import assert from "node:assert/strict";
2+
import { spawnSync } from "node:child_process";
3+
import { readFileSync } from "node:fs";
4+
import { test } from "node:test";
5+
import { fileURLToPath } from "node:url";
6+
import { buildInputPatterns, isBuildAffected } from "./build-inputs.mjs";
7+
8+
const workflows = new Map([
9+
["desktop", "alpha-macos-aarch64.yml"],
10+
["headless-runner", "celld-runner-deploy.yml"],
11+
["review", "review-app-deploy.yml"],
12+
].map(([target, name]) => [target, readFileSync(new URL(`../workflows/${name}`, import.meta.url), "utf8")]));
13+
14+
function job(workflow, name) {
15+
const body = workflow.split(`\n ${name}:\n`)[1]?.split(/\n [a-z][a-z0-9-]*:\n/)[0];
16+
assert.ok(body, `Missing ${name} job`);
17+
return body;
18+
}
19+
20+
for (const [target, workflow] of workflows) {
21+
test(`${target} classifies every dev push before requesting expensive runners or deployment approval`, () => {
22+
const triggers = workflow.split("\non:\n")[1]?.split("\npermissions:\n")[0];
23+
assert.match(triggers, /push:[\s\S]*branches:[\s\S]*dev/);
24+
assert.match(triggers, /workflow_dispatch:/);
25+
// A copied workflow path list can filter a new graph edge out before the
26+
// dependency-aware classifier ever sees it. Only this cheap job is broad.
27+
assert.doesNotMatch(triggers, /^\s+paths(?:-ignore)?:/m);
28+
// Workflow-level locks would let an unrelated broad-trigger push cancel a
29+
// running build or replace a queued deployment before classification.
30+
assert.doesNotMatch(workflow.split("\njobs:\n")[0], /^concurrency:/m);
31+
32+
const changes = job(workflow, "changes");
33+
assert.match(changes, /runs-on: ubuntu-latest/);
34+
assert.match(changes, /affected: \$\{\{ steps\.classify\.outputs\.affected \}\}/);
35+
assert.match(changes, /persist-credentials: false/);
36+
assert.match(changes, /node-version: 24\.22\.1/);
37+
assert.match(changes, /BUILD_BASE: \$\{\{ github\.event\.before \}\}/);
38+
assert.match(changes, /BUILD_HEAD: \$\{\{ github\.sha \}\}/);
39+
assert.ok(changes.includes(`node .github/scripts/build-inputs.mjs --target ${target} --base "\${BUILD_BASE:-${"0".repeat(40)}}" --head "$BUILD_HEAD"`));
40+
assert.doesNotMatch(changes, /\bpnpm\b|setup-bun|environment:|secrets\.|swift build|celld deploy|vercel@/);
41+
assert.equal(isBuildAffected(target, null), true, "Unknown comparisons must run, including dispatches without a push base");
42+
assert.equal(isBuildAffected(target, []), false);
43+
assert.ok(buildInputPatterns(target).includes(".github/scripts/build-inputs.mjs"));
44+
});
45+
}
46+
47+
test("the workflow CLI commands force manual builds but skip a known empty push range", () => {
48+
for (const [target, workflow] of workflows) {
49+
const command = job(workflow, "changes").match(/^ run: (node .*)$/m)?.[1];
50+
assert.ok(command, target);
51+
for (const [base, affected] of [["", true], ["HEAD", false]]) {
52+
const result = spawnSync("bash", ["-euc", command], {
53+
cwd: fileURLToPath(new URL("../../", import.meta.url)),
54+
env: { ...process.env, BUILD_BASE: base, BUILD_HEAD: "HEAD", GITHUB_OUTPUT: "", GITHUB_ACTIONS: "false" },
55+
encoding: "utf8",
56+
timeout: 30_000,
57+
});
58+
assert.equal(result.status, 0, `${target}: ${result.stderr}`);
59+
assert.ok(result.stdout.split("\n").includes(`affected=${affected}`), `${target}: ${result.stdout}`);
60+
assert.match(result.stdout, /fingerprint=[a-f0-9]{64}/);
61+
}
62+
}
63+
});
64+
65+
test("both alpha platforms depend on the desktop scope while retaining manual platform selection", () => {
66+
const workflow = workflows.get("desktop");
67+
for (const [name, otherPlatform] of [
68+
["publish-alpha-macos-aarch64", "windows-x64"],
69+
["publish-alpha-windows-x64", "macos-arm64"],
70+
]) {
71+
const publish = job(workflow, name);
72+
assert.match(publish, /needs: changes/);
73+
assert.ok(publish.includes(`if: needs.changes.outputs.affected == 'true' && (github.event_name == 'push' || inputs.platform != '${otherPlatform}')`));
74+
assert.match(publish, /pnpm --filter @openwork\/desktop\.\.\. --filter @openwork\/app\.\.\. --filter openwork-server\.\.\. install --frozen-lockfile --prefer-offline/);
75+
}
76+
});
77+
78+
test("deployment scope gates retain repository, environment and authentication checks", () => {
79+
const runner = job(workflows.get("headless-runner"), "deploy");
80+
const review = job(workflows.get("review"), "deploy");
81+
for (const deploy of [runner, review]) {
82+
assert.match(deploy, /needs: changes/);
83+
assert.match(deploy, /github\.repository == 'different-ai\/openwork'/);
84+
assert.match(deploy, /needs\.changes\.outputs\.affected == 'true'/);
85+
}
86+
assert.match(runner, /concurrency:\n group: celld-runner-deploy\n cancel-in-progress: false/);
87+
assert.match(review, /concurrency:\n group: review-app-deploy\n cancel-in-progress: false/);
88+
assert.match(runner, /environment: celld-production/);
89+
assert.match(runner, /name: Check the live runner and this one can serve each other/);
90+
assert.match(runner, /name: Preflight on a throwaway prefix/);
91+
assert.match(runner, /name: Wait for every node to adopt it/);
92+
assert.match(review, /name: review-app/);
93+
assert.match(review, /vars\.OPENWORK_REVIEW_URL != ''/);
94+
assert.match(review, /vars\.OPENWORK_REVIEW_VERCEL_ORG_ID != ''/);
95+
assert.match(review, /vars\.OPENWORK_REVIEW_VERCEL_PROJECT_ID != ''/);
96+
assert.match(review, /name: Verify the alias still requires Vercel Authentication/);
97+
});
98+
99+
test("Electron source selects desktop packaging, not backend builds or deployments", () => {
100+
const files = ["apps/desktop/electron/main.mjs"];
101+
assert.equal(isBuildAffected("desktop", files), true);
102+
for (const target of ["den-api", "den-web", "inference", "client-web", "workbot", "headless-runner", "review", "swift"]) {
103+
assert.equal(isBuildAffected(target, files), false, target);
104+
}
105+
});
106+
107+
test("alpha includes transitive workspace packages and native/release inputs", () => {
108+
for (const path of [
109+
"packages/browser-tabs/src/index.ts",
110+
"packages/remote-sessions/src/index.ts",
111+
"packages/sandbox-freestyle/src/index.ts",
112+
"packages/codemode/src/index.ts",
113+
"packages/free-auto/src/index.ts",
114+
"packages/headless-threads/src/index.ts",
115+
"packages/computer-use/native/Sources/ComputerUse/main.swift",
116+
".github/actions/windows-signing/action.yml",
117+
"scripts/release/stamp-version.mjs",
118+
".github/workflows/alpha-macos-aarch64.yml",
119+
]) {
120+
assert.equal(isBuildAffected("desktop", [path]), true, path);
121+
}
122+
});
123+
124+
test("embedded docs include Markdown, MDX and navigation, not screenshots or website-only files", () => {
125+
for (const path of [
126+
"packages/docs/start-here/overview.md",
127+
"packages/docs/cloud/run-in-the-cloud/cloud-mcp.mdx",
128+
"packages/docs/docs.json",
129+
]) {
130+
assert.equal(isBuildAffected("desktop", [path]), true, path);
131+
}
132+
for (const path of [
133+
"packages/docs/images/screenshot.png",
134+
"packages/docs/images/screenshot.svg",
135+
"packages/docs/openapi.json",
136+
"docs/codeql-results.md",
137+
"ee/apps/landing/app/page.tsx",
138+
]) {
139+
assert.equal(isBuildAffected("desktop", [path]), false, path);
140+
}
141+
});
142+
143+
test("review follows all evidence dependencies and its external shared-color import", () => {
144+
for (const path of [
145+
"apps/review/app/page.tsx",
146+
"packages/review/src/schema.ts",
147+
"packages/evidence-provider/src/provider.ts",
148+
"packages/daytona-evidence/src/review-provider.ts",
149+
"packages/freestyle/src/builder.ts",
150+
"apps/app/src/styles/colors.css",
151+
".vercelignore",
152+
".github/workflows/review-app-deploy.yml",
153+
]) {
154+
assert.equal(isBuildAffected("review", [path]), true, path);
155+
}
156+
for (const path of ["apps/app/src/app.tsx", "apps/app/src/styles/base.css", "ee/apps/landing/app/page.tsx"]) {
157+
assert.equal(isBuildAffected("review", [path]), false, path);
158+
}
159+
});
160+
161+
test("celld includes the runner's transitive dependencies and desktop-image cross-file edge", () => {
162+
for (const path of [
163+
"ee/apps/headless-runner/scripts/celld-bundle.ts",
164+
"ee/packages/headless-protocol/src/index.ts",
165+
"ee/packages/headless-computer/scripts/desktop-identity.mjs",
166+
"packages/workbook/src/index.ts",
167+
"packages/sandbox/src/index.ts",
168+
"packages/sandbox-freestyle/src/index.ts",
169+
"packages/sandbox-daytona/src/index.ts",
170+
"packages/sandbox-differently/src/index.ts",
171+
"packages/computer-use/computer-x11-driver.mjs",
172+
"packages/codemode/src/index.ts",
173+
"packages/types/src/browser-demonstration.ts",
174+
"ee/apps/den-worker-runtime/scripts/cloud-desktop.sh",
175+
".github/workflows/celld-runner-deploy.yml",
176+
]) {
177+
assert.equal(isBuildAffected("headless-runner", [path]), true, path);
178+
}
179+
for (const path of ["ee/apps/den-worker-runtime/src/index.ts", "ee/apps/workbot/src/index.ts", "apps/desktop/electron/main.mjs"]) {
180+
assert.equal(isBuildAffected("headless-runner", [path]), false, path);
181+
}
182+
});
183+
184+
test("every native deployment includes its dependency configuration and classifier", () => {
185+
for (const target of workflows.keys()) {
186+
for (const path of ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", ".npmrc", "patches/example.patch", ".github/scripts/build-inputs.mjs"]) {
187+
assert.equal(isBuildAffected(target, [path]), true, `${target}: ${path}`);
188+
}
189+
}
190+
});

0 commit comments

Comments
 (0)