From afed03cada4ee7f8760f99b3cfe9f729e7c935f0 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 16 Oct 2026 22:56:47 +0100 Subject: [PATCH] Don't perform check for non-traced analyses --- lib/entry-points.js | 14 +++++ src/languages/traced.test.ts | 106 +++++++++++++++++++++++++++++++---- src/languages/traced.ts | 27 +++++++++ 3 files changed, 137 insertions(+), 10 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index b405963a1..d25bdb1ea 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -186270,9 +186270,23 @@ function handleUnsupportedVersion(logger2, config, skipUnsupportedTracedAnalysis logger2.warning(baseMessage); } } +async function hasTracedLanguages(config, codeql) { + for (const language of config.languages) { + if (await codeql.isTracedLanguage(language)) { + return true; + } + } + return false; +} async function checkRunnerSupportsTracedAnalysis(action, config, codeql) { const version = macOSVersion(action); await isSwiftCompatible(config, codeql, version); + if (config.buildMode !== void 0 && config.buildMode === "none") { + return; + } + if (!await hasTracedLanguages(config, codeql)) { + return; + } const skipUnsupportedTracedAnalysis = await action.features.getValue( "skip_unsupported_traced_analysis" /* SkipUnsupportedTracedAnalysis */ ); diff --git a/src/languages/traced.test.ts b/src/languages/traced.test.ts index 3f4a530d3..459db3789 100644 --- a/src/languages/traced.test.ts +++ b/src/languages/traced.test.ts @@ -3,10 +3,11 @@ import fs from "fs"; import test from "ava"; import * as sinon from "sinon"; -import { getCodeQLForTesting } from "../codeql"; +import { getCodeQLForTesting, type CodeQL } from "../codeql"; import * as diagnostics from "../diagnostics"; -import { ActionsEnvVars } from "../environment"; +import { ActionsEnvVars, type Env } from "../environment"; import { Feature } from "../feature-flags"; +import type { Logger } from "../logging"; import { XCODE_SELECT_LINK_PATH } from "../platform"; import { checkExpectedLogMessages, @@ -19,7 +20,7 @@ import { RecordingLogger, setupTests, } from "../testing-utils"; -import { withTmpDir } from "../util"; +import { BuildMode, withTmpDir } from "../util"; import { checkRunnerSupportsTracedAnalysis } from "./traced"; @@ -27,6 +28,26 @@ import { BuiltInLanguage } from "."; setupTests(test); +const TEST_DEFAULT_TRACED_LANGUAGES = { + [BuiltInLanguage.swift]: true, + [BuiltInLanguage.go]: true, +}; + +async function getCodeQLWithTracedStub( + cmd: string, + logger: Logger, + env: Env, + tracedLanguages: Partial< + Record + > = TEST_DEFAULT_TRACED_LANGUAGES, +): Promise { + const codeql = await getCodeQLForTesting(cmd, logger, env); + sinon.stub(codeql, "isTracedLanguage").callsFake(async (language) => { + return tracedLanguages[language] === true; + }); + return codeql; +} + const nonDarwinPlatforms: NodeJS.Platform[] = ["linux", "win32"]; for (const nonDarwinPlatform of nonDarwinPlatforms) { test(`checkRunnerSupportsTracedAnalysis throws for Swift on ${nonDarwinPlatform}`, async (t) => @@ -35,7 +56,7 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) { const env = getTestEnv(); env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, @@ -52,13 +73,78 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) { })); } +test(`checkRunnerSupportsTracedAnalysis doesn't throw for BMN`, async (t) => + withTmpDir(async (tmpDir) => { + const logger = new RecordingLogger(); + const env = getTestEnv(); + env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir); + + const codeql = await getCodeQLWithTracedStub( + "codeql-for-testing", + logger, + env, + ); + sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0")); + + await t.notThrowsAsync( + checkRunnerSupportsTracedAnalysis( + initAllState({ + platform: "darwin", + osRelease: "27.0.0", + env, + logger, + }), + createTestConfig({ buildMode: BuildMode.None }), + codeql, + ), + ); + })); + +// Some languages not in `TEST_DEFAULT_TRACED_LANGUAGES`. +const nonTracedLanguages: BuiltInLanguage[] = [ + BuiltInLanguage.javascript, + BuiltInLanguage.actions, +]; +for (const nonTracedLanguage of nonTracedLanguages) { + test(`checkRunnerSupportsTracedAnalysis doesn't throw for ${nonTracedLanguage} on unsupported macOS`, async (t) => + withTmpDir(async (tmpDir) => { + const logger = new RecordingLogger(); + const env = getTestEnv(); + env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir); + + const codeql = await getCodeQLWithTracedStub( + "codeql-for-testing", + logger, + env, + ); + sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0")); + + await t.notThrowsAsync( + checkRunnerSupportsTracedAnalysis( + initAllState({ + platform: "darwin", + osRelease: "27.0.0", + env, + logger, + }), + createTestConfig({ languages: [nonTracedLanguage] }), + codeql, + ), + ); + })); +} + test("checkRunnerSupportsTracedAnalysis warns if version string is not a semver", 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); + const codeql = await getCodeQLWithTracedStub( + "codeql-for-testing", + logger, + env, + ); sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0")); await checkRunnerSupportsTracedAnalysis( @@ -86,7 +172,7 @@ test.serial( const env = getTestEnv(); env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, @@ -146,7 +232,7 @@ test.serial( const features = createFeatures([Feature.SkipUnsupportedTracedAnalysis]); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, @@ -210,7 +296,7 @@ test.serial( .stub(fs, "readlinkSync") .returns("/Applications/Xcode_26.0.app/Contents/Developer"); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, @@ -260,7 +346,7 @@ test.serial( .stub(fs, "readlinkSync") .returns("/Applications/Xcode_27.0.app/Contents/Developer"); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, @@ -332,7 +418,7 @@ test.serial( const features = createFeatures([Feature.SkipUnsupportedTracedAnalysis]); - const codeql = await getCodeQLForTesting( + const codeql = await getCodeQLWithTracedStub( "codeql-for-testing", logger, env, diff --git a/src/languages/traced.ts b/src/languages/traced.ts index 1eaa04dd8..07f4cdc96 100644 --- a/src/languages/traced.ts +++ b/src/languages/traced.ts @@ -78,6 +78,23 @@ function handleUnsupportedVersion( } } +/** + * Decides whether {@link config} has any traced languages by looking for tracer + * configurations in the {@link codeql} CLI installation. + */ +export async function hasTracedLanguages( + config: ActionConfig<"languages">, + codeql: CodeQL, +): Promise { + for (const language of config.languages) { + if (await codeql.isTracedLanguage(language)) { + return true; + } + } + + return false; +} + /** * Determines whether we can run a traced analysis on the current runner. * @@ -94,6 +111,16 @@ export async function checkRunnerSupportsTracedAnalysis( // Perform some initial, Swift-specific checks. await isSwiftCompatible(config, codeql, version); + // `build-mode: none` doesn't use the tracer, so it is always supported. + if (config.buildMode !== undefined && config.buildMode === "none") { + return; + } + + // If none of the languages are traced, then we can skip the compatibility checks below as well. + if (!(await hasTracedLanguages(config, codeql))) { + return; + } + const skipUnsupportedTracedAnalysis = await action.features.getValue( Feature.SkipUnsupportedTracedAnalysis, );