Skip to content

Commit 8a884bd

Browse files
committed
Extend setupActionsVars
1 parent 129d771 commit 8a884bd

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/testing-utils.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,40 @@ export function setupTests(test: TestFn<any>) {
139139
});
140140
}
141141

142+
/**
143+
* Default values for environment variables typically set in an Actions
144+
* environment. Tests can override individual variables by passing them in the
145+
* `overrides` parameter.
146+
*/
147+
const DEFAULT_ACTIONS_VARS: Record<string, string> = {
148+
GITHUB_ACTION_REPOSITORY: "github/codeql-action",
149+
GITHUB_API_URL: "https://api.github.com",
150+
GITHUB_EVENT_NAME: "push",
151+
GITHUB_JOB: "test-job",
152+
GITHUB_REF: "refs/heads/main",
153+
GITHUB_REPOSITORY: "github/codeql-action-testing",
154+
GITHUB_RUN_ATTEMPT: "1",
155+
GITHUB_RUN_ID: "1",
156+
GITHUB_SERVER_URL: "https://github.com",
157+
GITHUB_SHA: "0".repeat(40),
158+
GITHUB_WORKFLOW: "test-workflow",
159+
RUNNER_OS: "Linux",
160+
};
161+
142162
// Sets environment variables that make using some libraries designed for
143163
// use only on actions safe to use outside of actions.
144-
export function setupActionsVars(tempDir: string, toolsDir: string) {
164+
export function setupActionsVars(
165+
tempDir: string,
166+
toolsDir: string,
167+
overrides?: Partial<Record<string, string>>,
168+
) {
169+
const vars = { ...DEFAULT_ACTIONS_VARS, ...overrides };
170+
for (const [key, value] of Object.entries(vars)) {
171+
process.env[key] = value;
172+
}
145173
process.env["RUNNER_TEMP"] = tempDir;
146174
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
147175
process.env["GITHUB_WORKSPACE"] = tempDir;
148-
process.env["GITHUB_EVENT_NAME"] = "push";
149176
}
150177

151178
type LogLevel = "debug" | "info" | "warning" | "error";

0 commit comments

Comments
 (0)