diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 335589de7..551d70351 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -132967,12 +132967,9 @@ async function run2(startedAt) { } } function getFinalJobStatus(config) { - const jobStatusFromEnvironment = process.env["CODEQL_ACTION_JOB_STATUS" /* JOB_STATUS */]; - if (jobStatusFromEnvironment !== void 0) { - if (Object.values(JobStatus).includes(jobStatusFromEnvironment)) { - return jobStatusFromEnvironment; - } - return "JOB_STATUS_UNKNOWN" /* UnknownStatus */; + const existingJobStatus = getJobStatusFromEnvironment(); + if (existingJobStatus !== void 0) { + return existingJobStatus; } let jobStatus; if (process.env["CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY" /* ANALYZE_DID_COMPLETE_SUCCESSFULLY */] === "true") { @@ -132986,6 +132983,16 @@ function getFinalJobStatus(config) { core16.exportVariable("CODEQL_ACTION_JOB_STATUS" /* JOB_STATUS */, jobStatus); return jobStatus; } +function getJobStatusFromEnvironment() { + const jobStatusFromEnvironment = process.env["CODEQL_ACTION_JOB_STATUS" /* JOB_STATUS */]; + if (jobStatusFromEnvironment !== void 0) { + if (Object.values(JobStatus).includes(jobStatusFromEnvironment)) { + return jobStatusFromEnvironment; + } + return "JOB_STATUS_UNKNOWN" /* UnknownStatus */; + } + return void 0; +} async function runWrapper() { const startedAt = /* @__PURE__ */ new Date(); const logger = getActionsLogger(); diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 340e01b79..cfae09693 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -141,17 +141,17 @@ async function run(startedAt: Date) { } } +/** + * Determine the final job status to be reported in the status report. + * + * If the job status has already been set by another step, we use that. + * Otherwise, we determine the job status based on whether the analyze step + * completed successfully and whether we have a valid CodeQL config. + */ function getFinalJobStatus(config: Config | undefined): JobStatus { - const jobStatusFromEnvironment = process.env[EnvVar.JOB_STATUS]; - - if (jobStatusFromEnvironment !== undefined) { - // Validate the job status from the environment. If it is invalid, return unknown. - if ( - Object.values(JobStatus).includes(jobStatusFromEnvironment as JobStatus) - ) { - return jobStatusFromEnvironment as JobStatus; - } - return JobStatus.UnknownStatus; + const existingJobStatus = getJobStatusFromEnvironment(); + if (existingJobStatus !== undefined) { + return existingJobStatus; } let jobStatus: JobStatus; @@ -186,6 +186,27 @@ function getFinalJobStatus(config: Config | undefined): JobStatus { return jobStatus; } +/** + * Get the job status from the environment variable, if it has been set. + * + * If the job status is invalid, return `UnknownStatus`. + */ +function getJobStatusFromEnvironment(): JobStatus | undefined { + const jobStatusFromEnvironment = process.env[EnvVar.JOB_STATUS]; + + if (jobStatusFromEnvironment !== undefined) { + // Validate the job status from the environment. If it is invalid, return unknown. + if ( + Object.values(JobStatus).includes(jobStatusFromEnvironment as JobStatus) + ) { + return jobStatusFromEnvironment as JobStatus; + } + return JobStatus.UnknownStatus; + } + + return undefined; +} + async function runWrapper() { const startedAt = new Date(); const logger = getActionsLogger();