Skip to content

Commit 01b6174

Browse files
authored
fix(ci): don't run desktop tests for purely mobile client changes (block#7709)
Mobile-only PRs currently trigger desktop CI because the desktop test filter's glob inadvertently matches every path outside Tauri. Fix that filter so that pure mobile changes skip desktop builds, tests, and their relay artifact producer. ### Verification - 12 regression tests exercise the exact pinned paths-filter action on mobile, desktop, Tauri, backend, mixed, workflow, and documentation changes. - Restoring the bad glob makes the mobile-only regression test fail. - The filter tests, existing required-context isolation contract, workflow syntax validation, and Biome pass locally. --------- Signed-off-by: Tom Brow <[email protected]>
1 parent d1cae93 commit 01b6174

2 files changed

Lines changed: 142 additions & 1 deletion

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
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/**'
@@ -114,6 +113,8 @@ jobs:
114113
scripts/test-rust-cache-contract-regressions.sh
115114
- name: CI required-context isolation contract
116115
run: scripts/test-ci-required-context-isolation.sh
116+
- name: CI path selection regression tests
117+
run: node --test scripts/ci-selection.test.mjs
117118
- name: File size policy
118119
run: just file-size-check
119120

‎scripts/ci-selection.test.mjs‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync, spawnSync } from "node:child_process";
3+
import {
4+
existsSync,
5+
mkdtempSync,
6+
mkdirSync,
7+
readFileSync,
8+
rmSync,
9+
writeFileSync,
10+
} from "node:fs";
11+
import { tmpdir } from "node:os";
12+
import { dirname, join } from "node:path";
13+
import { after, test } from "node:test";
14+
15+
const workflow = readFileSync(
16+
new URL("../.github/workflows/ci.yml", import.meta.url),
17+
"utf8",
18+
);
19+
const scratch = mkdtempSync(join(tmpdir(), "buzz-ci-selection-"));
20+
after(() => rmSync(scratch, { recursive: true, force: true }));
21+
const actionSha = workflow.match(/uses: dorny\/paths-filter@([a-f0-9]{40})/)[1];
22+
const filters = workflow
23+
.match(/ {10}filters: \|\n([\s\S]*?)(?= {6}- name:)/)[1]
24+
.split("\n")
25+
.map((line) => line.slice(12))
26+
.join("\n");
27+
// GitHub-hosted runners prepare pinned actions beside RUNNER_TEMP before any
28+
// steps run. Reuse that bundle, without another download in the selection gate.
29+
// Locally, point PATHS_FILTER_ACTION at dist/index.js from the pinned action.
30+
const actionPath =
31+
process.env.PATHS_FILTER_ACTION ||
32+
(process.env.RUNNER_TEMP &&
33+
join(
34+
process.env.RUNNER_TEMP,
35+
"..",
36+
"_actions",
37+
"dorny",
38+
"paths-filter",
39+
actionSha,
40+
"dist",
41+
"index.js",
42+
));
43+
assert.ok(
44+
actionPath && existsSync(actionPath),
45+
`Set PATHS_FILTER_ACTION to the local dist/index.js from dorny/paths-filter@${actionSha}`,
46+
);
47+
function select(paths) {
48+
const repo = mkdtempSync(join(scratch, "repo-"));
49+
const git = (...args) =>
50+
execFileSync("git", args, { cwd: repo, stdio: "pipe", timeout: 10000 });
51+
git("init", "-q");
52+
// Fixture repositories must not inherit developer machine hooks.
53+
mkdirSync(join(repo, "empty-hooks"));
54+
git("config", "core.hooksPath", join(repo, "empty-hooks"));
55+
git(
56+
"-c",
57+
"user.name=CI fixture",
58+
"-c",
59+
60+
"-c",
61+
"commit.gpgsign=false",
62+
"commit",
63+
"-q",
64+
"--allow-empty",
65+
"-m",
66+
"fixture",
67+
"-s",
68+
);
69+
for (const path of paths) {
70+
mkdirSync(dirname(join(repo, path)), { recursive: true });
71+
writeFileSync(join(repo, path), "fixture\n");
72+
}
73+
git("add", ".");
74+
const output = join(repo, "action-output");
75+
writeFileSync(output, "");
76+
const child = spawnSync(process.execPath, [actionPath], {
77+
cwd: repo,
78+
encoding: "utf8",
79+
timeout: 30000,
80+
env: {
81+
...process.env,
82+
INPUT_BASE: "HEAD",
83+
INPUT_FILTERS: filters,
84+
INPUT_TOKEN: "",
85+
INPUT_REF: "",
86+
GITHUB_OUTPUT: output,
87+
"INPUT_PREDICATE-QUANTIFIER":
88+
workflow.match(/predicate-quantifier: ['"]?([\w-]+)/)?.[1] ?? "some",
89+
},
90+
});
91+
assert.equal(child.status, 0, child.stdout + child.stderr);
92+
return Object.fromEntries(
93+
[
94+
...readFileSync(output, "utf8").matchAll(
95+
/^(rust|desktop|desktop-rust|web|mobile)<<([^\n]+)\n(true|false)\n\2/gm,
96+
),
97+
].map(([, key, , value]) => [key, value]),
98+
);
99+
}
100+
const scenarios = [
101+
[
102+
"mobile source and tests",
103+
[
104+
"mobile/lib/features/age_gate/age_signal_provider.dart",
105+
"mobile/test/features/age_gate/age_signal_provider_test.dart",
106+
],
107+
["mobile"],
108+
],
109+
["mobile lockfile", ["mobile/pubspec.lock"], ["mobile"]],
110+
["mobile release script", ["scripts/mobile-release.sh"], ["mobile"]],
111+
["desktop", ["desktop/src/main.tsx"], ["desktop"]],
112+
["Tauri", ["desktop/src-tauri/src/main.rs"], ["desktop", "desktop-rust"]],
113+
["relay", ["crates/buzz-relay/src/main.rs"], ["rust"]],
114+
["migration", ["migrations/123.sql"], ["rust"]],
115+
["shared workflow", [".github/workflows/ci.yml"], ["rust", "mobile"]],
116+
[
117+
"mixed mobile and relay",
118+
["mobile/lib/main.dart", "crates/buzz-core/src/lib.rs"],
119+
["rust", "mobile"],
120+
],
121+
[
122+
"mixed mobile and desktop",
123+
["mobile/lib/main.dart", "desktop/src/main.tsx"],
124+
["desktop", "mobile"],
125+
],
126+
["web", ["web/src/main.tsx"], ["web"]],
127+
["documentation", ["README.md"], []],
128+
];
129+
for (const [name, paths, expected] of scenarios) {
130+
test(`real paths-filter: ${name}`, () => {
131+
const outputs = select(paths);
132+
assert.equal(Object.keys(outputs).length, 5);
133+
assert.deepEqual(
134+
Object.keys(outputs)
135+
.filter((key) => outputs[key] === "true")
136+
.sort(),
137+
expected.sort(),
138+
);
139+
});
140+
}

0 commit comments

Comments
 (0)