Skip to content

Commit 0bd54b0

Browse files
committed
Make getCodeQLForCmd use Env
1 parent 859c056 commit 0bd54b0

4 files changed

Lines changed: 51 additions & 37 deletions

File tree

‎lib/entry-points.js‎

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

‎src/actions-util.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const getOptionalInput = function (name: string): string | undefined {
7272
* directory that has been set in `CODEQL_ACTION_TEMP` by e.g. a previous step, or the
7373
* value of `RUNNER_TEMP` otherwise.
7474
*/
75-
export function getTemporaryDirectory(env: Env = getEnv()): string {
75+
export function getTemporaryDirectory(env: ReadOnlyEnv = getEnv()): string {
7676
return (
7777
env.getOptional(EnvVar.TEMP) ?? env.getRequired(ActionsEnvVars.RUNNER_TEMP)
7878
);

‎src/cli/output-cache.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
import path from "path";
33

44
import { getTemporaryDirectory } from "../actions-util";
5-
import { Env } from "../environment";
5+
import { ReadOnlyEnv } from "../environment";
66
import * as json from "../json";
77
import { Logger } from "../logging";
88

@@ -51,7 +51,7 @@ export function resetCachedCodeQlVersion(): void {
5151
* Returns the path to the temporary file that backs the
5252
* on-disk cache of CLI responses between workflow steps.
5353
*/
54-
export function getCommandCacheFilePath(env: Env): string {
54+
export function getCommandCacheFilePath(env: ReadOnlyEnv): string {
5555
return path.join(getTemporaryDirectory(env), COMMAND_CACHE_FILENAME);
5656
}
5757

‎src/codeql.ts‎

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { VersionInfo } from "./cli/types";
1717
import { CliError, wrapCliConfigurationError } from "./cli-errors";
1818
import { appendExtraQueryExclusions, type Config } from "./config-utils";
1919
import { DocUrl } from "./doc-url";
20-
import { EnvVar, getEnv, exportEnvVar } from "./environment";
20+
import { EnvVar, getEnv, exportEnvVar, Env, ReadOnlyEnv } from "./environment";
2121
import {
2222
CodeQLDefaultVersionInfo,
2323
Feature,
@@ -493,8 +493,9 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
493493
export async function getCodeQLForTesting(
494494
cmd = "codeql-for-testing",
495495
logger: Logger = getRunnerLogger(true),
496+
env: Env = getEnv(),
496497
): Promise<CodeQL> {
497-
return getCodeQLForCmd(logger, cmd, false);
498+
return getCodeQLForCmd(logger, cmd, false, env);
498499
}
499500

500501
/**
@@ -509,13 +510,14 @@ async function getCodeQLForCmd(
509510
logger: Logger,
510511
cmd: string,
511512
checkVersion: boolean,
513+
env: Env = getEnv(),
512514
): Promise<CodeQL> {
513515
const codeql: CodeQL = {
514516
getPath() {
515517
return cmd;
516518
},
517519
async getVersion() {
518-
const cacheFilePath = outputCache.getCommandCacheFilePath(getEnv());
520+
const cacheFilePath = outputCache.getCommandCacheFilePath(env);
519521
let result = outputCache.getCachedCodeQlVersion(
520522
logger,
521523
cacheFilePath,
@@ -641,7 +643,7 @@ async function getCodeQLForCmd(
641643
}
642644
},
643645
async runAutobuild(config: Config, language: Language) {
644-
applyAutobuildAzurePipelinesTimeoutFix();
646+
applyAutobuildAzurePipelinesTimeoutFix(env);
645647

646648
const autobuildCmd = path.join(
647649
await this.resolveExtractor(language),
@@ -651,8 +653,11 @@ async function getCodeQLForCmd(
651653

652654
// Bump the verbosity of the autobuild command if we're in debug mode
653655
if (config.debugMode) {
654-
process.env[EnvVar.CLI_VERBOSITY] =
655-
process.env[EnvVar.CLI_VERBOSITY] || EXTRACTION_DEBUG_MODE_VERBOSITY;
656+
env.set(
657+
EnvVar.CLI_VERBOSITY,
658+
env.getOptional(EnvVar.CLI_VERBOSITY) ??
659+
EXTRACTION_DEBUG_MODE_VERBOSITY,
660+
);
656661
}
657662

658663
// On macOS, System Integrity Protection (SIP) typically interferes with
@@ -684,7 +689,7 @@ async function getCodeQLForCmd(
684689
},
685690
async extractUsingBuildMode(config: Config, language: Language) {
686691
if (config.buildMode === BuildMode.Autobuild) {
687-
applyAutobuildAzurePipelinesTimeoutFix();
692+
applyAutobuildAzurePipelinesTimeoutFix(env);
688693
}
689694
try {
690695
await runCli(cmd, [
@@ -816,7 +821,7 @@ async function getCodeQLForCmd(
816821
"--sarif-group-rules-by-pack",
817822
"--sarif-include-query-help=always",
818823
"--sublanguage-file-coverage",
819-
...(await getJobRunUuidSarifOptions()),
824+
...(await getJobRunUuidSarifOptions(env)),
820825
...getExtraOptionsFromEnv(["database", "interpret-results"]),
821826
];
822827
if (sarifRunPropertyFlag !== undefined) {
@@ -1036,7 +1041,7 @@ async function getCodeQLForCmd(
10361041
);
10371042
} else if (
10381043
checkVersion &&
1039-
process.env[EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING] !== "true" &&
1044+
env.getOptional(EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING) !== "true" &&
10401045
!(await util.codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION))
10411046
) {
10421047
const result = await codeql.getVersion();
@@ -1256,17 +1261,20 @@ function getExtractionVerbosityArguments(
12561261
* Without the fix, long build processes will timeout when pulling down Java packages
12571262
* https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
12581263
*/
1259-
function applyAutobuildAzurePipelinesTimeoutFix() {
1260-
const javaToolOptions = process.env["JAVA_TOOL_OPTIONS"] || "";
1261-
process.env["JAVA_TOOL_OPTIONS"] = [
1262-
...javaToolOptions.split(/\s+/),
1263-
"-Dhttp.keepAlive=false",
1264-
"-Dmaven.wagon.http.pool=false",
1265-
].join(" ");
1264+
function applyAutobuildAzurePipelinesTimeoutFix(env: Env) {
1265+
const javaToolOptions = env.getOptional("JAVA_TOOL_OPTIONS") ?? "";
1266+
env.set(
1267+
"JAVA_TOOL_OPTIONS",
1268+
[
1269+
...javaToolOptions.split(/\s+/),
1270+
"-Dhttp.keepAlive=false",
1271+
"-Dmaven.wagon.http.pool=false",
1272+
].join(" "),
1273+
);
12661274
}
12671275

1268-
async function getJobRunUuidSarifOptions() {
1269-
const jobRunUuid = process.env[EnvVar.JOB_RUN_UUID];
1276+
async function getJobRunUuidSarifOptions(env: ReadOnlyEnv) {
1277+
const jobRunUuid = env.getOptional(EnvVar.JOB_RUN_UUID);
12701278

12711279
return jobRunUuid ? [`--sarif-run-property=jobRunUuid=${jobRunUuid}`] : [];
12721280
}

0 commit comments

Comments
 (0)