Skip to content

Commit

Permalink
Respect end-tracing script instead of deleting one variable
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardopirovano committed Feb 17, 2022
1 parent cefec5b commit 3f68d85
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
12 changes: 10 additions & 2 deletions lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion lib/tracer-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tracer-config.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions src/analyze.ts
Expand Up @@ -5,12 +5,17 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
import * as yaml from "js-yaml";

import * as analysisPaths from "./analysis-paths";
import { CODEQL_VERSION_COUNTS_LINES, getCodeQL } from "./codeql";
import {
CODEQL_VERSION_COUNTS_LINES,
CODEQL_VERSION_NEW_TRACING,
getCodeQL,
} from "./codeql";
import * as configUtils from "./config-utils";
import { countLoc } from "./count-loc";
import { isScannedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import * as sharedEnv from "./shared-environment";
import { endTracingForCluster } from "./tracer-config";
import * as util from "./util";

export class CodeQLAnalysisError extends Error {
Expand Down Expand Up @@ -409,8 +414,14 @@ export async function runFinalize(
config: configUtils.Config,
logger: Logger
) {
// Delete the tracer config env var to avoid tracing ourselves
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
const codeql = await getCodeQL(config.codeQLCmd);
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
// Delete variables as specified by the end-tracing script
await endTracingForCluster(config);
} else {
// Delete the tracer config env var to avoid tracing ourselves
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
}

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

Expand Down
21 changes: 21 additions & 0 deletions src/tracer-config.ts
Expand Up @@ -20,6 +20,27 @@ const CRITICAL_TRACER_VARS = new Set([
"SEMMLE_JAVA_TOOL_OPTIONS",
]);

export async function endTracingForCluster(
config: configUtils.Config
): Promise<void> {
const endTracingEnvVariables: Map<string, string | undefined> = JSON.parse(
fs.readFileSync(
path.resolve(
config.dbLocation,
"temp/tracingEnvironment/end-tracing.json"
),
"utf8"
)
);
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
if (value !== undefined) {
process.env[key] = value;
} else {
delete process.env[key];
}
}
}

export async function getTracerConfigForCluster(
config: configUtils.Config
): Promise<TracerConfig> {
Expand Down

0 comments on commit 3f68d85

Please sign in to comment.