Check if macOS version is unsupported

This commit is contained in:
Michael B. Gale
2026-10-09 15:51:31 +01:00
committed by GitHub
parent fbefdc443a
commit f48ee7b3f6
3 changed files with 133 additions and 0 deletions

31
lib/entry-points.js generated
View File

@@ -186083,6 +186083,8 @@ async function getToolsInput(action, repositoryProperties) {
}
// src/languages/swift.ts
var SWIFT_TRACED_UNSUPPORTED_MACOS = 27;
var SWIFT_TRACED_UNSUPPORTED_XCODE = 27;
async function isSwiftCompatible(action, config, codeql) {
if (!config.languages.includes("swift" /* swift */)) {
return;
@@ -186102,6 +186104,35 @@ async function isSwiftCompatible(action, config, codeql) {
);
return;
}
if (version.major >= SWIFT_TRACED_UNSUPPORTED_MACOS) {
const baseMessage = [
`Traced Swift analysis is not supported on macOS ${SWIFT_TRACED_UNSUPPORTED_MACOS} or above.`,
`Configure your analysis to run on macOS ${SWIFT_TRACED_UNSUPPORTED_MACOS - 1} or below`,
`and XCode ${SWIFT_TRACED_UNSUPPORTED_XCODE - 1} or below.`
].join(" ");
action.logger.warning(baseMessage);
addDiagnostic(
config,
"swift" /* swift */,
makeDiagnostic(
"codeql-action/unsupported-traced-swift-analysis-macos",
"Traced Swift analysis is not supported on this version of macOS",
{
attributes: {
languages: config.languages,
macOSVersion: version.toString()
},
markdownMessage: baseMessage,
severity: "warning",
visibility: {
cliSummaryTable: true,
statusPage: true,
telemetry: true
}
}
)
);
}
}
// src/status-report/tools-download.ts

View File

@@ -2,6 +2,7 @@ import test from "ava";
import * as sinon from "sinon";
import { getCodeQLForTesting } from "../codeql";
import * as diagnostics from "../diagnostics";
import { ActionsEnvVars } from "../environment";
import {
checkExpectedLogMessages,
@@ -10,6 +11,7 @@ import {
initAllState,
makeVersionInfo,
RecordingLogger,
setupTests,
} from "../testing-utils";
import { ToolsFeature } from "../tools-features";
import { withTmpDir } from "../util";
@@ -18,6 +20,8 @@ import { isSwiftCompatible } from "./swift";
import { BuiltInLanguage } from ".";
setupTests(test);
test("isSwiftCompatible doesn't throw for non-Swift languages", async (t) => {
for (const language of Object.values(BuiltInLanguage)) {
if (language === BuiltInLanguage.swift) {
@@ -128,3 +132,60 @@ test("isSwiftCompatible warns if version string is not a semver", async (t) =>
"Unable to determine version of macOS, got: unexpected",
]);
}));
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
test.serial(
"isSwiftCompatible logs and adds diagnostic if macOS version is unsupported",
async (t) =>
withTmpDir(async (tmpDir) => {
const logger = new RecordingLogger();
const env = getTestEnv();
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
const codeql = await getCodeQLForTesting(
"codeql-for-testing",
logger,
env,
);
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
const addDiagnostic = sinon.stub(diagnostics, "addDiagnostic");
const config = createTestConfig({ languages: [BuiltInLanguage.swift] });
await isSwiftCompatible(
initAllState({
logger,
platform: "darwin",
osRelease: "27.0.0",
env,
}),
config,
codeql,
);
checkExpectedLogMessages(t, logger.messages, [
"Traced Swift analysis is not supported on macOS 27",
]);
t.is(addDiagnostic.callCount, 1);
t.like(addDiagnostic.args[0], [
config,
BuiltInLanguage.swift,
{
attributes: {
languages: [BuiltInLanguage.swift],
macOSVersion: "27.0.0",
},
source: {
id: "codeql-action/unsupported-traced-swift-analysis-macos",
name: "Traced Swift analysis is not supported on this version of macOS",
},
visibility: {
cliSummaryTable: true,
statusPage: true,
telemetry: true,
},
} satisfies Partial<diagnostics.DiagnosticMessage>,
]);
}),
);

View File

@@ -1,12 +1,19 @@
import { ActionState } from "../action-common";
import { CodeQL } from "../codeql";
import { Config } from "../config-utils";
import { addDiagnostic, makeDiagnostic } from "../diagnostics";
import { macOSVersion } from "../platform";
import { ToolsFeature } from "../tools-features";
import { ConfigurationError } from "../util";
import { BuiltInLanguage } from ".";
/** macOS 27 and above do not support traced extraction for Swift. */
export const SWIFT_TRACED_UNSUPPORTED_MACOS = 27;
/** Xcode 27 and above do not support traced extraction for Swift. */
export const SWIFT_TRACED_UNSUPPORTED_XCODE = 27;
/**
* Determines whether we can run a Swift analysis on the current runner.
*
@@ -49,4 +56,38 @@ export async function isSwiftCompatible(
);
return;
}
if (version.major >= SWIFT_TRACED_UNSUPPORTED_MACOS) {
const baseMessage = [
`Traced Swift analysis is not supported on macOS ${SWIFT_TRACED_UNSUPPORTED_MACOS} or above.`,
`Configure your analysis to run on macOS ${SWIFT_TRACED_UNSUPPORTED_MACOS - 1} or below`,
`and XCode ${SWIFT_TRACED_UNSUPPORTED_XCODE - 1} or below.`,
].join(" ");
// Log the message. This will also show up as a workflow annotation.
action.logger.warning(baseMessage);
// Create a diagnostic that will show up on the TSP.
addDiagnostic(
config,
BuiltInLanguage.swift,
makeDiagnostic(
"codeql-action/unsupported-traced-swift-analysis-macos",
"Traced Swift analysis is not supported on this version of macOS",
{
attributes: {
languages: config.languages,
macOSVersion: version.toString(),
},
markdownMessage: baseMessage,
severity: "warning",
visibility: {
cliSummaryTable: true,
statusPage: true,
telemetry: true,
},
},
),
);
}
}