Skip to content

Commit 8f2596e

Browse files
committed
Remove xcodeVersion and inline fallback logic in checkRunnerSupportsTracedAnalysis
1 parent 1fb9308 commit 8f2596e

5 files changed

Lines changed: 68 additions & 44 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/languages/traced.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "fs";
22

3+
import * as io from "@actions/io";
34
import test from "ava";
45
import * as sinon from "sinon";
56

@@ -426,6 +427,61 @@ test.serial(
426427
}),
427428
);
428429

430+
test.serial(
431+
"checkRunnerSupportsTracedAnalysis uses Xcode SDK version as fallback",
432+
async (t) =>
433+
withTmpDir(async (tmpDir) => {
434+
const logger = new RecordingLogger();
435+
const env = getTestEnv();
436+
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
437+
const features = createFeatures([Feature.CheckUnsupportedTracedAnalysis]);
438+
439+
const readlinkSync = sinon
440+
.stub(fs, "readlinkSync")
441+
.throws(new Error("Not found"));
442+
const which = sinon.stub(io, "which").throws(new Error("Tool not found"));
443+
444+
const codeql = await getCodeQLWithTracedStub(
445+
"codeql-for-testing",
446+
logger,
447+
env,
448+
);
449+
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
450+
451+
const addDiagnostic = sinon.stub(diagnostics, "addDiagnostic");
452+
453+
const config = createTestConfig({
454+
tempDir: tmpDir,
455+
languages: [BuiltInLanguage.swift],
456+
});
457+
await checkRunnerSupportsTracedAnalysis(
458+
initAllState({
459+
logger,
460+
platform: "darwin",
461+
osRelease: "26.0.0",
462+
env,
463+
features,
464+
}),
465+
config,
466+
codeql,
467+
);
468+
469+
t.is(readlinkSync.callCount, 1);
470+
t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]);
471+
t.is(which.callCount, 1);
472+
t.deepEqual(which.args[0], ["xcrun", true]);
473+
474+
checkExpectedLogMessages(t, logger.messages, [
475+
"Unable to determine Xcode version: Tool not found",
476+
]);
477+
checkUnexpectedLogMessages(t, logger.messages, [
478+
"Traced analysis is not supported on Xcode 27",
479+
]);
480+
481+
t.is(addDiagnostic.callCount, 0);
482+
}),
483+
);
484+
429485
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
430486
test.serial(
431487
"checkRunnerSupportsTracedAnalysis logs and adds diagnostic if Xcode version is unsupported",

‎src/languages/traced.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import type { ActionConfig } from "../config/action-config";
77
import { addDiagnostic, makeDiagnostic } from "../diagnostics";
88
import { DocUrl } from "../doc-url";
99
import { Feature } from "../feature-flags";
10-
import { darwinVersion, xcodeVersion } from "../platform";
10+
import {
11+
darwinVersion,
12+
xcodeVersionFromLink,
13+
xcodeVersionFromSdk,
14+
} from "../platform";
1115
import { ConfigurationError } from "../util";
1216

1317
import { checkSwiftCompatibility } from "./swift";
@@ -196,8 +200,12 @@ export async function checkRunnerSupportsTracedAnalysis(
196200
}
197201

198202
// Determining whether the Xcode version is supported only makes sense on macOS, so we only do it
199-
// after determining that we are running on macOS.
200-
const xcodeVer = await xcodeVersion(action.logger);
203+
// after determining that we are running on macOS. We first try to obtain the version of Xcode itself
204+
// starting with the cheapest approach. If that doesn't work, we obtain the version from the SDK instead.
205+
// Since either Xcode or the SDK at version 27 or above is incompatible, the major version of either is fine.
206+
const xcodeVer =
207+
xcodeVersionFromLink(action.logger) ??
208+
(await xcodeVersionFromSdk(action.logger));
201209

202210
if (
203211
xcodeVer !== undefined &&

‎src/platform.test.ts‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
darwinVersion,
1313
XCODE_SELECT_LINK_PATH,
1414
xcodeVersionFromLink,
15-
xcodeVersion,
1615
xcodeVersionFromSdk,
1716
} from "./platform";
1817
import {
@@ -295,27 +294,3 @@ test.serial(
295294
});
296295
},
297296
);
298-
299-
test.serial("xcodeVersion falls back to xcodeVersionFromSdk", async (t) => {
300-
const logger = new RecordingLogger();
301-
302-
const readlinkSync = sinon
303-
.stub(fs, "readlinkSync")
304-
.throws(new Error("ENOENT: no such file or directory"));
305-
const which = sinon.stub(io, "which").throws(new Error("No such tool"));
306-
307-
await t.notThrowsAsync(async () => {
308-
const result = await xcodeVersion(logger);
309-
310-
t.is(result, undefined);
311-
312-
t.is(readlinkSync.callCount, 1);
313-
t.is(which.callCount, 1);
314-
t.deepEqual(which.args[0], ["xcrun", true]);
315-
316-
checkExpectedLogMessages(t, logger.messages, [
317-
"Unable to determine Xcode version: ENOENT: no such file or directory",
318-
"Unable to determine Xcode version: No such tool",
319-
]);
320-
});
321-
});

‎src/platform.ts‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,3 @@ export async function xcodeVersionFromSdk(
170170
return undefined;
171171
}
172172
}
173-
174-
/**
175-
* Tries to determine the version of Xcode that is installed.
176-
*
177-
* @param logger The logger to use.
178-
* @returns The Xcode version or `undefined` if it couldn't be determined.
179-
*/
180-
export async function xcodeVersion(
181-
logger: Logger,
182-
): Promise<semver.SemVer | undefined> {
183-
return xcodeVersionFromLink(logger) ?? (await xcodeVersionFromSdk(logger));
184-
}

0 commit comments

Comments
 (0)