Configure CodeQL to output SARIF artifacts without uploading to Code Scanning#10
Configure CodeQL to output SARIF artifacts without uploading to Code Scanning#10Copilot wants to merge 2 commits into
Conversation
… as artifact Co-authored-by: igor-holt <125706350+igor-holt@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| # Optional: archive SARIF as a plain artifact | ||
| - name: Upload SARIF artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| sarif_file: ../results | ||
| continue-on-error: true | ||
| name: codeql-sarif | ||
| path: results/**/*.sarif |
There was a problem hiding this comment.
The new artifact upload step now points to results/**/*.sarif, but the CodeQL analyze action writes its SARIF bundle into ../results (see the previous workflow version where sarif_file: ../results was required for upload-sarif). Because the directory name and depth no longer match, the actions/upload-artifact@v4 step never finds any files to upload, so the workflow produces no downloadable SARIF despite the stated goal of the change. The path should continue to target ../results (or whatever directory analyze is configured to emit) before this workflow can deliver the promised artifacts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the CodeQL workflow to output SARIF security analysis results as downloadable workflow artifacts instead of uploading them to GitHub Code Scanning. This allows manual review of security findings without populating the repository's Security tab.
Key Changes
- Removed
security-events: writepermission since Code Scanning upload is disabled - Added
upload: "false"parameter to the CodeQL analyze action to prevent automatic upload - Replaced
github/codeql-action/upload-sarif@v3withactions/upload-artifact@v4to save SARIF files as workflow artifacts
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| sarif_file: ../results | ||
| continue-on-error: true | ||
| name: codeql-sarif | ||
| path: results/**/*.sarif |
There was a problem hiding this comment.
The SARIF file path pattern is likely incorrect. When using upload: "false" in the CodeQL analyze action, the SARIF files are typically generated in ../results/ (relative to the GitHub workspace), not results/ within the workspace.
The correct path should be:
path: ../results/*.sarifAdditionally, you may want to specify an output parameter in the analyze step to explicitly control where SARIF files are saved:
- name: Perform CodeQL Analysis (no code scanning upload)
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
upload: "false"
output: ../results| with: | ||
| sarif_file: ../results | ||
| continue-on-error: true | ||
| name: codeql-sarif |
There was a problem hiding this comment.
The artifact name should include the language from the matrix to avoid conflicts when multiple languages are analyzed. Since this workflow uses a matrix strategy for languages, uploading artifacts with the same name will cause them to overwrite each other.
Consider using:
name: codeql-sarif-${{ matrix.language }}| name: codeql-sarif | |
| name: codeql-sarif-${{ matrix.language }} |
Modified the CodeQL workflow to run security analysis and save results as downloadable artifacts instead of uploading to GitHub Code Scanning.
Changes
security-events: write(not needed without code scanning upload)upload: "false"to disable automatic upload to Code Scanningcodeql-action/upload-sarifwithactions/upload-artifact@v4to save SARIF files as workflow artifactsThis allows manual review of security findings without populating the repository's Security tab.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.