compileWorkflowWithTrackingAndRefresh compiles a workflow, tracks generated files, and optionally refreshes stop time. This function ensures that the file tracker records all files created or modified during compilation.
(ctx context.Context, filePath string, verbose bool, quiet bool, engineOverride string, tracker *FileTracker, refreshStopTime bool)
| 64 | // compileWorkflowWithTrackingAndRefresh compiles a workflow, tracks generated files, and optionally refreshes stop time. |
| 65 | // This function ensures that the file tracker records all files created or modified during compilation. |
| 66 | func compileWorkflowWithTrackingAndRefresh(ctx context.Context, filePath string, verbose bool, quiet bool, engineOverride string, tracker *FileTracker, refreshStopTime bool) error { |
| 67 | addWorkflowCompilationLog.Printf("Compiling workflow with tracking: file=%s, refresh_stop_time=%v", filePath, refreshStopTime) |
| 68 | |
| 69 | // Generate the expected lock file path |
| 70 | lockFile := stringutil.MarkdownToLockFile(filePath) |
| 71 | |
| 72 | // Check if lock file exists before compilation |
| 73 | lockFileExists := fileutil.FileExists(lockFile) |
| 74 | |
| 75 | addWorkflowCompilationLog.Printf("Lock file %s exists: %v", lockFile, lockFileExists) |
| 76 | |
| 77 | // Check if .gitattributes exists before compilation so we know whether to |
| 78 | // use TrackCreated or TrackModified if ensureGitAttributes modifies it later. |
| 79 | gitRoot, gitRootErr := gitutil.FindGitRoot() |
| 80 | gitAttributesPath := "" |
| 81 | gitAttributesExisted := false |
| 82 | if gitRootErr == nil { |
| 83 | gitAttributesPath = filepath.Join(gitRoot, ".gitattributes") |
| 84 | gitAttributesExisted = fileutil.FileExists(gitAttributesPath) |
| 85 | } |
| 86 | |
| 87 | // Track the lock file before compilation |
| 88 | if lockFileExists { |
| 89 | tracker.TrackModified(lockFile) |
| 90 | } else { |
| 91 | tracker.TrackCreated(lockFile) |
| 92 | } |
| 93 | |
| 94 | // Create compiler with auto-detected version and action mode |
| 95 | compiler := workflow.NewCompiler( |
| 96 | workflow.WithVerbose(verbose), |
| 97 | workflow.WithEngineOverride(engineOverride), |
| 98 | ) |
| 99 | compiler.SetFileTracker(tracker) |
| 100 | compiler.SetRefreshStopTime(refreshStopTime) |
| 101 | compiler.SetQuiet(quiet) |
| 102 | if err := CompileWorkflowWithValidation(ctx, compiler, filePath, CompileValidationOptions{Verbose: verbose}); err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | // Ensure .gitattributes marks .lock.yml files as generated; only track it if it was actually |
| 107 | // modified. Errors here are non-fatal — gitattributes update failure does not prevent the |
| 108 | // compiled workflow from being usable. |
| 109 | if updated, err := ensureGitAttributes(); err != nil { |
| 110 | if verbose { |
| 111 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to update .gitattributes: %v", err))) |
| 112 | } |
| 113 | } else if updated && gitRootErr == nil { |
| 114 | if gitAttributesExisted { |
| 115 | tracker.TrackModified(gitAttributesPath) |
| 116 | } else { |
| 117 | tracker.TrackCreated(gitAttributesPath) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return nil |
| 122 | } |
| 123 |
no test coverage detected