-
Notifications
You must be signed in to change notification settings - Fork 434
Simplify computation of job status #3420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify computation of job status #3420
Conversation
- Move it out of the failed SARIF reporting so we compute the job status whether or not we have a CodeQL config. - Add comments to clarify what happens in the case that the CodeQL config is absent.
c1f6643 to
dcd1b12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Summary:
This PR refactors job status computation to centralize the logic in a single function (getFinalJobStatus) in init-action-post.ts, moving it from init-action-post-helper.ts where it was previously split across multiple functions. The refactoring adds clarifying comments about behavior when CodeQL config is absent.
Changes:
- Moved and enhanced
getFinalJobStatusfunction frominit-action-post-helper.tstoinit-action-post.ts, accepting aConfigparameter to handle the case where config is undefined - Simplified
tryUploadSarifIfRunFailedininit-action-post-helper.tsby removing job status setting logic - Fixed spelling from "analysing" to "analyzing" for consistency
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/init-action-post.ts | Added centralized getFinalJobStatus function with improved logic and comments; fixed spelling consistency |
| src/init-action-post-helper.ts | Removed job status setting logic from tryUploadSarifIfRunFailed; removed getFinalJobStatus export |
| lib/init-action-post.js | Generated JavaScript (not reviewed per custom guidelines) |
mbg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on simplifying this! I think that the changes here are a good step towards accomplishing that.
I agree with the "High risk" assessment for this PR, since there are changes to code that always runs. Whenever we have a "High risk" PR, it's worth assessing whether this is unavoidable as a result of the nature of the change, due to a lack of FF (and whether one can reasonably be added), or because of a lack of test coverage. I note that all of this refactoring was able to pass CI without any adjustments to any tests.
The job status computation spans an entire CodeQL workflow as follows:
- Whenever we send a status report for a
failure,aborted, oruser-errorstatus, we setEnvVar.JOB_STATUSaccordingly, unless it is already set to some value. - Consequently, by the time we get to the
init-postaction, we are in one of the following scenarios:- An earlier step failed, we sent a status report, and
EnvVar.JOB_STATUSis set accordingly. - An earlier step failed catastrophically, and we did not set
EnvVar.JOB_STATUS. - Everything succeeded,
EnvVar.JOB_STATUSis not set, butEnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLYis set totrue.
- An earlier step failed, we sent a status report, and
In general, we do not change the value of EnvVar.JOB_STATUS if it is already set.
Previously, we had the following logic in init-post:
- If an
initstep successfully initialised aConfig, then we runinitActionPostHelper.runwhich callstryUploadSarifIfRunFailed:- If
EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLYisn'ttrue:- If
EnvVar.JOB_STATUSis not already set, it setsEnvVar.JOB_STATUStoJobStatus.ConfigErrorStatus. - Otherwise,
EnvVar.JOB_STATUSkeeps its existing value.
- If
- Else:
EnvVar.JOB_STATUSis set toJobStatus.SuccessStatus, if not already set to some value.
- If
- If no
Configwas initialised by aninitstep, we do not callinitActionPostHelper.runand none of the above logic that might setEnvVar.JOB_STATUSruns. I.e.EnvVar.JOB_STATUSremains the same as wheninit-poststarted. - Then,
initActionPostHelper.getFinalJobStatus()is used to retrieve the value ofEnvVar.JOB_STATUSand convert it to a correspondingJobStatusvalue. IfEnvVar.JOB_STATUSis unset or invalid, thenJobStatus.UnknownStatusis returned.
The new logic in this PR removes all EnvVar.JOB_STATUS-related code from tryUploadSarifIfRunFailed and moves it into a new getFinalJobStatus() function which combines the EnvVar.JOB_STATUS-related parts from tryUploadSarifIfRunFailed with the old behaviour of initActionPostHelper.getFinalJobStatus().
The change here is limited to the init-post action and we don't change the order in which the EnvVar.JOB_STATUS-related checks/computations are performed. However, we may be computing a final value for EnvVar.JOB_STATUS later than before. Therefore, I would expect these changes to at most impact the job status that is reported in status reports, if e.g. an exception is thrown after we previously would have computed the final job status, but before we do it with these changes.
If the change only affects status reports, then I think that no FF and the associated complexity of maintaining two code paths is required.
I don't see any blockers here. It would be good to use this opportunity to improve our unit test coverage, though. Aside from that, I only have some minor comments (including a couple unrelated to the changes in this PR).
| return JobStatus.UnknownStatus; | ||
| } | ||
|
|
||
| let jobStatus: JobStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a unit test for the part of this function from here onwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave this as is for now.
| } | ||
| } | ||
|
|
||
| export async function run( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR, but why do we have a run function here? It's a bit confusing that we typically have run functions in the -action[-post].ts entry points, and here we have one in a module that's not that. We also have a run function call another run function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this is suboptimal, but will leave this as is for now to avoid scope creep.
| ); | ||
|
|
||
| // If we are analysing the default branch and some kind of caching is enabled, | ||
| // If we are analyzing the default branch and some kind of caching is enabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: This seems like an unnecessary and unrelated change 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a spell checker in my IDE that was complaining, nothing personal 😆
Refactor how we compute job status so this happens in a single place, and whether or not we have a CodeQL config. Also add comments to clarify what happens in the case that the CodeQL config is absent.
Risk assessment
For internal use only. Please select the risk level of this change:
Which use cases does this change impact?
Workflow types:
dynamicworkflows (Default Setup, CCR, ...).Products:
analysis-kinds: code-scanning.analysis-kinds: code-quality.Environments:
github.comand/or GitHub Enterprise Cloud with Data Residency.How did/will you validate this change?
pr-checks).If something goes wrong after this change is released, what are the mitigation and rollback strategies?
How will you know if something goes wrong after this change is released?
Are there any special considerations for merging or releasing this change?
Merge / deployment checklist