diff --git a/lib/entry-points.js b/lib/entry-points.js index f46c91b54..93c634319 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -186044,6 +186044,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; @@ -186063,6 +186065,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 diff --git a/src/languages/swift.test.ts b/src/languages/swift.test.ts index 745f631b5..152775682 100644 --- a/src/languages/swift.test.ts +++ b/src/languages/swift.test.ts @@ -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, + ]); + }), +); diff --git a/src/languages/swift.ts b/src/languages/swift.ts index 3b6d70959..21172951b 100644 --- a/src/languages/swift.ts +++ b/src/languages/swift.ts @@ -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, + }, + }, + ), + ); + } }