cleanupAllIncludes removes all include files when no workflows remain
(verbose bool)
| 365 | |
| 366 | // cleanupAllIncludes removes all include files when no workflows remain |
| 367 | func cleanupAllIncludes(verbose bool) error { |
| 368 | workflowsDir := constants.GetWorkflowDir() |
| 369 | |
| 370 | err := filepath.Walk(workflowsDir, func(path string, info os.FileInfo, err error) error { |
| 371 | if err != nil { |
| 372 | return err |
| 373 | } |
| 374 | |
| 375 | if !info.IsDir() && strings.HasSuffix(info.Name(), ".md") { |
| 376 | relPath, _ := filepath.Rel(workflowsDir, path) |
| 377 | |
| 378 | // Only remove files in subdirectories (like shared/) as these are include files |
| 379 | // Root-level .md files are workflow files, not include files |
| 380 | if strings.Contains(relPath, string(filepath.Separator)) { |
| 381 | if err := os.Remove(path); err != nil { |
| 382 | if verbose { |
| 383 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to remove include %s: %v", relPath, err))) |
| 384 | } |
| 385 | } else { |
| 386 | fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Removed include: "+relPath)) |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return nil |
| 392 | }) |
| 393 | |
| 394 | return err |
| 395 | } |
| 396 | |
| 397 | // findIncludesInContent finds all import references in content |
| 398 | func findIncludesInContent(content string) ([]string, error) { |
no test coverage detected