toggleWorkflowsByNames toggles workflows by specific names, or all if no names provided
(ctx context.Context, workflowNames []string, enable bool, repoOverride string)
| 35 | |
| 36 | // toggleWorkflowsByNames toggles workflows by specific names, or all if no names provided |
| 37 | func toggleWorkflowsByNames(ctx context.Context, workflowNames []string, enable bool, repoOverride string) error { |
| 38 | action := "enable" |
| 39 | if !enable { |
| 40 | action = "disable" |
| 41 | } |
| 42 | |
| 43 | enableLog.Printf("Toggle workflows: action=%s, count=%d, repo=%s", action, len(workflowNames), repoOverride) |
| 44 | |
| 45 | // If no specific workflow names provided, enable/disable all workflows |
| 46 | if len(workflowNames) == 0 { |
| 47 | enableLog.Print("No specific workflows provided, processing all workflows") |
| 48 | fmt.Fprintf(os.Stderr, "No specific workflows provided. %sing all workflows...\n", strings.ToUpper(action[:1])+action[1:]) |
| 49 | // Get all workflow names and process them |
| 50 | mdFiles, err := getMarkdownWorkflowFiles("") |
| 51 | if err != nil { |
| 52 | return fmt.Errorf("no workflow files found to %s: %w", action, err) |
| 53 | } |
| 54 | |
| 55 | if len(mdFiles) == 0 { |
| 56 | return fmt.Errorf("no markdown workflow files found to %s", action) |
| 57 | } |
| 58 | |
| 59 | // Extract all workflow names |
| 60 | var allWorkflowNames []string |
| 61 | for _, file := range mdFiles { |
| 62 | base := filepath.Base(file) |
| 63 | name := normalizeWorkflowID(base) |
| 64 | allWorkflowNames = append(allWorkflowNames, name) |
| 65 | } |
| 66 | |
| 67 | // Recursively call with all workflow names |
| 68 | return toggleWorkflowsByNames(ctx, allWorkflowNames, enable, repoOverride) |
| 69 | } |
| 70 | |
| 71 | // Check if gh CLI is available |
| 72 | if !isGHCLIAvailable() { |
| 73 | return errors.New("GitHub CLI (gh) is required but not available") |
| 74 | } |
| 75 | |
| 76 | // Get the core set of workflows from markdown files in .github/workflows |
| 77 | mdFiles, err := getMarkdownWorkflowFiles("") |
| 78 | if err != nil { |
| 79 | return fmt.Errorf("no workflow files found to %s: %w", action, err) |
| 80 | } |
| 81 | |
| 82 | // Get GitHub workflows status for comparison; warn but continue if unavailable |
| 83 | enableLog.Print("Fetching GitHub workflows status for comparison") |
| 84 | githubWorkflows, err := fetchGitHubWorkflows(repoOverride, false) |
| 85 | if err != nil { |
| 86 | enableLog.Printf("Failed to fetch GitHub workflows: %v", err) |
| 87 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Unable to fetch GitHub workflows (gh CLI may not be authenticated): %v", err))) |
| 88 | githubWorkflows = make(map[string]*GitHubWorkflow) |
| 89 | } |
| 90 | enableLog.Printf("Retrieved %d GitHub workflows from remote", len(githubWorkflows)) |
| 91 | |
| 92 | // Internal target model to support enabling by ID or lock filename |
| 93 | type workflowTarget struct { |
| 94 | Name string |
no test coverage detected