Use macOSVersion in isSwiftCompatible

This commit is contained in:
Michael B. Gale
2026-10-09 11:35:54 +01:00
parent 570e438ccc
commit e0220172c9
3 changed files with 120 additions and 73 deletions

View File

@@ -3,6 +3,7 @@ import sinon from "sinon";
import { ActionsEnvVars } from "../environment";
import {
checkExpectedLogMessages,
createTestConfig,
getCodeQLForTesting,
getTestEnv,
@@ -68,3 +69,14 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
);
});
}
test("checkSwiftCompatibility warns if version string is not a semver", (t) => {
const logger = new RecordingLogger();
checkSwiftCompatibility(
initAllState({ logger, platform: "darwin", osRelease: "unexpected" }),
createTestConfig({ languages: [BuiltInLanguage.swift] }),
);
checkExpectedLogMessages(t, logger.messages, [
"Unable to determine version of macOS, got: unexpected",
]);
});

View File

@@ -1,5 +1,6 @@
import { ActionState } from "../action-common";
import { Config } from "../config-utils";
import { macOSVersion } from "../platform";
import { ConfigurationError } from "../util";
import { BuiltInLanguage } from ".";
@@ -13,15 +14,28 @@ import { BuiltInLanguage } from ".";
* @throws {ConfigurationError} If Swift analysis is not possible on the current runner.
*/
export function checkSwiftCompatibility(
action: ActionState<["Base"]>,
action: ActionState<["Base", "Logger"]>,
config: Config,
) {
if (
config.languages.includes(BuiltInLanguage.swift) &&
action.platform !== "darwin"
) {
// The checks are not relevant if we are not trying to analyse Swift.
if (!config.languages.includes(BuiltInLanguage.swift)) {
return;
}
// Try to get the macOS version.
const version = macOSVersion(action);
// If `version` is undefined, then we are not on macOS.
if (version === undefined) {
throw new ConfigurationError(
`Swift analysis is only supported on macOS runner images. Please migrate to a macOS runner.`,
);
}
// If we got a string, we are on macOS but couldn't parse the version string.
if (typeof version === "string") {
action.logger.warning(
`Unable to determine version of macOS, got: ${version}`,
);
return;
}
}