Skip to content

Commit 339e55f

Browse files
authored
[WIP] Update workflows and recompile scripts after update (#3929)
1 parent 57b6619 commit 339e55f

2 files changed

Lines changed: 103 additions & 42 deletions

File tree

pkg/cli/update_command.go

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/githubnext/gh-aw/pkg/console"
1212
"github.com/githubnext/gh-aw/pkg/constants"
1313
"github.com/githubnext/gh-aw/pkg/parser"
14-
"github.com/githubnext/gh-aw/pkg/workflow"
1514
"github.com/spf13/cobra"
1615
)
1716

@@ -25,7 +24,7 @@ func NewUpdateCommand(validateEngine func(string) error) *cobra.Command {
2524
The command:
2625
1. Checks if a newer version of gh-aw is available
2726
2. Updates workflows using the 'source' field in the workflow frontmatter
28-
3. Recompiles all workflows
27+
3. Compiles each workflow immediately after update
2928
3029
For workflow updates, it fetches the latest version based on the current ref:
3130
- If the ref is a tag, it updates to the latest release (use --major for major version updates)
@@ -109,54 +108,23 @@ func checkExtensionUpdate(verbose bool) error {
109108
return nil
110109
}
111110

112-
// runCompileWorkflows runs the compile command to recompile all workflows
113-
func runCompileWorkflows(verbose bool, engineOverride string, workflowsDir string) error {
114-
if verbose {
115-
fmt.Fprintln(os.Stderr, console.FormatVerboseMessage("Compiling workflows..."))
116-
}
117-
118-
// Create a compiler instance similar to how compile command does it
119-
compiler := workflow.NewCompiler(verbose, engineOverride, GetVersion())
120-
121-
// Use provided workflows directory or default
122-
if workflowsDir == "" {
123-
workflowsDir = getWorkflowsDir()
124-
}
125-
126-
// Compile all workflows in the workflows directory
127-
_, err := compileAllWorkflowFiles(compiler, workflowsDir, verbose)
128-
if err != nil {
129-
return fmt.Errorf("failed to compile workflows: %w", err)
130-
}
131-
132-
if verbose {
133-
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Successfully compiled all workflows"))
134-
}
135-
return nil
136-
}
137-
138111
// UpdateWorkflowsWithExtensionCheck performs the complete update process:
139112
// 1. Check for gh-aw extension updates
140-
// 2. Update workflows from source repositories
141-
// 3. Compile all workflows
142-
// 4. Optionally create a PR
113+
// 2. Update workflows from source repositories (compiles each workflow after update)
114+
// 3. Optionally create a PR
143115
func UpdateWorkflowsWithExtensionCheck(workflowNames []string, allowMajor, force, verbose bool, engineOverride string, createPR bool, workflowsDir string) error {
144116
// Step 1: Check for gh-aw extension updates
145117
if err := checkExtensionUpdate(verbose); err != nil {
146118
return fmt.Errorf("extension update check failed: %w", err)
147119
}
148120

149121
// Step 2: Update workflows from source repositories
122+
// Note: Each workflow is compiled immediately after update
150123
if err := UpdateWorkflows(workflowNames, allowMajor, force, verbose, engineOverride, workflowsDir); err != nil {
151124
return fmt.Errorf("workflow update failed: %w", err)
152125
}
153126

154-
// Step 3: Compile all workflows
155-
if err := runCompileWorkflows(verbose, engineOverride, workflowsDir); err != nil {
156-
return fmt.Errorf("compile failed: %w", err)
157-
}
158-
159-
// Step 4: Optionally create PR if flag is set
127+
// Step 3: Optionally create PR if flag is set
160128
if createPR {
161129
if err := createUpdatePR(verbose); err != nil {
162130
return fmt.Errorf("failed to create PR: %w", err)
@@ -271,21 +239,29 @@ func UpdateWorkflows(workflowNames []string, allowMajor, force, verbose bool, en
271239

272240
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Found %d workflow(s) to update", len(workflows))))
273241

242+
// Track update results
243+
var successfulUpdates []string
244+
var failedUpdates []updateFailure
245+
274246
// Update each workflow
275-
updatedCount := 0
276247
for _, wf := range workflows {
277248
if err := updateWorkflow(wf, allowMajor, force, verbose, engineOverride); err != nil {
278-
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to update %s: %v", wf.Name, err)))
249+
failedUpdates = append(failedUpdates, updateFailure{
250+
Name: wf.Name,
251+
Error: err.Error(),
252+
})
279253
continue
280254
}
281-
updatedCount++
255+
successfulUpdates = append(successfulUpdates, wf.Name)
282256
}
283257

284-
if updatedCount == 0 {
258+
// Show summary
259+
showUpdateSummary(successfulUpdates, failedUpdates)
260+
261+
if len(successfulUpdates) == 0 {
285262
return fmt.Errorf("no workflows were successfully updated")
286263
}
287264

288-
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Successfully updated %d workflow(s)", updatedCount)))
289265
return nil
290266
}
291267

@@ -296,6 +272,37 @@ type workflowWithSource struct {
296272
SourceSpec string // e.g., "owner/repo/path@ref"
297273
}
298274

275+
// updateFailure represents a failed workflow update
276+
type updateFailure struct {
277+
Name string
278+
Error string
279+
}
280+
281+
// showUpdateSummary displays a summary of workflow updates using console helpers
282+
func showUpdateSummary(successfulUpdates []string, failedUpdates []updateFailure) {
283+
fmt.Fprintln(os.Stderr, "")
284+
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("=== Update Summary ==="))
285+
fmt.Fprintln(os.Stderr, "")
286+
287+
// Show successful updates
288+
if len(successfulUpdates) > 0 {
289+
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Successfully updated and compiled %d workflow(s):", len(successfulUpdates))))
290+
for _, name := range successfulUpdates {
291+
fmt.Fprintf(os.Stderr, " ✓ %s\n", name)
292+
}
293+
fmt.Fprintln(os.Stderr, "")
294+
}
295+
296+
// Show failed updates
297+
if len(failedUpdates) > 0 {
298+
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(fmt.Sprintf("Failed to update %d workflow(s):", len(failedUpdates))))
299+
for _, failure := range failedUpdates {
300+
fmt.Fprintf(os.Stderr, " ✗ %s: %s\n", failure.Name, failure.Error)
301+
}
302+
fmt.Fprintln(os.Stderr, "")
303+
}
304+
}
305+
299306
// findWorkflowsWithSource finds all workflows that have a source field
300307
func findWorkflowsWithSource(workflowsDir string, filterNames []string, verbose bool) ([]*workflowWithSource, error) {
301308
var workflows []*workflowWithSource

pkg/cli/update_command_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,57 @@ Test content.`
457457
t.Errorf("Expected workflow path to contain custom directory '%s', got '%s'", customWorkflowDir, workflows[0].Path)
458458
}
459459
}
460+
461+
// TestShowUpdateSummary tests the update summary display
462+
func TestShowUpdateSummary(t *testing.T) {
463+
tests := []struct {
464+
name string
465+
successfulUpdates []string
466+
failedUpdates []updateFailure
467+
wantSuccess bool
468+
wantFailed bool
469+
}{
470+
{
471+
name: "all successful",
472+
successfulUpdates: []string{"workflow1", "workflow2", "workflow3"},
473+
failedUpdates: []updateFailure{},
474+
wantSuccess: true,
475+
wantFailed: false,
476+
},
477+
{
478+
name: "all failed",
479+
successfulUpdates: []string{},
480+
failedUpdates: []updateFailure{
481+
{Name: "workflow1", Error: "failed to download"},
482+
{Name: "workflow2", Error: "merge conflict"},
483+
},
484+
wantSuccess: false,
485+
wantFailed: true,
486+
},
487+
{
488+
name: "mixed results",
489+
successfulUpdates: []string{"workflow1", "workflow3"},
490+
failedUpdates: []updateFailure{
491+
{Name: "workflow2", Error: "failed to compile"},
492+
},
493+
wantSuccess: true,
494+
wantFailed: true,
495+
},
496+
{
497+
name: "empty results",
498+
successfulUpdates: []string{},
499+
failedUpdates: []updateFailure{},
500+
wantSuccess: false,
501+
wantFailed: false,
502+
},
503+
}
504+
505+
for _, tt := range tests {
506+
t.Run(tt.name, func(t *testing.T) {
507+
// This test just verifies the function doesn't panic and can be called
508+
// We don't check the exact output format since it uses console helpers
509+
// and the exact formatting may change
510+
showUpdateSummary(tt.successfulUpdates, tt.failedUpdates)
511+
})
512+
}
513+
}

0 commit comments

Comments
 (0)