Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/cli/copilot_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,32 @@ func ensureCopilotSetupSteps(verbose bool) error {
return nil
}

// injectExtensionInstallStep injects the gh-aw extension install step into an existing workflow
// injectExtensionInstallStep injects the gh-aw extension install and verification steps into an existing workflow
func injectExtensionInstallStep(workflow *Workflow) error {
// Define the extension install step to inject
extensionStep := WorkflowStep{
// Define the extension install and verify steps to inject
installStep := WorkflowStep{
Name: "Install gh-aw extension",
Run: "curl -fsSL https://raw.githubusercontent.com/githubnext/gh-aw/refs/heads/main/install-gh-aw.sh | bash",
}
verifyStep := WorkflowStep{
Name: "Verify gh-aw installation",
Run: "./gh-aw version",
}

// Find the copilot-setup-steps job
job, exists := workflow.Jobs["copilot-setup-steps"]
if !exists {
return fmt.Errorf("copilot-setup-steps job not found in workflow")
}

// Insert the extension install step at the beginning
// Insert the extension install and verify steps at the beginning
insertPosition := 0

// Insert the step at the determined position
newSteps := make([]WorkflowStep, 0, len(job.Steps)+1)
// Insert both steps at the determined position
newSteps := make([]WorkflowStep, 0, len(job.Steps)+2)
newSteps = append(newSteps, job.Steps[:insertPosition]...)
newSteps = append(newSteps, extensionStep)
newSteps = append(newSteps, installStep)
newSteps = append(newSteps, verifyStep)
newSteps = append(newSteps, job.Steps[insertPosition:]...)

job.Steps = newSteps
Expand Down
29 changes: 20 additions & 9 deletions pkg/cli/copilot_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ func TestEnsureCopilotSetupSteps(t *testing.T) {
t.Fatalf("Expected job 'copilot-setup-steps' not found")
}

// Extension install should be injected at the beginning
if len(job.Steps) < 3 {
t.Fatalf("Expected at least 3 steps after injection, got %d", len(job.Steps))
// Extension install and verify steps should be injected at the beginning
if len(job.Steps) < 4 {
t.Fatalf("Expected at least 4 steps after injection (2 injected + 2 existing), got %d", len(job.Steps))
}

if job.Steps[0].Name != "Install gh-aw extension" {
t.Errorf("Expected first step to be 'Install gh-aw extension', got %q", job.Steps[0].Name)
}

if job.Steps[1].Name != "Verify gh-aw installation" {
t.Errorf("Expected second step to be 'Verify gh-aw installation', got %q", job.Steps[1].Name)
}
},
},
}
Expand Down Expand Up @@ -199,13 +203,17 @@ func TestInjectExtensionInstallStep(t *testing.T) {
},
},
wantErr: false,
expectedSteps: 3,
expectedSteps: 4, // 2 injected steps + 2 existing steps
validateFunc: func(t *testing.T, w *Workflow) {
steps := w.Jobs["copilot-setup-steps"].Steps
// Extension install should be at index 0 (beginning)
if steps[0].Name != "Install gh-aw extension" {
t.Errorf("Expected step 0 to be 'Install gh-aw extension', got %q", steps[0].Name)
}
// Verify step should be at index 1
if steps[1].Name != "Verify gh-aw installation" {
t.Errorf("Expected step 1 to be 'Verify gh-aw installation', got %q", steps[1].Name)
}
},
},
{
Expand All @@ -218,15 +226,18 @@ func TestInjectExtensionInstallStep(t *testing.T) {
},
},
wantErr: false,
expectedSteps: 1,
expectedSteps: 2, // 2 injected steps (install + verify)
validateFunc: func(t *testing.T, w *Workflow) {
steps := w.Jobs["copilot-setup-steps"].Steps
// Extension install should be the only step
if len(steps) != 1 {
t.Errorf("Expected 1 step, got %d", len(steps))
// Should have 2 steps
if len(steps) != 2 {
t.Errorf("Expected 2 steps, got %d", len(steps))
}
if steps[0].Name != "Install gh-aw extension" {
t.Errorf("Expected step to be 'Install gh-aw extension', got %q", steps[0].Name)
t.Errorf("Expected step 0 to be 'Install gh-aw extension', got %q", steps[0].Name)
}
if steps[1].Name != "Verify gh-aw installation" {
t.Errorf("Expected step 1 to be 'Verify gh-aw installation', got %q", steps[1].Name)
}
},
},
Expand Down
Loading