Skip to content

Commit 378f30f

Browse files
call setupActionsVars in the tests too
1 parent d698cb3 commit 378f30f

10 files changed

Lines changed: 58 additions & 38 deletions

File tree

lib/codeql.test.js

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

lib/codeql.test.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/runner.js

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

lib/runner.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/util.js

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

lib/util.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.

queries/unguarded-action-lib.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class RunnerEntrypoint extends Function {
6565
* Does this runner entry point set the RUNNER_TEMP and
6666
* RUNNER_TOOL_CACHE env vars which make some actions libraries
6767
* safe to use outside of actions.
68-
* See "setupActionsVars" in "runner.ts".
68+
* See "setupActionsVars" in "util.ts".
6969
*/
7070
predicate setsActionsEnvVars() {
7171
// This is matching code of the following format, where "this"

src/codeql.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const sampleGHAEApiDetails = {
2424

2525
test("download codeql bundle cache", async (t) => {
2626
await util.withTmpDir(async (tmpDir) => {
27+
util.setupActionsVars(tmpDir, tmpDir);
28+
2729
const versions = ["20200601", "20200610"];
2830

2931
for (let i = 0; i < versions.length; i++) {
@@ -56,6 +58,8 @@ test("download codeql bundle cache", async (t) => {
5658

5759
test("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => {
5860
await util.withTmpDir(async (tmpDir) => {
61+
util.setupActionsVars(tmpDir, tmpDir);
62+
5963
nock("https://example.com")
6064
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
6165
.replyWithFile(
@@ -96,6 +100,8 @@ test("download codeql bundle cache explicitly requested with pinned different ve
96100

97101
test("don't download codeql bundle cache with pinned different version cached", async (t) => {
98102
await util.withTmpDir(async (tmpDir) => {
103+
util.setupActionsVars(tmpDir, tmpDir);
104+
99105
nock("https://example.com")
100106
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
101107
.replyWithFile(
@@ -131,6 +137,8 @@ test("don't download codeql bundle cache with pinned different version cached",
131137

132138
test("download codeql bundle cache with different version cached (not pinned)", async (t) => {
133139
await util.withTmpDir(async (tmpDir) => {
140+
util.setupActionsVars(tmpDir, tmpDir);
141+
134142
nock("https://example.com")
135143
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
136144
.replyWithFile(
@@ -181,6 +189,8 @@ test("download codeql bundle cache with different version cached (not pinned)",
181189

182190
test('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => {
183191
await util.withTmpDir(async (tmpDir) => {
192+
util.setupActionsVars(tmpDir, tmpDir);
193+
184194
nock("https://example.com")
185195
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
186196
.replyWithFile(
@@ -232,6 +242,8 @@ test('download codeql bundle cache with pinned different version cached if "late
232242

233243
test("download codeql bundle from github ae endpoint", async (t) => {
234244
await util.withTmpDir(async (tmpDir) => {
245+
util.setupActionsVars(tmpDir, tmpDir);
246+
235247
const bundleAssetID = 10;
236248

237249
const platform =

src/runner.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getThreadsFlag,
2222
parseGithubUrl,
2323
getGitHubAuth,
24+
setupActionsVars,
2425
} from "./util";
2526

2627
const program = new Command();
@@ -86,22 +87,6 @@ function parseTraceProcessLevel(): number | undefined {
8687
return undefined;
8788
}
8889

89-
// Sets environment variables that make using some libraries designed for
90-
// use only on actions safe to use outside of actions.
91-
//
92-
// Obviously this is not a tremendously great thing we're doing and it
93-
// would be better to write our own implementation of libraries to use
94-
// outside of actions. For now this works well enough.
95-
//
96-
// Currently this list of libraries that is deemed to now be safe includes:
97-
// - @actions/tool-cache
98-
//
99-
// Also see "queries/unguarded-action-lib.ql".
100-
function setupActionsVars(tempDir: string, toolsDir: string) {
101-
process.env["RUNNER_TEMP"] = tempDir;
102-
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
103-
}
104-
10590
interface InitArgs {
10691
languages: string | undefined;
10792
queries: string | undefined;

src/util.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,19 @@ export async function getGitHubAuth(
390390
"No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input."
391391
);
392392
}
393+
394+
// Sets environment variables that make using some libraries designed for
395+
// use only on actions safe to use outside of actions.
396+
//
397+
// Obviously this is not a tremendously great thing we're doing and it
398+
// would be better to write our own implementation of libraries to use
399+
// outside of actions. For now this works well enough.
400+
//
401+
// Currently this list of libraries that is deemed to now be safe includes:
402+
// - @actions/tool-cache
403+
//
404+
// Also see "queries/unguarded-action-lib.ql".
405+
export function setupActionsVars(tempDir: string, toolsDir: string) {
406+
process.env["RUNNER_TEMP"] = tempDir;
407+
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
408+
}

0 commit comments

Comments
 (0)