From 511ac68353faed9a70fe74281ca050ea6b67d657 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 9 Oct 2026 11:35:54 +0100 Subject: [PATCH] Use `macOSVersion` in `isSwiftCompatible` --- lib/entry-points.js | 22 +++++++++++++++++++++- src/languages/swift.test.ts | 18 +++++++++++++++++- src/languages/swift.ts | 24 +++++++++++++++++++----- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index eccce77eb..e727825c6 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -175650,6 +175650,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"; @@ -186035,11 +186045,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 diff --git a/src/languages/swift.test.ts b/src/languages/swift.test.ts index b0ddc89a3..ecbaae76f 100644 --- a/src/languages/swift.test.ts +++ b/src/languages/swift.test.ts @@ -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", + ]); +}); diff --git a/src/languages/swift.ts b/src/languages/swift.ts index 501e7a027..fa6517c6d 100644 --- a/src/languages/swift.ts +++ b/src/languages/swift.ts @@ -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; + } }