Skip to content

Commit 157fcc5

Browse files
committed
fix(ci): isolate mobile changes and report unused backend checks early
Signed-off-by: Tom Brow <[email protected]>
1 parent 4c2086c commit 157fcc5

2 files changed

Lines changed: 303 additions & 8 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
- 'scripts/model-capabilities.json'
6464
- 'scripts/normative-corpus.json'
6565
- 'desktop/**'
66-
- '!desktop/src-tauri/**'
6766
- 'pnpm-lock.yaml'
6867
desktop-rust:
6968
- 'desktop/src-tauri/**'
@@ -113,7 +112,9 @@ jobs:
113112
scripts/test-rust-cache-contract.sh
114113
scripts/test-rust-cache-contract-regressions.sh
115114
- name: CI required-context isolation contract
116-
run: scripts/test-ci-required-context-isolation.sh
115+
run: |
116+
scripts/test-ci-required-context-isolation.sh
117+
node --test scripts/ci-selection.test.mjs
117118
- name: File size policy
118119
run: just file-size-check
119120

@@ -330,9 +331,31 @@ jobs:
330331
RESULT: ${{ needs.relay-domain.outputs.desktop_e2e_integration_result }}
331332
run: test "$RESULT" = success
332333

334+
# These contexts must finish without waiting for desktop's relay artifacts.
335+
# Only one reporter owns each required name for a given change selection.
336+
backend-not-required:
337+
name: ${{ (needs.changes.result != 'success' || (github.event_name != 'push' && needs.changes.outputs.rust != 'true')) && matrix.check || format('{0} (skip reporter)', matrix.check) }}
338+
needs: [changes]
339+
if: always() && (needs.changes.result != 'success' || (github.event_name != 'push' && needs.changes.outputs.rust != 'true'))
340+
strategy:
341+
matrix:
342+
check: ['Backend Integration (relay e2e)', 'Relay E2E', 'PostgreSQL Tests']
343+
runs-on: ubuntu-latest
344+
timeout-minutes: 5
345+
permissions: {}
346+
steps:
347+
- name: Verify path selection before reporting not required
348+
env:
349+
CHANGES_RESULT: ${{ needs.changes.result }}
350+
RUST: ${{ needs.changes.outputs.rust }}
351+
run: |
352+
test "$CHANGES_RESULT" = success
353+
test "$RUST" = false
354+
echo "Backend checks are not required for these changed paths."
355+
333356
backend-integration:
334-
name: Backend Integration (relay e2e)
335-
if: always() && needs.changes.result == 'success' && needs.relay-artifacts-domain.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
357+
name: ${{ (needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')) && 'Backend Integration (relay e2e)' || 'Backend Integration (relay e2e) (not selected)' }}
358+
if: always() && needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
336359
needs: [changes, relay-artifacts-domain, relay-domain]
337360
runs-on: ubuntu-latest
338361
timeout-minutes: 5
@@ -344,8 +367,8 @@ jobs:
344367
run: test "$RESULT" = success
345368

346369
postgres-tests:
347-
name: PostgreSQL Tests
348-
if: always() && needs.changes.result == 'success' && needs.relay-artifacts-domain.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
370+
name: ${{ (needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')) && 'PostgreSQL Tests' || 'PostgreSQL Tests (not selected)' }}
371+
if: always() && needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
349372
needs: [changes, relay-artifacts-domain, postgres-domain]
350373
runs-on: ubuntu-latest
351374
timeout-minutes: 5
@@ -357,8 +380,8 @@ jobs:
357380
run: test "$RESULT" = success
358381

359382
relay-e2e:
360-
name: Relay E2E
361-
if: always() && needs.changes.result == 'success' && needs.relay-artifacts-domain.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
383+
name: ${{ (needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')) && 'Relay E2E' || 'Relay E2E (not selected)' }}
384+
if: always() && needs.changes.result == 'success' && (github.event_name == 'push' || needs.changes.outputs.rust == 'true')
362385
needs: [changes, relay-artifacts-domain, relay-domain]
363386
runs-on: ubuntu-latest
364387
timeout-minutes: 5

‎scripts/ci-selection.test.mjs‎

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync, spawnSync } from "node:child_process";
3+
import {
4+
mkdtempSync,
5+
mkdirSync,
6+
readFileSync,
7+
rmSync,
8+
writeFileSync,
9+
} from "node:fs";
10+
import { tmpdir } from "node:os";
11+
import { dirname, join } from "node:path";
12+
import { after, test } from "node:test";
13+
14+
const workflow = readFileSync(
15+
new URL("../.github/workflows/ci.yml", import.meta.url),
16+
"utf8",
17+
);
18+
const jobs = Object.fromEntries(
19+
[
20+
...workflow.matchAll(
21+
/^ {2}([\w-]+):\n([\s\S]*?)(?=^ {2}[\w-]+:|$(?![\s\S]))/gm,
22+
),
23+
].map(([, id, body]) => [id, body]),
24+
);
25+
const field = (job, key) => {
26+
const match = jobs[job].match(new RegExp(`^ ${key}: (.+)$`, "m"));
27+
assert.ok(match, `${job}.${key} must exist`);
28+
return match[1];
29+
};
30+
// Evaluate the small expression subset used by these production gates. Values
31+
// come from fixtures, never from a pull request title, path, or other metadata.
32+
function evaluate(expression, event, outputs, result = "success", check = "") {
33+
const translated = expression
34+
.replace(/^\$\{\{\s*|\s*\}\}$/g, "")
35+
.replace(/needs\.changes\.outputs\.([\w-]+)/g, (_, key) =>
36+
JSON.stringify(outputs[key] ?? ""),
37+
)
38+
.replaceAll("needs.changes.result", JSON.stringify(result))
39+
.replaceAll("github.event_name", JSON.stringify(event))
40+
.replaceAll("matrix.check", JSON.stringify(check))
41+
.replaceAll("always()", "true");
42+
return Function(
43+
"format",
44+
`return (${translated});`,
45+
)((template, value) => template.replace("{0}", value));
46+
}
47+
const scratch = mkdtempSync(join(tmpdir(), "buzz-ci-selection-"));
48+
after(() => rmSync(scratch, { recursive: true, force: true }));
49+
const actionSha = workflow.match(/uses: dorny\/paths-filter@([a-f0-9]{40})/)[1];
50+
const filters = workflow
51+
.match(/ {10}filters: \|\n([\s\S]*?)(?= {6}- name:)/)[1]
52+
.split("\n")
53+
.map((line) => line.slice(12))
54+
.join("\n");
55+
let actionPath;
56+
async function select(paths) {
57+
if (!actionPath) {
58+
// Exercise the exact bundled matcher CI executes, including negation and
59+
// dotfile semantics, instead of maintaining an approximation of picomatch.
60+
actionPath = join(scratch, "paths-filter.cjs");
61+
execFileSync("curl", [
62+
"--fail",
63+
"--silent",
64+
"--show-error",
65+
"--max-time",
66+
"30",
67+
"-o",
68+
actionPath,
69+
`https://raw.githubusercontent.com/dorny/paths-filter/${actionSha}/dist/index.js`,
70+
]);
71+
}
72+
const repo = mkdtempSync(join(scratch, "repo-"));
73+
const git = (...args) =>
74+
execFileSync("git", args, { cwd: repo, stdio: "pipe" });
75+
git("init", "-q");
76+
// Fixture repositories must not inherit developer machine hooks.
77+
mkdirSync(join(repo, "empty-hooks"));
78+
git("config", "core.hooksPath", join(repo, "empty-hooks"));
79+
git(
80+
"-c",
81+
"user.name=CI fixture",
82+
"-c",
83+
84+
"-c",
85+
"commit.gpgsign=false",
86+
"commit",
87+
"-q",
88+
"--allow-empty",
89+
"-m",
90+
"fixture",
91+
"-s",
92+
);
93+
for (const path of paths) {
94+
mkdirSync(dirname(join(repo, path)), { recursive: true });
95+
writeFileSync(join(repo, path), "fixture\n");
96+
}
97+
git("add", ".");
98+
const output = join(repo, "action-output");
99+
writeFileSync(output, "");
100+
const child = spawnSync(process.execPath, [actionPath], {
101+
cwd: repo,
102+
encoding: "utf8",
103+
timeout: 30000,
104+
env: {
105+
...process.env,
106+
INPUT_BASE: "HEAD",
107+
INPUT_FILTERS: filters,
108+
INPUT_TOKEN: "",
109+
INPUT_REF: "",
110+
GITHUB_OUTPUT: output,
111+
"INPUT_PREDICATE-QUANTIFIER":
112+
workflow.match(/predicate-quantifier: ['"]?([\w-]+)/)?.[1] ?? "some",
113+
},
114+
});
115+
assert.equal(child.status, 0, child.stdout + child.stderr);
116+
return Object.fromEntries(
117+
[
118+
...readFileSync(output, "utf8").matchAll(
119+
/^(rust|desktop|desktop-rust|web|mobile)<<([^\n]+)\n(true|false)\n\2/gm,
120+
),
121+
].map(([, key, , value]) => [key, value]),
122+
);
123+
}
124+
const scenarios = [
125+
[
126+
"mobile source and tests",
127+
[
128+
"mobile/lib/features/age_gate/age_signal_provider.dart",
129+
"mobile/test/features/age_gate/age_signal_provider_test.dart",
130+
],
131+
["mobile"],
132+
],
133+
["mobile lockfile", ["mobile/pubspec.lock"], ["mobile"]],
134+
["mobile release script", ["scripts/mobile-release.sh"], ["mobile"]],
135+
["desktop", ["desktop/src/main.tsx"], ["desktop"]],
136+
["Tauri", ["desktop/src-tauri/src/main.rs"], ["desktop", "desktop-rust"]],
137+
["relay", ["crates/buzz-relay/src/main.rs"], ["rust"]],
138+
["migration", ["migrations/123.sql"], ["rust"]],
139+
["shared workflow", [".github/workflows/ci.yml"], ["rust", "mobile"]],
140+
[
141+
"mixed mobile and relay",
142+
["mobile/lib/main.dart", "crates/buzz-core/src/lib.rs"],
143+
["rust", "mobile"],
144+
],
145+
[
146+
"mixed mobile and desktop",
147+
["mobile/lib/main.dart", "desktop/src/main.tsx"],
148+
["desktop", "mobile"],
149+
],
150+
["web", ["web/src/main.tsx"], ["web"]],
151+
["documentation", ["README.md"], []],
152+
];
153+
for (const [name, paths, expected] of scenarios) {
154+
test(`real paths-filter: ${name}`, async () => {
155+
const outputs = await select(paths);
156+
assert.equal(Object.keys(outputs).length, 5);
157+
assert.deepEqual(
158+
Object.keys(outputs)
159+
.filter((key) => outputs[key] === "true")
160+
.sort(),
161+
expected.sort(),
162+
);
163+
const desktop =
164+
expected.includes("desktop") ||
165+
expected.includes("desktop-rust") ||
166+
expected.includes("rust");
167+
for (const job of [
168+
"desktop-domain",
169+
"desktop-macos-domain",
170+
"relay-artifacts-domain",
171+
"relay-domain",
172+
]) {
173+
assert.equal(
174+
evaluate(field(job, "if"), "pull_request", outputs),
175+
desktop,
176+
job,
177+
);
178+
assert.equal(
179+
evaluate(field(job, "if"), "push", outputs),
180+
true,
181+
`${job} on push`,
182+
);
183+
}
184+
assert.equal(
185+
evaluate(field("postgres-domain", "if"), "pull_request", outputs),
186+
expected.includes("rust"),
187+
);
188+
});
189+
}
190+
const checks = {
191+
"backend-integration": [
192+
"Backend Integration (relay e2e)",
193+
"relay-domain",
194+
"backend_integration_result",
195+
],
196+
"relay-e2e": ["Relay E2E", "relay-domain", "relay_e2e_result"],
197+
"postgres-tests": [
198+
"PostgreSQL Tests",
199+
"postgres-domain",
200+
"postgres_tests_result",
201+
],
202+
};
203+
test("unneeded backend contexts have no dependency on desktop or relay work", () => {
204+
assert.equal(field("backend-not-required", "needs"), "[changes]");
205+
for (const [name] of Object.values(checks))
206+
assert.ok(jobs["backend-not-required"].includes(`'${name}'`));
207+
const run = jobs["backend-not-required"].match(/ {8}run: \|\n([\s\S]*)/)[1];
208+
for (const result of ["success", "failure", "cancelled", "skipped", ""]) {
209+
for (const rust of ["false", "true", ""]) {
210+
const child = spawnSync("bash", ["-e", "-c", run], {
211+
env: { ...process.env, CHANGES_RESULT: result, RUST: rust },
212+
encoding: "utf8",
213+
});
214+
assert.equal(
215+
child.status === 0,
216+
result === "success" && rust === "false",
217+
);
218+
}
219+
}
220+
});
221+
test("exactly one reporter owns each required name, including failed path detection", () => {
222+
for (const event of ["push", "pull_request"]) {
223+
for (const rust of ["true", "false", ""]) {
224+
for (const result of ["success", "failure", "cancelled", "skipped"]) {
225+
for (const [job, [name]] of Object.entries(checks)) {
226+
const outputs = { rust };
227+
const early = evaluate(
228+
field("backend-not-required", "if"),
229+
event,
230+
outputs,
231+
result,
232+
);
233+
const late = evaluate(field(job, "if"), event, outputs, result);
234+
assert.notEqual(early, late, `${event}/${rust}/${result}/${job}`);
235+
assert.equal(
236+
evaluate(
237+
field("backend-not-required", "name"),
238+
event,
239+
outputs,
240+
result,
241+
name,
242+
) === name,
243+
early,
244+
);
245+
assert.equal(
246+
evaluate(field(job, "name"), event, outputs, result) === name,
247+
late,
248+
);
249+
}
250+
}
251+
}
252+
}
253+
});
254+
test("selected backend gates fail on missing, failed, cancelled, or skipped test results", () => {
255+
for (const [job, [, domain, output]] of Object.entries(checks)) {
256+
assert.ok(field(job, "needs").includes(domain));
257+
assert.ok(
258+
jobs[job].includes(`RESULT: \${{ needs.${domain}.outputs.${output} }}`),
259+
);
260+
const run = jobs[job].match(/ {8}run: (.+)/)[1];
261+
for (const result of ["success", "failure", "cancelled", "skipped", ""]) {
262+
const child = spawnSync("bash", ["-e", "-c", run], {
263+
env: { ...process.env, RESULT: result },
264+
});
265+
assert.equal(
266+
child.status === 0,
267+
result === "success",
268+
`${job}/${result}`,
269+
);
270+
}
271+
}
272+
});

0 commit comments

Comments
 (0)