UpdateWorkflows updates workflows from their source repositories
(ctx context.Context, opts UpdateWorkflowsOptions)
| 72 | |
| 73 | // UpdateWorkflows updates workflows from their source repositories |
| 74 | func UpdateWorkflows(ctx context.Context, opts UpdateWorkflowsOptions) error { |
| 75 | clearUpdateResolutionCaches() |
| 76 | updateLog.Printf("Scanning for workflows with source field: dir=%s, filter=%v, noMerge=%v, noCompile=%v, noRedirect=%v, disableSecurityScanner=%v, coolDown=%v", opts.WorkflowsDir, opts.WorkflowNames, opts.NoMerge, opts.NoCompile, opts.NoRedirect, opts.DisableSecurityScanner, opts.CoolDown) |
| 77 | |
| 78 | // Use provided workflows directory or default |
| 79 | workflowsDir := opts.WorkflowsDir |
| 80 | if workflowsDir == "" { |
| 81 | workflowsDir = getWorkflowsDir() |
| 82 | } |
| 83 | |
| 84 | // Find all workflows with source field |
| 85 | workflows, err := findWorkflowsWithSource(workflowsDir, opts.WorkflowNames, opts.Verbose) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | updateLog.Printf("Found %d workflows with source field", len(workflows)) |
| 91 | |
| 92 | if len(workflows) == 0 { |
| 93 | if len(opts.WorkflowNames) > 0 { |
| 94 | return errors.New("no workflows found matching the specified names with source field") |
| 95 | } |
| 96 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("no workflows found with source field")) |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Found %d workflow(s) to update", len(workflows)))) |
| 101 | |
| 102 | // Track update results |
| 103 | var successfulUpdates []string |
| 104 | var failedUpdates []updateFailure |
| 105 | |
| 106 | manifestGroups := make(map[string][]*workflowWithSource) |
| 107 | var directWorkflows []*workflowWithSource |
| 108 | for _, wf := range workflows { |
| 109 | if _, ok, err := parseManifestSourceSpec(wf.SourceSpec); err != nil { |
| 110 | failedUpdates = append(failedUpdates, updateFailure{ |
| 111 | Name: wf.Name, |
| 112 | Error: err.Error(), |
| 113 | }) |
| 114 | continue |
| 115 | } else if ok { |
| 116 | manifestGroups[strings.TrimSpace(wf.SourceSpec)] = append(manifestGroups[strings.TrimSpace(wf.SourceSpec)], wf) |
| 117 | continue |
| 118 | } |
| 119 | directWorkflows = append(directWorkflows, wf) |
| 120 | } |
| 121 | |
| 122 | // Update each workflow |
| 123 | for _, wf := range directWorkflows { |
| 124 | updateLog.Printf("Updating workflow: %s (source: %s)", wf.Name, wf.SourceSpec) |
| 125 | if err := updateWorkflow(ctx, wf, opts); err != nil { |
| 126 | updateLog.Printf("Failed to update workflow %s: %v", wf.Name, err) |
| 127 | failedUpdates = append(failedUpdates, updateFailure{ |
| 128 | Name: wf.Name, |
| 129 | Error: err.Error(), |
| 130 | }) |
| 131 | continue |
no test coverage detected