Skip to content

Commit 0a3ea86

Browse files
authored
Make getCodeQLForCmd use Env
1 parent 38b1131 commit 0a3ea86

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
@@ -18,7 +18,7 @@ import { CliError, wrapCliConfigurationError } from "./cli-errors";
1818
import type { ActionConfig } from "./config/action-config";
1919
import { appendExtraQueryExclusions, type Config } from "./config-utils";
2020
import { DocUrl } from "./doc-url";
21-
import { EnvVar, getEnv, exportEnvVar } from "./environment";
21+
import { EnvVar, getEnv, exportEnvVar, Env, ReadOnlyEnv } from "./environment";
2222
import {
2323
CodeQLDefaultVersionInfo,
2424
Feature,
@@ -495,8 +495,9 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
495495
export async function getCodeQLForTesting(
496496
cmd = "codeql-for-testing",
497497
logger: Logger = getRunnerLogger(true),
498+
env: Env = getEnv(),
498499
): Promise<CodeQL> {
499-
return getCodeQLForCmd(logger, cmd, false);
500+
return getCodeQLForCmd(logger, cmd, false, env);
500501
}
501502

502503
/**
@@ -511,13 +512,14 @@ async function getCodeQLForCmd(
511512
logger: Logger,
512513
cmd: string,
513514
checkVersion: boolean,
515+
env: Env = getEnv(),
514516
): Promise<CodeQL> {
515517
const codeql: CodeQL = {
516518
getPath() {
517519
return cmd;
518520
},
519521
async getVersion() {
520-
const cacheFilePath = outputCache.getCommandCacheFilePath(getEnv());
522+
const cacheFilePath = outputCache.getCommandCacheFilePath(env);
521523
let result = outputCache.getCachedCodeQlVersion(
522524
logger,
523525
cacheFilePath,
@@ -643,7 +645,7 @@ async function getCodeQLForCmd(
643645
}
644646
},
645647
async runAutobuild(config: Config, language: Language) {
646-
applyAutobuildAzurePipelinesTimeoutFix();
648+
applyAutobuildAzurePipelinesTimeoutFix(env);
647649

648650
const autobuildCmd = path.join(
649651
await this.resolveExtractor(language),
@@ -653,8 +655,11 @@ async function getCodeQLForCmd(
653655

654656
// Bump the verbosity of the autobuild command if we're in debug mode
655657
if (config.debugMode) {
656-
process.env[EnvVar.CLI_VERBOSITY] =
657-
process.env[EnvVar.CLI_VERBOSITY] || EXTRACTION_DEBUG_MODE_VERBOSITY;
658+
env.set(
659+
EnvVar.CLI_VERBOSITY,
660+
env.getOptional(EnvVar.CLI_VERBOSITY) ??
661+
EXTRACTION_DEBUG_MODE_VERBOSITY,
662+
);
658663
}
659664

660665
// On macOS, System Integrity Protection (SIP) typically interferes with
@@ -686,7 +691,7 @@ async function getCodeQLForCmd(
686691
},
687692
async extractUsingBuildMode(config: Config, language: Language) {
688693
if (config.buildMode === BuildMode.Autobuild) {
689-
applyAutobuildAzurePipelinesTimeoutFix();
694+
applyAutobuildAzurePipelinesTimeoutFix(env);
690695
}
691696
try {
692697
await runCli(cmd, [
@@ -818,7 +823,7 @@ async function getCodeQLForCmd(
818823
"--sarif-group-rules-by-pack",
819824
"--sarif-include-query-help=always",
820825
"--sublanguage-file-coverage",
821-
...(await getJobRunUuidSarifOptions()),
826+
...(await getJobRunUuidSarifOptions(env)),
822827
...getExtraOptionsFromEnv(["database", "interpret-results"]),
823828
];
824829
if (sarifRunPropertyFlag !== undefined) {
@@ -1042,7 +1047,7 @@ async function getCodeQLForCmd(
10421047
);
10431048
} else if (
10441049
checkVersion &&
1045-
process.env[EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING] !== "true" &&
1050+
env.getOptional(EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING) !== "true" &&
10461051
!(await util.codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION))
10471052
) {
10481053
const result = await codeql.getVersion();
@@ -1264,17 +1269,20 @@ function getExtractionVerbosityArguments(
12641269
* Without the fix, long build processes will timeout when pulling down Java packages
12651270
* https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
12661271
*/
1267-
function applyAutobuildAzurePipelinesTimeoutFix() {
1268-
const javaToolOptions = process.env["JAVA_TOOL_OPTIONS"] || "";
1269-
process.env["JAVA_TOOL_OPTIONS"] = [
1270-
...javaToolOptions.split(/\s+/),
1271-
"-Dhttp.keepAlive=false",
1272-
"-Dmaven.wagon.http.pool=false",
1273-
].join(" ");
1272+
function applyAutobuildAzurePipelinesTimeoutFix(env: Env) {
1273+
const javaToolOptions = env.getOptional("JAVA_TOOL_OPTIONS") ?? "";
1274+
env.set(
1275+
"JAVA_TOOL_OPTIONS",
1276+
[
1277+
...javaToolOptions.split(/\s+/),
1278+
"-Dhttp.keepAlive=false",
1279+
"-Dmaven.wagon.http.pool=false",
1280+
].join(" "),
1281+
);
12741282
}
12751283

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

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

0 commit comments

Comments
 (0)