From 64ec5d5f6775d0afa3757a8248edf1d513a8a55e Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Oct 2026 22:18:06 +0100 Subject: [PATCH] Improve `restoreInputs` --- lib/entry-points.js | 17 +++++++++++------ src/action-common.ts | 2 +- src/actions-util.ts | 19 ++++++++++++++----- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 0f2ade5c1..9fbf311f2 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -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); diff --git a/src/action-common.ts b/src/action-common.ts index 908cb3c63..e2dc0d199 100644 --- a/src/action-common.ts +++ b/src/action-common.ts @@ -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. diff --git a/src/actions-util.ts b/src/actions-util.ts index 35d9676b9..44e58bcf7 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -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.", );