cancelWorkflowRunsByLockFile cancels in-progress runs for a workflow identified by its lock file name
(lockFileName string)
| 60 | |
| 61 | // cancelWorkflowRunsByLockFile cancels in-progress runs for a workflow identified by its lock file name |
| 62 | func cancelWorkflowRunsByLockFile(lockFileName string) error { |
| 63 | cancelLog.Printf("Cancelling workflow runs for lock file: %s", lockFileName) |
| 64 | |
| 65 | // Start spinner for network operation |
| 66 | spinner := console.NewSpinner("Cancelling workflow runs...") |
| 67 | spinner.Start() |
| 68 | |
| 69 | // Get running workflow runs by lock file name |
| 70 | cmd := workflow.ExecGH("run", "list", "--workflow", lockFileName, "--status", "in_progress", "--json", "databaseId") |
| 71 | output, err := cmd.Output() |
| 72 | if err != nil { |
| 73 | cancelLog.Printf("Failed to list workflow runs by lock file: %v", err) |
| 74 | spinner.Stop() |
| 75 | return err |
| 76 | } |
| 77 | |
| 78 | var runs []struct { |
| 79 | DatabaseID int64 `json:"databaseId"` |
| 80 | } |
| 81 | if err := json.Unmarshal(output, &runs); err != nil { |
| 82 | cancelLog.Printf("Failed to parse workflow runs JSON: %v", err) |
| 83 | spinner.Stop() |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | cancelLog.Printf("Found %d in-progress workflow runs to cancel", len(runs)) |
| 88 | |
| 89 | // Cancel each running workflow |
| 90 | totalRuns := len(runs) |
| 91 | for i, run := range runs { |
| 92 | cancelLog.Printf("Cancelling workflow run: %d", run.DatabaseID) |
| 93 | cancelCmd := workflow.ExecGH("run", "cancel", strconv.FormatInt(run.DatabaseID, 10)) |
| 94 | _ = cancelCmd.Run() // Ignore errors for individual cancellations |
| 95 | // Update spinner with progress after cancellation completes |
| 96 | spinner.UpdateMessage(fmt.Sprintf("Cancelling workflow runs... (%d/%d completed)", i+1, totalRuns)) |
| 97 | } |
| 98 | |
| 99 | if len(runs) > 0 { |
| 100 | spinner.StopWithMessage(fmt.Sprintf("✓ Cancelled %d workflow runs", len(runs))) |
| 101 | } else { |
| 102 | spinner.StopWithMessage("✓ No in-progress workflow runs to cancel") |
| 103 | } |
| 104 | cancelLog.Print("Workflow run cancellation completed") |
| 105 | return nil |
| 106 | } |
no test coverage detected