Skip to content

Commit 540a4a7

Browse files
committed
fix(ci): handle missing SwiftLint in Testbox changed checks
1 parent 903d9c1 commit 540a4a7

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎scripts/check-changed.mjs‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { performance } from "node:perf_hooks";
2+
import { accessSync, constants } from "node:fs";
3+
import path from "node:path";
24
import {
35
detectChangedLanesForPaths,
46
listChangedPathsFromGit,
@@ -41,6 +43,38 @@ function isTruthyEnvFlag(value) {
4143
return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no";
4244
}
4345

46+
function executableExistsOnPath(command, env = process.env) {
47+
const pathValue = env.PATH ?? env.Path ?? "";
48+
const pathExts =
49+
process.platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";") : [""];
50+
for (const searchPath of pathValue.split(path.delimiter)) {
51+
if (!searchPath) {
52+
continue;
53+
}
54+
for (const ext of pathExts) {
55+
try {
56+
accessSync(path.join(searchPath, `${command}${ext}`), constants.X_OK);
57+
return true;
58+
} catch {
59+
continue;
60+
}
61+
}
62+
}
63+
return false;
64+
}
65+
66+
export function shouldSkipAppLintForMissingSwiftlint(options = {}) {
67+
const env = options.env ?? process.env;
68+
const platform = options.platform ?? process.platform;
69+
const swiftlintAvailable =
70+
options.swiftlintAvailable ?? executableExistsOnPath("swiftlint", env);
71+
return (
72+
isTruthyEnvFlag(env.OPENCLAW_TESTBOX_REMOTE_RUN) &&
73+
platform !== "darwin" &&
74+
!swiftlintAvailable
75+
);
76+
}
77+
4478
export function shouldDelegateChangedCheckToCrabbox(argv = [], env = process.env) {
4579
if (!isTruthyEnvFlag(env.OPENCLAW_TESTBOX)) {
4680
return false;
@@ -198,7 +232,17 @@ export function createChangedCheckPlan(result, options = {}) {
198232
if (lanes.tooling || lanes.liveDockerTooling) {
199233
addLint("lint scripts", ["lint:scripts"]);
200234
}
201-
if (lanes.apps) {
235+
if (lanes.apps && shouldSkipAppLintForMissingSwiftlint({ ...options, env: baseEnv })) {
236+
addCommand(
237+
"lint apps (swiftlint unavailable in Testbox)",
238+
"node",
239+
[
240+
"-e",
241+
"console.error('[check:changed] Swift app lint skipped: swiftlint is unavailable in this Linux Testbox; macOS CI owns SwiftLint coverage.')",
242+
],
243+
baseEnv,
244+
);
245+
} else if (lanes.apps) {
202246
addLint("lint apps", ["lint:apps"]);
203247
}
204248

‎test/scripts/changed-lanes.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,41 @@ describe("scripts/changed-lanes", () => {
865865
expect(plan.commands.map((command) => command.args[0])).not.toContain("tsgo:all");
866866
});
867867

868+
it("keeps app lint explicit when Linux Testbox lacks SwiftLint", () => {
869+
const result = detectChangedLanes([
870+
"apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift",
871+
]);
872+
const plan = createChangedCheckPlan(result, {
873+
env: { OPENCLAW_TESTBOX_REMOTE_RUN: "1", PATH: "/usr/bin" },
874+
platform: "linux",
875+
swiftlintAvailable: false,
876+
});
877+
878+
expectLanes(result.lanes, {
879+
apps: true,
880+
});
881+
expect(plan.commands.map((command) => command.args[0])).not.toContain("lint:apps");
882+
expect(plan.commands).toContainEqual(
883+
expect.objectContaining({
884+
name: "lint apps (swiftlint unavailable in Testbox)",
885+
bin: "node",
886+
}),
887+
);
888+
});
889+
890+
it("runs app lint when SwiftLint is available in Testbox", () => {
891+
const result = detectChangedLanes([
892+
"apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift",
893+
]);
894+
const plan = createChangedCheckPlan(result, {
895+
env: { OPENCLAW_TESTBOX_REMOTE_RUN: "1", PATH: "/usr/bin" },
896+
platform: "linux",
897+
swiftlintAvailable: true,
898+
});
899+
900+
expect(plan.commands.map((command) => command.args[0])).toContain("lint:apps");
901+
});
902+
868903
it("routes legacy root asset deletions as tooling during root cleanup", () => {
869904
const result = detectChangedLanes([
870905
"assets/avatar-placeholder.svg",

0 commit comments

Comments
 (0)