Skip to content

Commit b333fc6

Browse files
committed
Split up getFinalJobStatus
1 parent 60b658e commit b333fc6

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

lib/init-action-post.js

Lines changed: 13 additions & 6 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: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ async function run(startedAt: Date) {
141141
}
142142
}
143143

144+
/**
145+
* Determine the final job status to be reported in the status report.
146+
*
147+
* If the job status has already been set by another step, we use that.
148+
* Otherwise, we determine the job status based on whether the analyze step
149+
* completed successfully and whether we have a valid CodeQL config.
150+
*/
144151
function getFinalJobStatus(config: Config | undefined): JobStatus {
145-
const jobStatusFromEnvironment = process.env[EnvVar.JOB_STATUS];
146-
147-
if (jobStatusFromEnvironment !== undefined) {
148-
// Validate the job status from the environment. If it is invalid, return unknown.
149-
if (
150-
Object.values(JobStatus).includes(jobStatusFromEnvironment as JobStatus)
151-
) {
152-
return jobStatusFromEnvironment as JobStatus;
153-
}
154-
return JobStatus.UnknownStatus;
152+
const existingJobStatus = getJobStatusFromEnvironment();
153+
if (existingJobStatus !== undefined) {
154+
return existingJobStatus;
155155
}
156156

157157
let jobStatus: JobStatus;
@@ -186,6 +186,27 @@ function getFinalJobStatus(config: Config | undefined): JobStatus {
186186
return jobStatus;
187187
}
188188

189+
/**
190+
* Get the job status from the environment variable, if it has been set.
191+
*
192+
* If the job status is invalid, return `UnknownStatus`.
193+
*/
194+
function getJobStatusFromEnvironment(): JobStatus | undefined {
195+
const jobStatusFromEnvironment = process.env[EnvVar.JOB_STATUS];
196+
197+
if (jobStatusFromEnvironment !== undefined) {
198+
// Validate the job status from the environment. If it is invalid, return unknown.
199+
if (
200+
Object.values(JobStatus).includes(jobStatusFromEnvironment as JobStatus)
201+
) {
202+
return jobStatusFromEnvironment as JobStatus;
203+
}
204+
return JobStatus.UnknownStatus;
205+
}
206+
207+
return undefined;
208+
}
209+
189210
async function runWrapper() {
190211
const startedAt = new Date();
191212
const logger = getActionsLogger();

0 commit comments

Comments
 (0)