Skip to content

Commit 33d7086

Browse files
committed
Pass environment explicitly to CLI caching functions
1 parent 40f80a8 commit 33d7086

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎lib/entry-points.js‎

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

‎src/cli/output-cache.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test.serial(
2525
"utf8",
2626
);
2727
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
28-
t.deepEqual(outputCache.getCachedCodeQlVersion("/path/to/codeql", env), {
28+
t.deepEqual(outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"), {
2929
version: "2.20.0",
3030
});
3131
});
@@ -47,7 +47,7 @@ test.serial(
4747
);
4848
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
4949
t.is(
50-
outputCache.getCachedCodeQlVersion("/path/to/codeql", env),
50+
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
5151
undefined,
5252
);
5353
});
@@ -62,7 +62,7 @@ test.serial(
6262
fs.writeFileSync(cacheFile, "not valid json", "utf8");
6363
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
6464
t.is(
65-
outputCache.getCachedCodeQlVersion("/path/to/codeql", env),
65+
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
6666
undefined,
6767
);
6868
});
@@ -94,7 +94,7 @@ test.serial(
9494
for (const value of testValues) {
9595
fs.writeFileSync(cacheFile, value, "utf8");
9696
t.is(
97-
outputCache.getCachedCodeQlVersion("/path/to/codeql", env),
97+
outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"),
9898
undefined,
9999
value,
100100
);
@@ -106,6 +106,6 @@ test.serial(
106106
test.serial("getCachedCodeQlVersion ignores non-existent file", async (t) => {
107107
await util.withTmpDir(async (tmpDir: string) => {
108108
const env = getTestEnv({ [EnvVar.TEMP]: tmpDir });
109-
t.is(outputCache.getCachedCodeQlVersion("/path/to/codeql", env), undefined);
109+
t.is(outputCache.getCachedCodeQlVersion(env, "/path/to/codeql"), undefined);
110110
});
111111
});

‎src/cli/output-cache.ts‎

Lines changed: 4 additions & 4 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, getEnv } from "../environment";
5+
import { Env } from "../environment";
66

77
import type { VersionInfo } from "./types";
88

@@ -64,7 +64,7 @@ function getCommandCacheFilePath(env: Env): string {
6464
export function cacheCodeQlVersion(
6565
cmd: string,
6666
version: VersionInfo,
67-
env: Env = getEnv(),
67+
env: Env,
6868
): void {
6969
if (cachedCodeQlVersion !== undefined) {
7070
throw new Error("cacheCodeQlVersion() should be called only once");
@@ -83,12 +83,12 @@ export function cacheCodeQlVersion(
8383

8484
/**
8585
* Returns the cached CodeQL CLI version, if any.
86-
* @param cmd The path to the CodeQL CLI.
8786
* @param env The environment variables to use.
87+
* @param cmd The path to the CodeQL CLI.
8888
*/
8989
export function getCachedCodeQlVersion(
90+
env: Env,
9091
cmd?: string,
91-
env: Env = getEnv(),
9292
): undefined | VersionInfo {
9393
if (cachedCodeQlVersion !== undefined) {
9494
return cachedCodeQlVersion;

‎src/codeql.ts‎

Lines changed: 3 additions & 3 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 } from "./environment";
20+
import { EnvVar, getEnv } from "./environment";
2121
import {
2222
CodeQLDefaultVersionInfo,
2323
Feature,
@@ -490,7 +490,7 @@ async function getCodeQLForCmd(
490490
return cmd;
491491
},
492492
async getVersion() {
493-
let result = outputCache.getCachedCodeQlVersion(cmd);
493+
let result = outputCache.getCachedCodeQlVersion(getEnv(), cmd);
494494
if (result === undefined) {
495495
result = await runCliJson<VersionInfo>(
496496
cmd,
@@ -499,7 +499,7 @@ async function getCodeQLForCmd(
499499
noStreamStdout: true,
500500
},
501501
);
502-
outputCache.cacheCodeQlVersion(cmd, result);
502+
outputCache.cacheCodeQlVersion(cmd, result, getEnv());
503503
}
504504
return result;
505505
},

‎src/status-report.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export async function createStatusReportBase(
376376
core.exportVariable(EnvVar.WORKFLOW_STARTED_AT, workflowStartedAt);
377377
}
378378
const runnerOs = getRequiredEnvParam("RUNNER_OS");
379-
const codeQlCliVersion = getCachedCodeQlVersion();
379+
const codeQlCliVersion = getCachedCodeQlVersion(getEnv());
380380
const actionRef = process.env["GITHUB_ACTION_REF"] || "";
381381
const testingEnvironment = getTestingEnvironment();
382382
// re-export the testing environment variable so that it is available to subsequent steps,

0 commit comments

Comments
 (0)