Skip to content

Commit d7ad71d

Browse files
Merge pull request #938 from github/respect-end-tracing
Respect `end-tracing` script instead of deleting one variable
2 parents f14beeb + afbddca commit d7ad71d

File tree

6 files changed

+84
-8
lines changed

6 files changed

+84
-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: 25 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ 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 envVariablesFile = path.resolve(
30+
config.dbLocation,
31+
"temp/tracingEnvironment/end-tracing.json"
32+
);
33+
if (!fs.existsSync(envVariablesFile)) {
34+
throw new Error(
35+
`Environment file for ending tracing not found: ${envVariablesFile}`
36+
);
37+
}
38+
try {
39+
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
40+
fs.readFileSync(envVariablesFile, "utf8")
41+
);
42+
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
43+
if (value !== null) {
44+
process.env[key] = value;
45+
} else {
46+
delete process.env[key];
47+
}
48+
}
49+
} catch (e) {
50+
throw new Error(
51+
`Failed to parse file containing end tracing environment variables: ${e}`
52+
);
53+
}
54+
}
55+
2356
export async function getTracerConfigForCluster(
2457
config: configUtils.Config
2558
): Promise<TracerConfig> {

0 commit comments

Comments
 (0)