mirror of
https://github.com/github/codeql-action.git
synced 2026-11-05 04:29:40 +00:00
Improve restoreInputs
This commit is contained in:
17
lib/entry-points.js
generated
17
lib/entry-points.js
generated
@@ -170390,17 +170390,22 @@ var persistInputs = function(env = getEnv()) {
|
||||
);
|
||||
core4.saveState(persistedInputsKey, JSON.stringify(inputEnvironmentVariables));
|
||||
};
|
||||
function restoreInputs(logger2) {
|
||||
function restoreInputs(action) {
|
||||
try {
|
||||
const persistedInputsValue = core4.getState(persistedInputsKey);
|
||||
const persistedInputsValue = action.actions.getState(persistedInputsKey);
|
||||
if (persistedInputsValue) {
|
||||
const persistedInputs = JSON.parse(persistedInputsValue);
|
||||
const persistedInputs = JSON.parse(
|
||||
persistedInputsValue
|
||||
);
|
||||
if (!Array.isArray(persistedInputs)) {
|
||||
throw new Error("Restored value is not an array.");
|
||||
}
|
||||
for (const [name, value] of persistedInputs) {
|
||||
process.env[name] = value;
|
||||
action.env.set(name, value);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger2.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
|
||||
action.logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
|
||||
throw new Error(
|
||||
"Failed to restore inputs from the state set by this action's main execution."
|
||||
);
|
||||
@@ -171783,7 +171788,7 @@ async function runInActions(action) {
|
||||
actions: actionsEnv
|
||||
};
|
||||
if (isPostAction(action.name)) {
|
||||
restoreInputs(logger2);
|
||||
restoreInputs(actionState);
|
||||
}
|
||||
getJobUUID(actionState);
|
||||
await action.run(actionState);
|
||||
|
||||
@@ -183,7 +183,7 @@ export async function runInActions(action: Action) {
|
||||
|
||||
// If this is a post-action, restore inputs from the main action.
|
||||
if (isPostAction(action.name)) {
|
||||
restoreInputs(logger);
|
||||
restoreInputs(actionState);
|
||||
}
|
||||
|
||||
// Create a unique identifier for this run.
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as github from "@actions/github";
|
||||
import * as io from "@actions/io";
|
||||
|
||||
import type { ActionState } from "./action-common";
|
||||
import { hasConfigKey, type Config } from "./config/action-config";
|
||||
import { Env, EnvVar, ActionsEnvVars, ReadOnlyEnv } from "./environment";
|
||||
import { Logger } from "./logging";
|
||||
@@ -426,18 +427,26 @@ export const persistInputs = function (env: Env = getEnv()) {
|
||||
/**
|
||||
* Restores all inputs to the action from the persisted state.
|
||||
*/
|
||||
export function restoreInputs(logger: Logger) {
|
||||
export function restoreInputs(
|
||||
action: ActionState<["Env", "Logger", "Actions"]>,
|
||||
) {
|
||||
try {
|
||||
const persistedInputsValue = core.getState(persistedInputsKey);
|
||||
const persistedInputsValue = action.actions.getState(persistedInputsKey);
|
||||
if (persistedInputsValue) {
|
||||
const persistedInputs = JSON.parse(persistedInputsValue);
|
||||
const persistedInputs = JSON.parse(
|
||||
persistedInputsValue,
|
||||
) as PersistedInputs;
|
||||
|
||||
if (!Array.isArray(persistedInputs)) {
|
||||
throw new Error("Restored value is not an array.");
|
||||
}
|
||||
|
||||
for (const [name, value] of persistedInputs) {
|
||||
process.env[name] = value;
|
||||
action.env.set(name, value);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
|
||||
action.logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
|
||||
throw new Error(
|
||||
"Failed to restore inputs from the state set by this action's main execution.",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user