Add initial ActionsEnv abstraction

This commit is contained in:
Michael B. Gale
2026-06-16 12:19:30 +02:00
parent f57d3726c3
commit a0276b7dc4
2 changed files with 25 additions and 1 deletions

View File

@@ -21,6 +21,21 @@ import {
*/
declare const __CODEQL_ACTION_VERSION__: string;
/**
* Abstracts over GitHub Actions functions so that we do not have to stub
* global functions in tests.
*/
export interface ActionsEnv {
getOptionalInput: (name: string) => string | undefined;
}
/**
* Gets the real `ActionsEnv` used by production code.
*/
export function getActionsEnv(): ActionsEnv {
return { getOptionalInput };
}
/**
* Wrapper around core.getInput for inputs that always have a value.
* Also see getOptionalInput.

View File

@@ -10,7 +10,7 @@ import test, {
import nock from "nock";
import * as sinon from "sinon";
import { getActionVersion } from "./actions-util";
import { ActionsEnv, getActionVersion } from "./actions-util";
import { AnalysisKind } from "./analyses";
import * as apiClient from "./api-client";
import { GitHubApiDetails } from "./api-client";
@@ -172,6 +172,15 @@ export function makeMacro<Args extends unknown[]>(
return wrapper;
}
/**
* Gets an `ActionsEnv` instance for use in tests.
*/
export function getTestActionsEnv(): ActionsEnv {
return {
getOptionalInput: () => undefined,
};
}
/**
* Default values for environment variables typically set in an Actions
* environment. Tests can override individual variables by passing them in the