@@ -10,11 +10,14 @@ import (
1010
1111 "github.com/githubnext/gh-aw/pkg/console"
1212 "github.com/githubnext/gh-aw/pkg/constants"
13+ "github.com/githubnext/gh-aw/pkg/logger"
1314 "github.com/githubnext/gh-aw/pkg/parser"
1415 "github.com/githubnext/gh-aw/pkg/workflow"
1516 "github.com/spf13/cobra"
1617)
1718
19+ var updateLog = logger .New ("cli:update_command" )
20+
1821// NewUpdateCommand creates the update command
1922func NewUpdateCommand (validateEngine func (string ) error ) * cobra.Command {
2023 cmd := & cobra.Command {
@@ -118,6 +121,8 @@ func checkExtensionUpdate(verbose bool) error {
118121// 2. Update workflows from source repositories (compiles each workflow after update)
119122// 3. Optionally create a PR
120123func UpdateWorkflowsWithExtensionCheck (workflowNames []string , allowMajor , force , verbose bool , engineOverride string , createPR bool , workflowsDir string , noStopAfter bool , stopAfter string ) error {
124+ updateLog .Printf ("Starting update process: workflows=%v, allowMajor=%v, force=%v, createPR=%v" , workflowNames , allowMajor , force , createPR )
125+
121126 // Step 1: Check for gh-aw extension updates
122127 if err := checkExtensionUpdate (verbose ); err != nil {
123128 return fmt .Errorf ("extension update check failed: %w" , err )
@@ -224,6 +229,8 @@ func createUpdatePR(verbose bool) error {
224229
225230// UpdateWorkflows updates workflows from their source repositories
226231func UpdateWorkflows (workflowNames []string , allowMajor , force , verbose bool , engineOverride string , workflowsDir string , noStopAfter bool , stopAfter string ) error {
232+ updateLog .Printf ("Scanning for workflows with source field: dir=%s, filter=%v" , workflowsDir , workflowNames )
233+
227234 // Use provided workflows directory or default
228235 if workflowsDir == "" {
229236 workflowsDir = getWorkflowsDir ()
@@ -235,6 +242,8 @@ func UpdateWorkflows(workflowNames []string, allowMajor, force, verbose bool, en
235242 return err
236243 }
237244
245+ updateLog .Printf ("Found %d workflows with source field" , len (workflows ))
246+
238247 if len (workflows ) == 0 {
239248 if len (workflowNames ) > 0 {
240249 return fmt .Errorf ("no workflows found matching the specified names with source field" )
@@ -394,12 +403,15 @@ func findWorkflowsWithSource(workflowsDir string, filterNames []string, verbose
394403
395404// resolveLatestRef resolves the latest ref for a workflow source
396405func resolveLatestRef (repo , currentRef string , allowMajor , verbose bool ) (string , error ) {
406+ updateLog .Printf ("Resolving latest ref: repo=%s, currentRef=%s, allowMajor=%v" , repo , currentRef , allowMajor )
407+
397408 if verbose {
398409 fmt .Fprintln (os .Stderr , console .FormatVerboseMessage (fmt .Sprintf ("Resolving latest ref for %s (current: %s)" , repo , currentRef )))
399410 }
400411
401412 // Check if current ref is a tag (looks like a semantic version)
402413 if isSemanticVersionTag (currentRef ) {
414+ updateLog .Print ("Current ref is semantic version tag, resolving latest release" )
403415 return resolveLatestRelease (repo , currentRef , allowMajor , verbose )
404416 }
405417
@@ -414,10 +426,12 @@ func resolveLatestRef(repo, currentRef string, allowMajor, verbose bool) (string
414426 }
415427
416428 if isBranch {
429+ updateLog .Printf ("Current ref is branch: %s" , currentRef )
417430 return resolveBranchHead (repo , currentRef , verbose )
418431 }
419432
420433 // Otherwise, use default branch
434+ updateLog .Print ("Using default branch for ref resolution" )
421435 return resolveDefaultBranchHead (repo , verbose )
422436}
423437
@@ -546,6 +560,8 @@ func resolveDefaultBranchHead(repo string, verbose bool) (string, error) {
546560
547561// updateWorkflow updates a single workflow from its source
548562func updateWorkflow (wf * workflowWithSource , allowMajor , force , verbose bool , engineOverride string , noStopAfter bool , stopAfter string ) error {
563+ updateLog .Printf ("Updating workflow: name=%s, source=%s, force=%v" , wf .Name , wf .SourceSpec , force )
564+
549565 if verbose {
550566 fmt .Fprintln (os .Stderr , console .FormatInfoMessage (fmt .Sprintf ("\n Updating workflow: %s" , wf .Name )))
551567 fmt .Fprintln (os .Stderr , console .FormatVerboseMessage (fmt .Sprintf ("Source: %s" , wf .SourceSpec )))
@@ -554,6 +570,7 @@ func updateWorkflow(wf *workflowWithSource, allowMajor, force, verbose bool, eng
554570 // Parse source spec
555571 sourceSpec , err := parseSourceSpec (wf .SourceSpec )
556572 if err != nil {
573+ updateLog .Printf ("Failed to parse source spec: %v" , err )
557574 return fmt .Errorf ("failed to parse source spec: %w" , err )
558575 }
559576
@@ -576,6 +593,8 @@ func updateWorkflow(wf *workflowWithSource, allowMajor, force, verbose bool, eng
576593
577594 // Check if update is needed
578595 if ! force && currentRef == latestRef {
596+ updateLog .Printf ("Workflow already at latest ref: %s, checking for local modifications" , currentRef )
597+
579598 // Download the source content to check if local file has been modified
580599 sourceContent , err := downloadWorkflowContent (sourceSpec .Repo , sourceSpec .Path , currentRef , verbose )
581600 if err != nil {
@@ -595,11 +614,13 @@ func updateWorkflow(wf *workflowWithSource, allowMajor, force, verbose bool, eng
595614
596615 // Check if local file differs from source
597616 if hasLocalModifications (string (sourceContent ), string (currentContent ), wf .SourceSpec , verbose ) {
617+ updateLog .Printf ("Local modifications detected in workflow: %s" , wf .Name )
598618 fmt .Fprintln (os .Stderr , console .FormatInfoMessage (fmt .Sprintf ("Workflow %s is already up to date (%s)" , wf .Name , currentRef )))
599619 fmt .Fprintln (os .Stderr , console .FormatWarningMessage (fmt .Sprintf ("⚠️ Local copy of %s has been modified from source" , wf .Name )))
600620 return nil
601621 }
602622
623+ updateLog .Printf ("Workflow %s is up to date with no local modifications" , wf .Name )
603624 fmt .Fprintln (os .Stderr , console .FormatInfoMessage (fmt .Sprintf ("Workflow %s is already up to date (%s)" , wf .Name , currentRef )))
604625 return nil
605626 }
@@ -631,11 +652,17 @@ func updateWorkflow(wf *workflowWithSource, allowMajor, force, verbose bool, eng
631652 }
632653
633654 // Perform 3-way merge using git merge-file
655+ updateLog .Printf ("Performing 3-way merge for workflow: %s" , wf .Name )
634656 mergedContent , hasConflicts , err := MergeWorkflowContent (string (baseContent ), string (currentContent ), string (newContent ), wf .SourceSpec , latestRef , verbose )
635657 if err != nil {
658+ updateLog .Printf ("Merge failed for workflow %s: %v" , wf .Name , err )
636659 return fmt .Errorf ("failed to merge workflow content: %w" , err )
637660 }
638661
662+ if hasConflicts {
663+ updateLog .Printf ("Merge conflicts detected in workflow: %s" , wf .Name )
664+ }
665+
639666 // Handle stop-after field modifications
640667 if noStopAfter {
641668 // Remove stop-after field if requested
@@ -675,10 +702,13 @@ func updateWorkflow(wf *workflowWithSource, allowMajor, force, verbose bool, eng
675702 return nil // Not an error, but user needs to resolve conflicts
676703 }
677704
705+ updateLog .Printf ("Successfully updated workflow %s from %s to %s" , wf .Name , currentRef , latestRef )
678706 fmt .Fprintln (os .Stderr , console .FormatSuccessMessage (fmt .Sprintf ("Updated %s from %s to %s" , wf .Name , currentRef , latestRef )))
679707
680708 // Compile the updated workflow with refreshStopTime enabled
709+ updateLog .Printf ("Compiling updated workflow: %s" , wf .Name )
681710 if err := compileWorkflowWithRefresh (wf .Path , verbose , engineOverride , true ); err != nil {
711+ updateLog .Printf ("Compilation failed for workflow %s: %v" , wf .Name , err )
682712 return fmt .Errorf ("failed to compile updated workflow: %w" , err )
683713 }
684714
0 commit comments