66
77import * as core from "@actions/core" ;
88
9+ import { runInActions , type Action , type ActionState } from "./action-common" ;
910import {
1011 restoreInputs ,
1112 getOptionalInput ,
@@ -25,12 +26,10 @@ import { EnvVar, getEnv, exportEnvVar } from "./environment";
2526import { initFeatures } from "./feature-flags" ;
2627import * as gitUtils from "./git-utils" ;
2728import * as initActionPostHelper from "./init-action-post-helper" ;
28- import { getActionsLogger } from "./logging" ;
2929import { getRepositoryNwo } from "./repository" ;
3030import {
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+
219225export 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}
0 commit comments