Skip to content

Commit 64ec5d5

Browse files
committed
Improve restoreInputs
1 parent 5b8ae33 commit 64ec5d5

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/action-common.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export async function runInActions(action: Action) {
183183

184184
// If this is a post-action, restore inputs from the main action.
185185
if (isPostAction(action.name)) {
186-
restoreInputs(logger);
186+
restoreInputs(actionState);
187187
}
188188

189189
// Create a unique identifier for this run.

‎src/actions-util.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
66
import * as github from "@actions/github";
77
import * as io from "@actions/io";
88

9+
import type { ActionState } from "./action-common";
910
import { hasConfigKey, type Config } from "./config/action-config";
1011
import { Env, EnvVar, ActionsEnvVars, ReadOnlyEnv } from "./environment";
1112
import { Logger } from "./logging";
@@ -426,18 +427,26 @@ export const persistInputs = function (env: Env = getEnv()) {
426427
/**
427428
* Restores all inputs to the action from the persisted state.
428429
*/
429-
export function restoreInputs(logger: Logger) {
430+
export function restoreInputs(
431+
action: ActionState<["Env", "Logger", "Actions"]>,
432+
) {
430433
try {
431-
const persistedInputsValue = core.getState(persistedInputsKey);
434+
const persistedInputsValue = action.actions.getState(persistedInputsKey);
432435
if (persistedInputsValue) {
433-
const persistedInputs = JSON.parse(persistedInputsValue);
436+
const persistedInputs = JSON.parse(
437+
persistedInputsValue,
438+
) as PersistedInputs;
439+
440+
if (!Array.isArray(persistedInputs)) {
441+
throw new Error("Restored value is not an array.");
442+
}
434443

435444
for (const [name, value] of persistedInputs) {
436-
process.env[name] = value;
445+
action.env.set(name, value);
437446
}
438447
}
439448
} catch (err) {
440-
logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
449+
action.logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
441450
throw new Error(
442451
"Failed to restore inputs from the state set by this action's main execution.",
443452
);

0 commit comments

Comments
 (0)