- 
                Notifications
    You must be signed in to change notification settings 
- Fork 412
          Add tests for upload-sarif
          #3166
        
          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
Conversation
Note that this also fixes the format of the `sarif-ids` outputs to match what is documented
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
This PR refactors the upload-sarif functionality by extracting upload logic from the action file into a separate module and adding comprehensive unit tests. The changes also fix the output format for sarif-ids and add error handling for cases where no SARIF files are found.
Key changes:
- Moves core upload logic from upload-sarif-action.tstoupload-sarif.tsfor better separation of concerns
- Adds extensive unit tests covering various SARIF file scenarios and upload combinations
- Changes sarif-idsoutput format from array to object structure for easier consumption
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| src/upload-sarif.ts | New module containing extracted upload logic with findAndUploadanduploadSariffunctions | 
| src/upload-sarif.test.ts | Comprehensive unit tests for the new upload-sarif module functions | 
| src/upload-sarif-action.ts | Refactored to use the new upload-sarif module and simplified upload flow | 
| pr-checks/checks/upload-quality-sarif.yml | Updated test to use new sarif-ids object format | 
| lib/upload-sarif-action.js | Generated JavaScript reflecting the TypeScript changes | 
| .github/workflows/__upload-quality-sarif.yml | Updated workflow to use new sarif-ids object format | 
Co-authored-by: Copilot <[email protected]>
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.
LGTM.
It's not blocking, but I'm getting a bit concerned about the complexity of the tests, especially
2adc894. It's the classic tradeoff between what tests current behaviour/API and what is maintainable.
| analysisKind === AnalysisKind.CodeScanning | ||
| ? CodeScanning | ||
| : CodeQuality, | 
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.
could this just be analysisKind? Or do we prefer the explicit casing?
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.
analysisKind: AnalysisKind while CodeScanning: AnalysisConfig and CodeQuality: AnalysisConfig. It maps the kind to the matching configuration. We could have this as a function for reusability instead of this ad-hoc mechanism, but we can't just use analysisKind here since we need an AnalysisConfig object for uploadSpecifiedFiles.
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.
right. My eyes missed the AnalysisKind. prefix.
| 
 I could modify  I'm inclined to accept the tests as they are for now, since I am planning to make further changes anyway and they might affect these tests and allow us to simplify this again later. | 
This PR takes parts of #3157:
upload-sarif-action.tstoupload-sarif.tsupload-sarif.tssarif-idsoutput format to match documentationConfigurationErrorif no SARIF files were uploaded, matching the behaviour ofupload-sarifprior to Fixupload-sarifAction failing if there are no Code Scanning SARIF files #3123This doesn't make any further changes to the actual upload logic beyond the hotfix we added in #3160. I am planning a follow-up PR to improve on that after having come up with an idea for a good approach over the weekend, but want to the tests,
sarif-idsfix, and error for the case where no files were uploaded merged first.Risk assessment
For internal use only. Please select the risk level of this change:
Merge / deployment checklist