Skip to content

Commit a440e35

Browse files
committed
Move ActionsEnvVars to environment.ts
1 parent be67a7b commit a440e35

7 files changed

Lines changed: 35 additions & 42 deletions

File tree

src/actions-util.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as github from "@actions/github";
77
import * as io from "@actions/io";
88

99
import type { Config } from "./config-utils";
10-
import { Env, EnvVar } from "./environment";
10+
import { Env, EnvVar, ActionsEnvVars } from "./environment";
1111
import { Logger } from "./logging";
1212
import {
1313
doesDirectoryExist,
@@ -22,28 +22,6 @@ import {
2222
*/
2323
declare const __CODEQL_ACTION_VERSION__: string;
2424

25-
/**
26-
* Enumerates known GitHub Actions environment variables that we expect
27-
* to be set in a GitHub Actions environment.
28-
*/
29-
export enum ActionsEnvVars {
30-
GITHUB_ACTION_REPOSITORY = "GITHUB_ACTION_REPOSITORY",
31-
GITHUB_API_URL = "GITHUB_API_URL",
32-
GITHUB_EVENT_NAME = "GITHUB_EVENT_NAME",
33-
GITHUB_EVENT_PATH = "GITHUB_EVENT_PATH",
34-
GITHUB_JOB = "GITHUB_JOB",
35-
GITHUB_REF = "GITHUB_REF",
36-
GITHUB_REPOSITORY = "GITHUB_REPOSITORY",
37-
GITHUB_RUN_ATTEMPT = "GITHUB_RUN_ATTEMPT",
38-
GITHUB_RUN_ID = "GITHUB_RUN_ID",
39-
GITHUB_SERVER_URL = "GITHUB_SERVER_URL",
40-
GITHUB_SHA = "GITHUB_SHA",
41-
GITHUB_WORKFLOW = "GITHUB_WORKFLOW",
42-
RUNNER_NAME = "RUNNER_NAME",
43-
RUNNER_OS = "RUNNER_OS",
44-
RUNNER_TEMP = "RUNNER_TEMP",
45-
}
46-
4725
/**
4826
* Abstracts over GitHub Actions functions so that we do not have to stub
4927
* global functions in tests.

src/api-client.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as sinon from "sinon";
66
import * as actionsUtil from "./actions-util";
77
import * as api from "./api-client";
88
import { DO_NOT_RETRY_STATUSES } from "./api-client";
9+
import { ActionsEnvVars } from "./environment";
910
import { getTestEnv, setupTests } from "./testing-utils";
1011
import * as util from "./util";
1112

@@ -21,14 +22,8 @@ test.serial("getApiClient", async (t) => {
2122
pluginStub.returns(githubStub);
2223

2324
const env = getTestEnv();
24-
env.set(
25-
actionsUtil.ActionsEnvVars.GITHUB_SERVER_URL,
26-
"http://github.localhost",
27-
);
28-
env.set(
29-
actionsUtil.ActionsEnvVars.GITHUB_API_URL,
30-
"http://api.github.localhost",
31-
);
25+
env.set(ActionsEnvVars.GITHUB_SERVER_URL, "http://github.localhost");
26+
env.set(ActionsEnvVars.GITHUB_API_URL, "http://api.github.localhost");
3227

3328
sinon.stub(actionsUtil, "getRequiredInput").withArgs("token").returns("xyz");
3429

src/api-client.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import * as core from "@actions/core";
22
import * as githubUtils from "@actions/github/lib/utils";
33
import * as retry from "@octokit/plugin-retry";
44

5-
import {
6-
ActionsEnvVars,
7-
getActionVersion,
8-
getRequiredInput,
9-
} from "./actions-util";
10-
import { EnvVar, ReadOnlyEnv, getEnv } from "./environment";
5+
import { getActionVersion, getRequiredInput } from "./actions-util";
6+
import { EnvVar, ReadOnlyEnv, ActionsEnvVars, getEnv } from "./environment";
117
import { Logger } from "./logging";
128
import { getRepositoryNwo, RepositoryNwo } from "./repository";
139
import {

src/config/remote-file.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from "ava";
22
import sinon from "sinon";
33

4-
import { ActionsEnvVars } from "../actions-util";
4+
import { ActionsEnvVars } from "../environment";
55
import * as errors from "../error-messages";
66
import { Feature } from "../feature-flags";
77
import { callee, getTestEnv } from "../testing-utils";

src/config/remote-file.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ActionState } from "../action-common";
2-
import { ActionsEnvVars } from "../actions-util";
3-
import { Env } from "../environment";
2+
import { Env, ActionsEnvVars } from "../environment";
43
import * as errorMessages from "../error-messages";
54
import { Feature } from "../feature-flags";
65
import { ConfigurationError, Failure, Result, Success } from "../util";

src/environment.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,31 @@ export enum EnvVar {
164164
RISK_ASSESSMENT_ID = "CODEQL_ACTION_RISK_ASSESSMENT_ID",
165165
}
166166

167+
/**
168+
* Enumerates known GitHub Actions environment variables that we expect
169+
* to be set in a GitHub Actions environment.
170+
*/
171+
export enum ActionsEnvVars {
172+
GITHUB_ACTION_REPOSITORY = "GITHUB_ACTION_REPOSITORY",
173+
GITHUB_API_URL = "GITHUB_API_URL",
174+
GITHUB_EVENT_NAME = "GITHUB_EVENT_NAME",
175+
GITHUB_EVENT_PATH = "GITHUB_EVENT_PATH",
176+
GITHUB_JOB = "GITHUB_JOB",
177+
GITHUB_REF = "GITHUB_REF",
178+
GITHUB_REPOSITORY = "GITHUB_REPOSITORY",
179+
GITHUB_RUN_ATTEMPT = "GITHUB_RUN_ATTEMPT",
180+
GITHUB_RUN_ID = "GITHUB_RUN_ID",
181+
GITHUB_SERVER_URL = "GITHUB_SERVER_URL",
182+
GITHUB_SHA = "GITHUB_SHA",
183+
GITHUB_WORKFLOW = "GITHUB_WORKFLOW",
184+
RUNNER_NAME = "RUNNER_NAME",
185+
RUNNER_OS = "RUNNER_OS",
186+
RUNNER_TEMP = "RUNNER_TEMP",
187+
}
188+
189+
/** A type representing all known environment variables. */
190+
export type KnownEnvVar = EnvVar | ActionsEnvVars;
191+
167192
/**
168193
* Gets an environment variable, but throws an error if it is not set.
169194
*/

src/testing-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import nock from "nock";
1111
import * as sinon from "sinon";
1212

1313
import { ActionState, StateFeature } from "./action-common";
14-
import { ActionsEnv, ActionsEnvVars, getActionVersion } from "./actions-util";
14+
import { ActionsEnv, getActionVersion } from "./actions-util";
1515
import { AnalysisKind } from "./analyses";
1616
import * as apiClient from "./api-client";
1717
import { GitHubApiDetails } from "./api-client";
1818
import { CachingKind } from "./caching-utils";
1919
import * as codeql from "./codeql";
2020
import { Config } from "./config-utils";
2121
import * as defaults from "./defaults.json";
22-
import { Env } from "./environment";
22+
import { Env, ActionsEnvVars } from "./environment";
2323
import {
2424
CodeQLDefaultVersionInfo,
2525
Feature,

0 commit comments

Comments
 (0)