Skip to content

Commit c85a167

Browse files
authored
Don't perform check for non-traced analyses
1 parent 4254c07 commit c85a167

3 files changed

Lines changed: 137 additions & 10 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/languages/traced.test.ts‎

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import fs from "fs";
33
import test from "ava";
44
import * as sinon from "sinon";
55

6-
import { getCodeQLForTesting } from "../codeql";
6+
import { getCodeQLForTesting, type CodeQL } from "../codeql";
77
import * as diagnostics from "../diagnostics";
8-
import { ActionsEnvVars } from "../environment";
8+
import { ActionsEnvVars, type Env } from "../environment";
99
import { Feature } from "../feature-flags";
10+
import type { Logger } from "../logging";
1011
import { XCODE_SELECT_LINK_PATH } from "../platform";
1112
import {
1213
checkExpectedLogMessages,
@@ -19,14 +20,34 @@ import {
1920
RecordingLogger,
2021
setupTests,
2122
} from "../testing-utils";
22-
import { withTmpDir } from "../util";
23+
import { BuildMode, withTmpDir } from "../util";
2324

2425
import { checkRunnerSupportsTracedAnalysis } from "./traced";
2526

2627
import { BuiltInLanguage } from ".";
2728

2829
setupTests(test);
2930

31+
const TEST_DEFAULT_TRACED_LANGUAGES = {
32+
[BuiltInLanguage.swift]: true,
33+
[BuiltInLanguage.go]: true,
34+
};
35+
36+
async function getCodeQLWithTracedStub(
37+
cmd: string,
38+
logger: Logger,
39+
env: Env,
40+
tracedLanguages: Partial<
41+
Record<BuiltInLanguage, boolean>
42+
> = TEST_DEFAULT_TRACED_LANGUAGES,
43+
): Promise<CodeQL> {
44+
const codeql = await getCodeQLForTesting(cmd, logger, env);
45+
sinon.stub(codeql, "isTracedLanguage").callsFake(async (language) => {
46+
return tracedLanguages[language] === true;
47+
});
48+
return codeql;
49+
}
50+
3051
const nonDarwinPlatforms: NodeJS.Platform[] = ["linux", "win32"];
3152
for (const nonDarwinPlatform of nonDarwinPlatforms) {
3253
test(`checkRunnerSupportsTracedAnalysis throws for Swift on ${nonDarwinPlatform}`, async (t) =>
@@ -35,7 +56,7 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
3556
const env = getTestEnv();
3657
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
3758

38-
const codeql = await getCodeQLForTesting(
59+
const codeql = await getCodeQLWithTracedStub(
3960
"codeql-for-testing",
4061
logger,
4162
env,
@@ -52,13 +73,78 @@ for (const nonDarwinPlatform of nonDarwinPlatforms) {
5273
}));
5374
}
5475

76+
test(`checkRunnerSupportsTracedAnalysis doesn't throw for BMN`, async (t) =>
77+
withTmpDir(async (tmpDir) => {
78+
const logger = new RecordingLogger();
79+
const env = getTestEnv();
80+
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
81+
82+
const codeql = await getCodeQLWithTracedStub(
83+
"codeql-for-testing",
84+
logger,
85+
env,
86+
);
87+
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
88+
89+
await t.notThrowsAsync(
90+
checkRunnerSupportsTracedAnalysis(
91+
initAllState({
92+
platform: "darwin",
93+
osRelease: "27.0.0",
94+
env,
95+
logger,
96+
}),
97+
createTestConfig({ buildMode: BuildMode.None }),
98+
codeql,
99+
),
100+
);
101+
}));
102+
103+
// Some languages not in `TEST_DEFAULT_TRACED_LANGUAGES`.
104+
const nonTracedLanguages: BuiltInLanguage[] = [
105+
BuiltInLanguage.javascript,
106+
BuiltInLanguage.actions,
107+
];
108+
for (const nonTracedLanguage of nonTracedLanguages) {
109+
test(`checkRunnerSupportsTracedAnalysis doesn't throw for ${nonTracedLanguage} on unsupported macOS`, async (t) =>
110+
withTmpDir(async (tmpDir) => {
111+
const logger = new RecordingLogger();
112+
const env = getTestEnv();
113+
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
114+
115+
const codeql = await getCodeQLWithTracedStub(
116+
"codeql-for-testing",
117+
logger,
118+
env,
119+
);
120+
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
121+
122+
await t.notThrowsAsync(
123+
checkRunnerSupportsTracedAnalysis(
124+
initAllState({
125+
platform: "darwin",
126+
osRelease: "27.0.0",
127+
env,
128+
logger,
129+
}),
130+
createTestConfig({ languages: [nonTracedLanguage] }),
131+
codeql,
132+
),
133+
);
134+
}));
135+
}
136+
55137
test("checkRunnerSupportsTracedAnalysis warns if version string is not a semver", async (t) =>
56138
withTmpDir(async (tmpDir) => {
57139
const logger = new RecordingLogger();
58140
const env = getTestEnv();
59141
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
60142

61-
const codeql = await getCodeQLForTesting("codeql-for-testing", logger, env);
143+
const codeql = await getCodeQLWithTracedStub(
144+
"codeql-for-testing",
145+
logger,
146+
env,
147+
);
62148
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
63149

64150
await checkRunnerSupportsTracedAnalysis(
@@ -86,7 +172,7 @@ test.serial(
86172
const env = getTestEnv();
87173
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
88174

89-
const codeql = await getCodeQLForTesting(
175+
const codeql = await getCodeQLWithTracedStub(
90176
"codeql-for-testing",
91177
logger,
92178
env,
@@ -146,7 +232,7 @@ test.serial(
146232

147233
const features = createFeatures([Feature.SkipUnsupportedTracedAnalysis]);
148234

149-
const codeql = await getCodeQLForTesting(
235+
const codeql = await getCodeQLWithTracedStub(
150236
"codeql-for-testing",
151237
logger,
152238
env,
@@ -210,7 +296,7 @@ test.serial(
210296
.stub(fs, "readlinkSync")
211297
.returns("/Applications/Xcode_26.0.app/Contents/Developer");
212298

213-
const codeql = await getCodeQLForTesting(
299+
const codeql = await getCodeQLWithTracedStub(
214300
"codeql-for-testing",
215301
logger,
216302
env,
@@ -260,7 +346,7 @@ test.serial(
260346
.stub(fs, "readlinkSync")
261347
.returns("/Applications/Xcode_27.0.app/Contents/Developer");
262348

263-
const codeql = await getCodeQLForTesting(
349+
const codeql = await getCodeQLWithTracedStub(
264350
"codeql-for-testing",
265351
logger,
266352
env,
@@ -332,7 +418,7 @@ test.serial(
332418

333419
const features = createFeatures([Feature.SkipUnsupportedTracedAnalysis]);
334420

335-
const codeql = await getCodeQLForTesting(
421+
const codeql = await getCodeQLWithTracedStub(
336422
"codeql-for-testing",
337423
logger,
338424
env,

‎src/languages/traced.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ function handleUnsupportedVersion(
7878
}
7979
}
8080

81+
/**
82+
* Decides whether {@link config} has any traced languages by looking for tracer
83+
* configurations in the {@link codeql} CLI installation.
84+
*/
85+
export async function hasTracedLanguages(
86+
config: ActionConfig<"languages">,
87+
codeql: CodeQL,
88+
): Promise<boolean> {
89+
for (const language of config.languages) {
90+
if (await codeql.isTracedLanguage(language)) {
91+
return true;
92+
}
93+
}
94+
95+
return false;
96+
}
97+
8198
/**
8299
* Determines whether we can run a traced analysis on the current runner.
83100
*
@@ -94,6 +111,16 @@ export async function checkRunnerSupportsTracedAnalysis(
94111
// Perform some initial, Swift-specific checks.
95112
await isSwiftCompatible(config, codeql, version);
96113

114+
// `build-mode: none` doesn't use the tracer, so it is always supported.
115+
if (config.buildMode !== undefined && config.buildMode === "none") {
116+
return;
117+
}
118+
119+
// If none of the languages are traced, then we can skip the compatibility checks below as well.
120+
if (!(await hasTracedLanguages(config, codeql))) {
121+
return;
122+
}
123+
97124
const skipUnsupportedTracedAnalysis = await action.features.getValue(
98125
Feature.SkipUnsupportedTracedAnalysis,
99126
);

0 commit comments

Comments
 (0)