-
Notifications
You must be signed in to change notification settings - Fork 402
Validate workflow to check that all codeql-action
versions are the same
#3099
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -72,6 +72,7 @@ function toCodedErrors(errors: { | |||||
export const WorkflowErrors = toCodedErrors({ | ||||||
MissingPushHook: `Please specify an on.push hook to analyze and see code scanning alerts from the default branch on the Security tab.`, | ||||||
CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`, | ||||||
InconsistentActionVersion: `Not all workflow steps that use \`github/codeql-action\` actions use the same version. Please ensure that all such steps use the same version to avoid compatibility issues.`, | ||||||
}); | ||||||
|
||||||
/** | ||||||
|
@@ -161,6 +162,29 @@ export async function getWorkflowErrors( | |||||
} | ||||||
} | ||||||
|
||||||
// Check that all `github/codeql-action` steps use the same ref, i.e. the same version. | ||||||
// Mixing different versions of the actions can lead to unpredictable behaviour. | ||||||
const codeqlStepRefs: string[] = []; | ||||||
for (const job of Object.values(doc?.jobs || {})) { | ||||||
if (Array.isArray(job.steps)) { | ||||||
for (const step of job.steps) { | ||||||
if (step.uses?.startsWith("github/codeql-action/")) { | ||||||
const parts = step.uses.split("@"); | ||||||
if (parts.length >= 2) { | ||||||
codeqlStepRefs.push(parts[parts.length - 1]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic assumes that splitting on '@' will always produce the version as the last part, but this may not handle edge cases correctly. For example, if
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
if ( | ||||||
codeqlStepRefs.length > 0 && | ||||||
!codeqlStepRefs.every((ref) => ref === codeqlStepRefs[0]) | ||||||
) { | ||||||
errors.push(WorkflowErrors.InconsistentActionVersion); | ||||||
} | ||||||
|
||||||
// If there is no push trigger, we will not be able to analyze the default branch. | ||||||
// So add a warning to the user to add a push trigger. | ||||||
// If there is a workflow_call trigger, we don't need a push trigger since we assume | ||||||
|
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: don't we have this kind of parsing elsewhere already?
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.
We have
in
getRemoteConfig
, but I thought I'd keep this simple.