Skip to content

Commit 84ab7c2

Browse files
Respect end-tracing script instead of deleting one variable
1 parent cefec5b commit 84ab7c2

File tree

6 files changed

+66
-8
lines changed

6 files changed

+66
-8
lines changed

lib/analyze.js

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

lib/analyze.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tracer-config.js

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tracer-config.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
55
import * as yaml from "js-yaml";
66

77
import * as analysisPaths from "./analysis-paths";
8-
import { CODEQL_VERSION_COUNTS_LINES, getCodeQL } from "./codeql";
8+
import {
9+
CODEQL_VERSION_COUNTS_LINES,
10+
CODEQL_VERSION_NEW_TRACING,
11+
getCodeQL,
12+
} from "./codeql";
913
import * as configUtils from "./config-utils";
1014
import { countLoc } from "./count-loc";
1115
import { isScannedLanguage, Language } from "./languages";
1216
import { Logger } from "./logging";
1317
import * as sharedEnv from "./shared-environment";
18+
import { endTracingForCluster } from "./tracer-config";
1419
import * as util from "./util";
1520

1621
export class CodeQLAnalysisError extends Error {
@@ -409,8 +414,14 @@ export async function runFinalize(
409414
config: configUtils.Config,
410415
logger: Logger
411416
) {
412-
// Delete the tracer config env var to avoid tracing ourselves
413-
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
417+
const codeql = await getCodeQL(config.codeQLCmd);
418+
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
419+
// Delete variables as specified by the end-tracing script
420+
await endTracingForCluster(config);
421+
} else {
422+
// Delete the tracer config env var to avoid tracing ourselves
423+
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
424+
}
414425

415426
fs.mkdirSync(outputDir, { recursive: true });
416427

src/tracer-config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ const CRITICAL_TRACER_VARS = new Set([
2020
"SEMMLE_JAVA_TOOL_OPTIONS",
2121
]);
2222

23+
export async function endTracingForCluster(
24+
config: configUtils.Config
25+
): Promise<void> {
26+
// If there are no traced languages, we don't need to do anything.
27+
if (!config.languages.some(isTracedLanguage)) return;
28+
29+
const endTracingEnvVariables: Map<string, string | undefined> = JSON.parse(
30+
fs.readFileSync(
31+
path.resolve(
32+
config.dbLocation,
33+
"temp/tracingEnvironment/end-tracing.json"
34+
),
35+
"utf8"
36+
)
37+
);
38+
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
39+
if (value !== undefined) {
40+
process.env[key] = value;
41+
} else {
42+
delete process.env[key];
43+
}
44+
}
45+
}
46+
2347
export async function getTracerConfigForCluster(
2448
config: configUtils.Config
2549
): Promise<TracerConfig> {

0 commit comments

Comments
 (0)