-
Notifications
You must be signed in to change notification settings - Fork 302
Fix invalid checkout-pr output references in workflows without contents permission #14286
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 |
|---|---|---|
|
|
@@ -163,7 +163,10 @@ func (c *Compiler) buildConclusionJob(data *WorkflowData, mainJobName string, sa | |
| } | ||
|
|
||
| // Add checkout_pr_success to detect PR checkout failures (e.g., PR merged and branch deleted) | ||
| agentFailureEnvVars = append(agentFailureEnvVars, fmt.Sprintf(" GH_AW_CHECKOUT_PR_SUCCESS: ${{ needs.%s.outputs.checkout_pr_success }}\n", mainJobName)) | ||
| // Only add if the checkout-pr step will be generated (requires contents read access) | ||
| if ShouldGeneratePRCheckoutStep(data) { | ||
| agentFailureEnvVars = append(agentFailureEnvVars, fmt.Sprintf(" GH_AW_CHECKOUT_PR_SUCCESS: ${{ needs.%s.outputs.checkout_pr_success }}\n", mainJobName)) | ||
| } | ||
|
Comment on lines
165
to
+169
|
||
|
|
||
| // Pass assignment error outputs from safe_outputs job if assign-to-agent is configured | ||
| if data.SafeOutputs != nil && data.SafeOutputs.AssignToAgent != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| //go:build !integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestShouldGeneratePRCheckoutStep(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| permissions string | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "with contents read permission", | ||
| permissions: "contents: read", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "with contents write permission", | ||
| permissions: "contents: write", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "without contents permission", | ||
| permissions: "issues: read", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "with read-all shorthand", | ||
| permissions: "read-all", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "with write-all shorthand", | ||
| permissions: "write-all", | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "with none shorthand", | ||
| permissions: "none", | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "with all: read", | ||
| permissions: `all: read`, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "multiple permissions including contents", | ||
| permissions: `contents: read | ||
| issues: write | ||
| pull-requests: read`, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "multiple permissions without contents", | ||
| permissions: `issues: write | ||
| pull-requests: read`, | ||
| expected: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| data := &WorkflowData{ | ||
| Permissions: tt.permissions, | ||
| } | ||
| result := ShouldGeneratePRCheckoutStep(data) | ||
| assert.Equal(t, tt.expected, result, "ShouldGeneratePRCheckoutStep() result mismatch") | ||
| }) | ||
| } | ||
| } |
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.
The new conditional addition of
checkout_pr_successoutput isn’t covered by unit tests. Sincepkg/workflow/compiler_activation_jobs_test.goalready exercisesbuildMainJob, add assertions for both cases (permissions with contents read/write vs. without contents) to ensure the output key is present/absent as expected and prevent regressions to invalidsteps.checkout-pr.outputs.*references.