|
1 | 1 | import { performance } from "node:perf_hooks"; |
| 2 | +import { accessSync, constants } from "node:fs"; |
| 3 | +import path from "node:path"; |
2 | 4 | import { |
3 | 5 | detectChangedLanesForPaths, |
4 | 6 | listChangedPathsFromGit, |
@@ -41,6 +43,38 @@ function isTruthyEnvFlag(value) { |
41 | 43 | return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "no"; |
42 | 44 | } |
43 | 45 |
|
| 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 | + |
44 | 78 | export function shouldDelegateChangedCheckToCrabbox(argv = [], env = process.env) { |
45 | 79 | if (!isTruthyEnvFlag(env.OPENCLAW_TESTBOX)) { |
46 | 80 | return false; |
@@ -198,7 +232,17 @@ export function createChangedCheckPlan(result, options = {}) { |
198 | 232 | if (lanes.tooling || lanes.liveDockerTooling) { |
199 | 233 | addLint("lint scripts", ["lint:scripts"]); |
200 | 234 | } |
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) { |
202 | 246 | addLint("lint apps", ["lint:apps"]); |
203 | 247 | } |
204 | 248 |
|
|
0 commit comments