fetchAllRemoteDependencies fetches all remote dependencies for a workflow: includes (@include directives), frontmatter imports, dispatch workflows, and resources. This is the single entry point shared by both the add and trial commands. Error handling is intentionally asymmetric: - @include and fro
(ctx context.Context, content string, spec *WorkflowSpec, targetDir string, verbose bool, force bool, tracker *FileTracker)
| 521 | // verbose is true but do not stop the overall operation. |
| 522 | // - Dispatch-workflow and resource errors are fatal and are returned to the caller. |
| 523 | func fetchAllRemoteDependencies(ctx context.Context, content string, spec *WorkflowSpec, targetDir string, verbose bool, force bool, tracker *FileTracker) error { |
| 524 | remoteWorkflowLog.Printf("Fetching all remote dependencies: spec=%s, targetDir=%s, force=%v", spec.String(), targetDir, force) |
| 525 | // Fetch and save @include directive dependencies (best-effort: errors are not fatal). |
| 526 | if err := fetchAndSaveRemoteIncludes(content, spec, targetDir, verbose, force, tracker); err != nil { |
| 527 | if verbose { |
| 528 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch include dependencies: %v", err))) |
| 529 | } |
| 530 | } |
| 531 | // Fetch and save frontmatter 'imports:' dependencies so they are available |
| 532 | // locally during compilation. Keeping these as relative paths (not workflowspecs) |
| 533 | // ensures the compiler resolves them from disk rather than downloading from GitHub. |
| 534 | // Best-effort: errors are not fatal. |
| 535 | if err := fetchAndSaveRemoteFrontmatterImports(content, spec, targetDir, verbose, force, tracker); err != nil { |
| 536 | if verbose { |
| 537 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch frontmatter import dependencies: %v", err))) |
| 538 | } |
| 539 | } |
| 540 | // Fetch and save workflows referenced in safe-outputs.dispatch-workflow so they are |
| 541 | // available locally. Workflow names using GitHub Actions expression syntax are skipped. |
| 542 | if err := fetchAndSaveRemoteDispatchWorkflows(ctx, content, spec, targetDir, verbose, force, tracker); err != nil { |
| 543 | if verbose { |
| 544 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch dispatch workflow dependencies: %v", err))) |
| 545 | } |
| 546 | return fmt.Errorf("failed to fetch dispatch workflow dependencies: %w", err) |
| 547 | } |
| 548 | // Fetch files listed in the 'resources:' frontmatter field (additional workflow or |
| 549 | // action files that should be present alongside this workflow). |
| 550 | if err := fetchAndSaveRemoteResources(content, spec, targetDir, verbose, force, tracker); err != nil { |
| 551 | if verbose { |
| 552 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch resource dependencies: %v", err))) |
| 553 | } |
| 554 | return fmt.Errorf("failed to fetch resource dependencies: %w", err) |
| 555 | } |
| 556 | return nil |
| 557 | } |