mirror of
https://github.com/github/codeql-action.git
synced 2026-04-28 18:08:53 +00:00
Split up getFinalJobStatus
This commit is contained in:
+31
-10
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user