@@ -49,6 +49,37 @@ func CompileWorkflowWithValidation(compiler *workflow.Compiler, filePath string,
4949 return nil
5050}
5151
52+ // CompileWorkflowDataWithValidation compiles from already-parsed WorkflowData with validation
53+ // This avoids re-parsing when the workflow data has already been parsed
54+ func CompileWorkflowDataWithValidation (compiler * workflow.Compiler , workflowData * workflow.WorkflowData , filePath string , verbose bool ) error {
55+ // Compile the workflow using already-parsed data
56+ if err := compiler .CompileWorkflowData (workflowData , filePath ); err != nil {
57+ return err
58+ }
59+
60+ // Always validate that the generated lock file is valid YAML (CLI requirement)
61+ lockFile := strings .TrimSuffix (filePath , ".md" ) + ".lock.yml"
62+ if _ , err := os .Stat (lockFile ); err != nil {
63+ // Lock file doesn't exist (likely due to no-emit), skip YAML validation
64+ return nil
65+ }
66+
67+ compileLog .Print ("Validating generated lock file YAML syntax" )
68+
69+ lockContent , err := os .ReadFile (lockFile )
70+ if err != nil {
71+ return fmt .Errorf ("failed to read generated lock file for validation: %w" , err )
72+ }
73+
74+ // Validate the lock file is valid YAML
75+ var yamlValidationTest any
76+ if err := yaml .Unmarshal (lockContent , & yamlValidationTest ); err != nil {
77+ return fmt .Errorf ("generated lock file is not valid YAML: %w" , err )
78+ }
79+
80+ return nil
81+ }
82+
5283// CompileConfig holds configuration options for compiling workflows
5384type CompileConfig struct {
5485 MarkdownFiles []string // Files to compile (empty for all files)
@@ -202,7 +233,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
202233 workflowDataList = append (workflowDataList , workflowData )
203234
204235 compileLog .Printf ("Starting compilation of %s" , resolvedFile )
205- if err := CompileWorkflowWithValidation (compiler , resolvedFile , verbose ); err != nil {
236+ if err := CompileWorkflowDataWithValidation (compiler , workflowData , resolvedFile , verbose ); err != nil {
206237 // Always put error on a new line and don't wrap with "failed to compile workflow"
207238 fmt .Fprintln (os .Stderr , err .Error ())
208239 errorMessages = append (errorMessages , err .Error ())
@@ -343,7 +374,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
343374 }
344375 workflowDataList = append (workflowDataList , workflowData )
345376
346- if err := CompileWorkflowWithValidation (compiler , file , verbose ); err != nil {
377+ if err := CompileWorkflowDataWithValidation (compiler , workflowData , file , verbose ); err != nil {
347378 // Print the error to stderr (errors from CompileWorkflow are already formatted)
348379 fmt .Fprintln (os .Stderr , err .Error ())
349380 errorCount ++
0 commit comments