Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixupload-sarif potentially initialising CodeQL twice#3006

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mbg wants to merge5 commits intomain
base:main
Choose a base branch
Loading
frommbg/upload-sarif/fix-twice-init

Conversation

@mbg
Copy link
Member

@mbgmbg commentedAug 6, 2025

Theupload-sarif action can be used in workflows without aninit step. This means that it is possible for theupload-sarif action to be used correctly even though the CodeQL CLI has not yet been initialised. However, if we are uploading multiple SARIF files to a given endpoint, then these are first combined using the CodeQL CLI. To allow this, we currently initialise the CodeQL CLI on the fly incombineSarifFilesUsingCLI if needed for this.

This was fine until#2935 where we started uploading two separate SARIF files andcombineSarifFilesUsingCLI could appear more than once in the call path. Since the CodeQL instance was shared, this could result in the CLI being initialised twice.

This PR changes theupload-sarif action to initialise the CLI if needed earlier on in the flow and then propagates the instance down the call path so that it can be shared between multiple calls tocombineSarifFilesUsingCLI.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm thereadme has been updated if necessary.
  • Confirm thechangelog has been updated if necessary.

@mbgmbg requested a review froma team as acode ownerAugust 6, 2025 14:57
CopilotAI review requested due to automatic review settingsAugust 6, 2025 14:57
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

The PR fixes a bug where theupload-sarif action could initialize the CodeQL CLI twice when uploading multiple SARIF files. This occurred becausecombineSarifFilesUsingCLI could be called multiple times in the execution path and each call would initialize CodeQL if needed.

  • Extracts CodeQL initialization logic to occur earlier in the upload flow when multiple SARIF files are detected
  • Refactors the upload functions to accept and pass through a CodeQL instance parameter
  • Updates all call sites to pass the CodeQL instance parameter

Reviewed Changes

Copilot reviewed 10 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/upload-sarif-action.tsMain fix - initializes CodeQL early and passes it to upload functions, adds helper functions to find SARIF files
src/upload-lib.tsRefactors upload functions to accept CodeQL parameter, extracts initialization logic to new function
src/init-action-post-helper.tsUpdates uploadFiles call to pass CodeQL instance
src/analyze-action.tsUpdates uploadFiles calls to pass CodeQL instance
src/init-action-post-helper.test.tsUpdates test assertion to match new function signature
lib/*.jsGenerated JavaScript files that mirror the TypeScript changes

);
}

return[];
Copy link

CopilotAIAug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The two helper functionsfindSecuritySarifFiles andfindQualitySarifFiles have duplicated logic. Consider extracting a common function that accepts the predicate as a parameter, or creating a more general function that returns both types of files to reduce code duplication.

Suggested change
return[];
asyncfunctionfindSarifFilesWithPredicate(
sarifPath:string,
predicate:(file:string)=>boolean,
fallback:string[],
):Promise<string[]>{
if(fs.lstatSync(sarifPath).isDirectory()){
returnupload_lib.findSarifFilesInDir(sarifPath,predicate);
}
returnfallback;
}
asyncfunctionfindSecuritySarifFiles(sarifPath:string):Promise<string[]>{
returnfindSarifFilesWithPredicate(
sarifPath,
upload_lib.CodeScanningTarget.sarifPredicate,
[sarifPath],
);
}
asyncfunctionfindQualitySarifFiles(sarifPath:string):Promise<string[]>{
returnfindSarifFilesWithPredicate(
sarifPath,
upload_lib.CodeQualityTarget.sarifPredicate,
[],
);

Copilot uses AI. Check for mistakes.
}else{
codeQL=awaitinitCodeQLForUpload(gitHubVersion,features,logger);
}
}
Copy link

CopilotAIAug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This CodeQL initialization logic is duplicated from the originalcombineSarifFilesUsingCLI function. Since this initialization is now handled earlier in the flow in most cases, consider adding a comment explaining when this fallback initialization is still needed to clarify the code's intent.

Copilot uses AI. Check for mistakes.
henrymercer
henrymercer previously approved these changesAug 6, 2025
@mbg
Copy link
MemberAuthor

mbg commentedAug 7, 2025

@henrymercer I rebased to resolve merge conflicts and added4836131 since the init logic inuploadSpecifiedFiles shouldn't be needed anymore. It would probably be nicer if we split up that function into a variant that requires theCodeQL instance and uploads multiple files and one that doesn't and uploads a single file, but I am not sure it's worth the effort. What do you think?

@mbgmbg requested a review fromhenrymercerAugust 7, 2025 11:27
Copy link
Contributor

@henrymercerhenrymercer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Throwing out a thought here — how about uploadSpecifiedFiles takes agetCodeQL(): async () => CodeQL function? We could then haveanalyze provide its CodeQL instance, andupload-sarif provide a function that memoises CodeQL so it's only loaded once?

@mbg
Copy link
MemberAuthor

mbg commentedAug 7, 2025

Not a bad idea. It would probably mean throwing most of the changes in this PR out, but it would be a simpler overall change and not require us to split upuploadSpecifiedFiles or deal with the current awkwardness.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@henrymercerhenrymercerhenrymercer left review comments

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

@mbgmbg

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@mbg@henrymercer

[8]ページ先頭

©2009-2025 Movatter.jp