Add setFailed to ActionsEnv

This commit is contained in:
Michael B. Gale
2026-10-19 19:59:14 +01:00
parent 9d9422aff0
commit 938d1c591f
3 changed files with 22 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ declare const __CODEQL_ACTION_VERSION__: string;
export interface ActionsEnv {
getRequiredInput: (name: string) => string;
getOptionalInput: (name: string) => string | undefined;
setFailed: (message: string) => void;
}
/**
@@ -39,6 +40,7 @@ export function getActionsEnv(): ActionsEnv {
return {
getRequiredInput,
getOptionalInput,
setFailed: core.setFailed,
};
}

View File

@@ -227,8 +227,13 @@ export function getTestEnv(testEnv: NodeJS.ProcessEnv = {}): Env {
return getEnv(testEnv);
}
/** An implementation of `ActionsEnv` for use in tests. */
/**
* An implementation of {@link ActionsEnv} for use in tests.
* The methods of instances of this class are intended to be stubbed.
*/
class TestActionsEnv implements ActionsEnv {
private failed: boolean = false;
constructor(private readonly env: Env) {}
public clone(env: Env): this {
@@ -242,6 +247,14 @@ class TestActionsEnv implements ActionsEnv {
public getOptionalInput(_name: string): string | undefined {
return undefined;
}
public setFailed(_message: string) {
this.failed = true;
}
get hasFailed() {
return this.failed;
}
}
/**