-
Notifications
You must be signed in to change notification settings - Fork 395
Apply checkout.fetch-depth to safe_outputs checkout steps
#33746
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
f098cb4
46c3ede
0b7c311
0e6d226
283ddb4
05d7024
6abc601
e20cd08
5f64dd6
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 |
|---|---|---|
|
|
@@ -53,6 +53,12 @@ func buildExtractBaseBranchStep() []string { | |
| func (c *Compiler) buildSharedPRCheckoutSteps(data *WorkflowData) []string { | ||
| consolidatedSafeOutputsStepsLog.Print("Building shared PR checkout steps") | ||
| var steps []string | ||
| fetchDepth := 1 | ||
|
|
||
| if defaultCheckout := NewCheckoutManager(data.CheckoutConfigs).GetDefaultCheckoutOverride(); defaultCheckout != nil && defaultCheckout.fetchDepth != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] Good defensive programming: initializing Consider adding a debug log when using the default: fetchDepth := 1
if defaultCheckout := NewCheckoutManager(data.CheckoutConfigs).GetDefaultCheckoutOverride(); defaultCheckout != nil && defaultCheckout.fetchDepth != nil {
fetchDepth = *defaultCheckout.fetchDepth
consolidatedSafeOutputsStepsLog.Printf("Using custom checkout fetch-depth for safe_outputs: %d", fetchDepth)
} else {
consolidatedSafeOutputsStepsLog.Print("Using default fetch-depth: 1")
}This helps with debugging when users expect depth=0 but it silently falls back to depth=1. |
||
| fetchDepth = *defaultCheckout.fetchDepth | ||
| consolidatedSafeOutputsStepsLog.Printf("Using custom checkout fetch-depth for safe_outputs: %d", fetchDepth) | ||
|
Comment on lines
+59
to
+60
|
||
| } | ||
|
|
||
| // Determine which token to use for checkout | ||
| // Uses resolvePRCheckoutToken for consistent token resolution (GitHub App or PAT chain) | ||
|
|
@@ -149,7 +155,7 @@ func (c *Compiler) buildSharedPRCheckoutSteps(data *WorkflowData) []string { | |
| steps = append(steps, " ref: ${{ github.event.repository.default_branch }}\n") | ||
| steps = append(steps, fmt.Sprintf(" token: %s\n", checkoutToken)) | ||
| steps = append(steps, " persist-credentials: false\n") | ||
| steps = append(steps, " fetch-depth: 1\n") | ||
| steps = append(steps, fmt.Sprintf(" fetch-depth: %d\n", fetchDepth)) | ||
| } | ||
|
|
||
| // Step 1b: Checkout repository with conditional execution | ||
|
|
@@ -172,7 +178,7 @@ func (c *Compiler) buildSharedPRCheckoutSteps(data *WorkflowData) []string { | |
| steps = append(steps, fmt.Sprintf(" ref: %s\n", checkoutRef)) | ||
| steps = append(steps, fmt.Sprintf(" token: %s\n", checkoutToken)) | ||
| steps = append(steps, " persist-credentials: false\n") | ||
| steps = append(steps, " fetch-depth: 1\n") | ||
| steps = append(steps, fmt.Sprintf(" fetch-depth: %d\n", fetchDepth)) | ||
|
|
||
| // Step 2: Configure Git credentials with conditional execution | ||
| // Security: Pass GitHub token through environment variable to prevent template injection | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,12 @@ import ( | |
|
|
||
| // TestBuildSharedPRCheckoutSteps tests shared PR checkout step generation | ||
| func TestBuildSharedPRCheckoutSteps(t *testing.T) { | ||
| fetchDepthZero := 0 | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| safeOutputs *SafeOutputsConfig | ||
| checkoutConfigs []*CheckoutConfig | ||
| trialMode bool | ||
| trialRepo string | ||
| checkContains []string | ||
|
|
@@ -39,6 +42,21 @@ func TestBuildSharedPRCheckoutSteps(t *testing.T) { | |
| "github-actions[bot]@users.noreply.github.com", | ||
| }, | ||
| }, | ||
| { | ||
| name: "uses custom checkout fetch-depth", | ||
| safeOutputs: &SafeOutputsConfig{ | ||
| CreatePullRequests: &CreatePullRequestsConfig{}, | ||
| }, | ||
| checkoutConfigs: []*CheckoutConfig{ | ||
| {FetchDepth: &fetchDepthZero}, | ||
| }, | ||
| checkContains: []string{ | ||
| "fetch-depth: 0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] This test case validates the happy path (custom fetch-depth is applied), but it's missing edge case coverage:
Consider adding test cases for these scenarios to ensure the default fallback logic ( {
name: "uses default fetch-depth when CheckoutConfigs is nil",
safeOutputs: &SafeOutputsConfig{
CreatePullRequests: &CreatePullRequestsConfig{},
},
checkoutConfigs: nil,
checkContains: []string{
"fetch-depth: 1",
},
},
{
name: "uses default fetch-depth when CheckoutConfigs is empty",
safeOutputs: &SafeOutputsConfig{
CreatePullRequests: &CreatePullRequestsConfig{},
},
checkoutConfigs: []*CheckoutConfig{},
checkContains: []string{
"fetch-depth: 1",
},
},These edge cases protect against regressions if the |
||
| }, | ||
| checkNotContains: []string{ | ||
| "fetch-depth: 1", | ||
| }, | ||
| }, | ||
| { | ||
| name: "push to PR branch only", | ||
| safeOutputs: &SafeOutputsConfig{ | ||
|
|
@@ -317,8 +335,9 @@ func TestBuildSharedPRCheckoutSteps(t *testing.T) { | |
| } | ||
|
|
||
| workflowData := &WorkflowData{ | ||
| Name: "Test Workflow", | ||
| SafeOutputs: tt.safeOutputs, | ||
| Name: "Test Workflow", | ||
| SafeOutputs: tt.safeOutputs, | ||
| CheckoutConfigs: tt.checkoutConfigs, | ||
| } | ||
|
|
||
| steps := compiler.buildSharedPRCheckoutSteps(workflowData) | ||
|
|
||
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.
[/diagnose] Potential inefficiency:
NewCheckoutManager(data.CheckoutConfigs)is called inline within theifcondition.If
CheckoutConfigsis large orNewCheckoutManagerhas non-trivial initialization logic, this could be optimized:This makes the code more readable and avoids potential repeated instantiation if the manager is used elsewhere in this function.