Use macOSVersion in isSwiftCompatible

This commit is contained in:
Michael B. Gale
2026-10-09 11:35:54 +01:00
parent 8ac4f4481b
commit d6fd306480
3 changed files with 57 additions and 7 deletions

22
lib/entry-points.js generated
View File

@@ -175614,6 +175614,16 @@ function getBundlePlatform(platform2 = process.platform, arch2 = process.arch) {
return void 0;
}
}
function macOSVersion(action) {
if (action.platform !== "darwin") {
return void 0;
}
const version = semver7.parse(action.osRelease);
if (version === null) {
return action.osRelease;
}
return version;
}
// src/per-language-bundles.ts
var MIN_PER_LANGUAGE_BUNDLE_CLI_VERSION = "2.27.1";
@@ -186019,11 +186029,21 @@ async function getToolsInput(action, repositoryProperties) {
// src/languages/swift.ts
function isSwiftCompatible(action, config) {
if (config.languages.includes("swift" /* swift */) && action.platform !== "darwin") {
if (!config.languages.includes("swift" /* swift */)) {
return;
}
const version = macOSVersion(action);
if (version === void 0) {
throw new ConfigurationError(
`Swift analysis is only supported on macOS runner images. Please migrate to a macOS runner.`
);
}
if (typeof version === "string") {
action.logger.warning(
`Unable to determine version of macOS, got: ${version}`
);
return;
}
}
// src/status-report/tools-download.ts

View File

@@ -1,6 +1,11 @@
import test from "ava";
import { createTestConfig, initAllState } from "../testing-utils";
import {
checkExpectedLogMessages,
createTestConfig,
initAllState,
RecordingLogger,
} from "../testing-utils";
import { isSwiftCompatible } from "./swift";
@@ -41,3 +46,14 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
});
});
}
test("isSwiftCompatible warns if version string is not a semver", (t) => {
const logger = new RecordingLogger();
isSwiftCompatible(
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 ".";
@@ -14,15 +15,28 @@ import { BuiltInLanguage } from ".";
* @returns True if we can run a Swift analysis.
*/
export function isSwiftCompatible(
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;
}
}