Persist inputs between the upload action and its post step.

This commit is contained in:
Chris Gavin 2024-10-21 10:37:48 +01:00
parent af56b044b5
commit 6026274108
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
9 changed files with 60 additions and 4 deletions

View file

@ -559,3 +559,29 @@ export async function runTool(
}
return stdout;
}
const persistedInputsKey = "persisted_inputs";
/**
* Persists all inputs to the action as state that can be retrieved later in the post-action.
* This is need due to a runner bug that can cause inputs to be lost in the post-action.
* https://github.com/actions/runner/issues/3514
*/
export const persistInputs = function () {
const inputEnvironmentVariables = Object.entries(process.env).filter(
([name]) => name.startsWith("INPUT_"),
);
core.saveState(persistedInputsKey, JSON.stringify(inputEnvironmentVariables));
};
/**
* Restores all inputs to the action from the persisted state.
*/
export const restoreInputs = function () {
const persistedInputs = core.getState(persistedInputsKey);
if (persistedInputs) {
for (const [name, value] of JSON.parse(persistedInputs)) {
process.env[name] = value;
}
}
};