@@ -6,6 +6,7 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
66import * as github from "@actions/github" ;
77import * as io from "@actions/io" ;
88
9+ import type { ActionState } from "./action-common" ;
910import { hasConfigKey , type Config } from "./config/action-config" ;
1011import { Env , EnvVar , ActionsEnvVars , ReadOnlyEnv } from "./environment" ;
1112import { 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