Skip to content

Commit a9b29f1

Browse files
committed
Use runInActions for init-post
1 parent a60169d commit a9b29f1

3 files changed

Lines changed: 33 additions & 42 deletions

File tree

‎lib/entry-points.js‎

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

‎src/init-action-post.ts‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import * as core from "@actions/core";
88

9+
import { runInActions, type Action, type ActionState } from "./action-common";
910
import {
1011
restoreInputs,
1112
getOptionalInput,
@@ -25,12 +26,10 @@ import { EnvVar, getEnv, exportEnvVar } from "./environment";
2526
import { initFeatures } from "./feature-flags";
2627
import * as gitUtils from "./git-utils";
2728
import * as initActionPostHelper from "./init-action-post-helper";
28-
import { getActionsLogger } from "./logging";
2929
import { getRepositoryNwo } from "./repository";
3030
import {
3131
StatusReportBase,
3232
sendStatusReport,
33-
sendUnhandledErrorStatusReport,
3433
createStatusReportBase,
3534
getActionsStatus,
3635
ActionName,
@@ -45,16 +44,17 @@ interface InitPostStatusReport
4544
initActionPostHelper.JobStatusReport,
4645
initActionPostHelper.DependencyCachingUsageReport {}
4746

48-
async function run(startedAt: Date) {
47+
async function run(action: ActionState<["Base", "Logger"]>) {
4948
// To capture errors appropriately, keep as much code within the try-catch as
5049
// possible, and only use safe functions outside.
50+
const logger = action.logger;
5151

52-
const logger = getActionsLogger();
5352
let config: Config | undefined;
5453
let uploadFailedSarifResult:
5554
| initActionPostHelper.UploadFailedSarifResult
5655
| undefined;
5756
let dependencyCachingUsage: DependencyCachingUsageReport | undefined;
57+
5858
try {
5959
// Read the job status before restoring inputs, since it is provided by the Actions runtime
6060
// environment for this step and would otherwise be overwritten by the value that the `init`
@@ -64,7 +64,8 @@ async function run(startedAt: Date) {
6464
// Restore inputs from `init` Action.
6565
restoreInputs(logger);
6666

67-
config = await getConfig(getTemporaryDirectory(), logger);
67+
const tmpDir = getTemporaryDirectory();
68+
config = await getConfig(tmpDir, logger);
6869

6970
const gitHubVersion = config?.gitHubVersion ?? (await getGitHubVersion());
7071
checkGitHubVersionInRange(gitHubVersion, logger);
@@ -112,9 +113,9 @@ async function run(startedAt: Date) {
112113
core.setFailed(error.message);
113114

114115
const statusReportBase = await createStatusReportBase(
115-
ActionName.InitPost,
116+
action.name,
116117
getActionsStatus(error),
117-
startedAt,
118+
action.startedAt,
118119
config,
119120
await checkDiskUsage(logger),
120121
logger,
@@ -130,9 +131,9 @@ async function run(startedAt: Date) {
130131
logger.info(`CodeQL job status was ${getJobStatusDisplayName(jobStatus)}.`);
131132

132133
const statusReportBase = await createStatusReportBase(
133-
ActionName.InitPost,
134+
action.name,
134135
"success",
135-
startedAt,
136+
action.startedAt,
136137
config,
137138
await checkDiskUsage(logger),
138139
logger,
@@ -216,18 +217,11 @@ function getJobStatusFromEnvironment(): JobStatus | undefined {
216217
return undefined;
217218
}
218219

220+
const initPost: Action = {
221+
name: ActionName.InitPost,
222+
run,
223+
};
224+
219225
export async function runWrapper() {
220-
const startedAt = new Date();
221-
const logger = getActionsLogger();
222-
try {
223-
await run(startedAt);
224-
} catch (error) {
225-
core.setFailed(`init post action failed: ${wrapError(error).message}`);
226-
await sendUnhandledErrorStatusReport(
227-
ActionName.InitPost,
228-
startedAt,
229-
error,
230-
logger,
231-
);
232-
}
226+
return await runInActions(initPost);
233227
}

‎src/status-report.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export enum ActionName {
6868
export function getDisplayActionName(actionName: ActionName): string {
6969
if (actionName === ActionName.Analyze) {
7070
return "analyze";
71+
} else if (actionName === ActionName.InitPost) {
72+
return "init post";
7173
}
7274
return actionName;
7375
}

0 commit comments

Comments
 (0)