Skip to content

Commit 6026274

Browse files
committed
Persist inputs between the upload action and its post step.
1 parent af56b04 commit 6026274

9 files changed

+60
-4
lines changed

lib/actions-util.js

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action-post.js

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

lib/upload-sarif-action-post.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,29 @@ export async function runTool(
559559
}
560560
return stdout;
561561
}
562+
563+
const persistedInputsKey = "persisted_inputs";
564+
565+
/**
566+
* Persists all inputs to the action as state that can be retrieved later in the post-action.
567+
* This is need due to a runner bug that can cause inputs to be lost in the post-action.
568+
* https://github.com/actions/runner/issues/3514
569+
*/
570+
export const persistInputs = function () {
571+
const inputEnvironmentVariables = Object.entries(process.env).filter(
572+
([name]) => name.startsWith("INPUT_"),
573+
);
574+
core.saveState(persistedInputsKey, JSON.stringify(inputEnvironmentVariables));
575+
};
576+
577+
/**
578+
* Restores all inputs to the action from the persisted state.
579+
*/
580+
export const restoreInputs = function () {
581+
const persistedInputs = core.getState(persistedInputsKey);
582+
if (persistedInputs) {
583+
for (const [name, value] of JSON.parse(persistedInputs)) {
584+
process.env[name] = value;
585+
}
586+
}
587+
};

src/upload-sarif-action-post.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import * as core from "@actions/core";
77

8+
import * as actionsUtil from "./actions-util";
89
import { getTemporaryDirectory } from "./actions-util";
910
import { getGitHubVersion } from "./api-client";
1011
import * as debugArtifacts from "./debug-artifacts";
@@ -20,6 +21,7 @@ import {
2021

2122
async function runWrapper() {
2223
try {
24+
actionsUtil.restoreInputs();
2325
const logger = getActionsLogger();
2426
const gitHubVersion = await getGitHubVersion();
2527
checkGitHubVersionInRange(gitHubVersion, logger);

src/upload-sarif-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ async function run() {
6060
const gitHubVersion = await getGitHubVersion();
6161
checkActionVersion(getActionVersion(), gitHubVersion);
6262

63+
actionsUtil.persistInputs();
64+
6365
const repositoryNwo = parseRepositoryNwo(
6466
getRequiredEnvParam("GITHUB_REPOSITORY"),
6567
);

0 commit comments

Comments
 (0)