-
Notifications
You must be signed in to change notification settings - Fork 325
fix: use token instead of github-token for upload-sarif action
#23837
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 |
|---|---|---|
|
|
@@ -78,9 +78,43 @@ func (c *Compiler) buildUploadCodeScanningSARIFStep(data *WorkflowData) []string | |
| steps = append(steps, " if: steps.process_safe_outputs.outputs.sarif_file != ''\n") | ||
| steps = append(steps, fmt.Sprintf(" uses: %s\n", GetActionPin("github/codeql-action/upload-sarif"))) | ||
| steps = append(steps, " with:\n") | ||
| c.addSafeOutputGitHubTokenForConfig(&steps, data, data.SafeOutputs.CreateCodeScanningAlerts.GitHubToken) | ||
| // NOTE: github/codeql-action/upload-sarif uses 'token' as the input name, not 'github-token' | ||
| c.addUploadSARIFToken(&steps, data, data.SafeOutputs.CreateCodeScanningAlerts.GitHubToken) | ||
| steps = append(steps, " sarif_file: ${{ steps.process_safe_outputs.outputs.sarif_file }}\n") | ||
| steps = append(steps, " wait-for-processing: true\n") | ||
|
|
||
| return steps | ||
| } | ||
|
|
||
| // addUploadSARIFToken adds the 'token' input for github/codeql-action/upload-sarif. | ||
| // This action uses 'token' as the input name (not 'github-token' like other GitHub Actions). | ||
| // Uses precedence: config token > safe-outputs global github-token > GH_AW_GITHUB_TOKEN || GITHUB_TOKEN | ||
| func (c *Compiler) addUploadSARIFToken(steps *[]string, data *WorkflowData, configToken string) { | ||
| var safeOutputsToken string | ||
| if data.SafeOutputs != nil { | ||
| safeOutputsToken = data.SafeOutputs.GitHubToken | ||
| } | ||
|
|
||
| // If app is configured, use app token | ||
| if data.SafeOutputs != nil && data.SafeOutputs.GitHubApp != nil { | ||
| *steps = append(*steps, " token: ${{ steps.safe-outputs-app-token.outputs.token }}\n") | ||
| return | ||
|
Comment on lines
+89
to
+101
|
||
| } | ||
|
|
||
| // Choose the first non-empty custom token for precedence | ||
| effectiveCustomToken := configToken | ||
| if effectiveCustomToken == "" { | ||
| effectiveCustomToken = safeOutputsToken | ||
| } | ||
|
|
||
| effectiveToken := getEffectiveSafeOutputGitHubToken(effectiveCustomToken) | ||
| // Log which token source is being used for debugging | ||
| tokenSource := "default (GH_AW_GITHUB_TOKEN || GITHUB_TOKEN)" | ||
| if configToken != "" { | ||
| tokenSource = "per-config github-token" | ||
| } else if safeOutputsToken != "" { | ||
| tokenSource = "safe-outputs github-token" | ||
| } | ||
| createCodeScanningAlertLog.Printf("Using token for SARIF upload from source: %s (upload-sarif uses 'token' not 'github-token')", tokenSource) | ||
| *steps = append(*steps, fmt.Sprintf(" token: %s\n", effectiveToken)) | ||
| } | ||
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.
uploadStepStart := strings.Index(stepsContent, "- name: Upload SARIF to GitHub Code Scanning")is unlikely to match because the compiled YAML step name line is indented (e.g., it’s emitted as" - name: Upload SARIF to GitHub Code Scanning\n"). This will make the test fail even when the step exists. Update the search string to include the expected indentation (or use a more robust delimiter that doesn’t depend on exact spacing).