@@ -20,7 +20,7 @@ import (
2020var compileLog = logger .New ("cli:compile_command" )
2121
2222// CompileWorkflowWithValidation compiles a workflow with always-on YAML validation for CLI usage
23- func CompileWorkflowWithValidation (compiler * workflow.Compiler , filePath string , verbose bool , runZizmorPerFile bool , runPoutinePerFile bool , runActionlintPerFile bool , strict bool ) error {
23+ func CompileWorkflowWithValidation (compiler * workflow.Compiler , filePath string , verbose bool , runZizmorPerFile bool , runPoutinePerFile bool , runActionlintPerFile bool , strict bool , validateActionSHAs bool ) error {
2424 // Compile the workflow first
2525 if err := compiler .CompileWorkflow (filePath ); err != nil {
2626 return err
@@ -46,6 +46,24 @@ func CompileWorkflowWithValidation(compiler *workflow.Compiler, filePath string,
4646 return fmt .Errorf ("generated lock file is not valid YAML: %w" , err )
4747 }
4848
49+ // Validate action SHAs if requested
50+ if validateActionSHAs {
51+ compileLog .Print ("Validating action SHAs in lock file" )
52+ // Find git root for action cache
53+ gitRoot , err := findGitRoot ()
54+ if err != nil {
55+ compileLog .Printf ("Unable to find git root for action cache: %v" , err )
56+ // Continue without validation if we can't find git root
57+ } else {
58+ // Create action cache for validation
59+ actionCache := workflow .NewActionCache (gitRoot )
60+ if err := workflow .ValidateActionSHAsInLockFile (lockFile , actionCache , verbose ); err != nil {
61+ // Action SHA validation warnings are non-fatal
62+ compileLog .Printf ("Action SHA validation completed with warnings: %v" , err )
63+ }
64+ }
65+ }
66+
4967 // Run zizmor on the generated lock file if requested
5068 if runZizmorPerFile {
5169 if err := runZizmorOnFile (lockFile , verbose , strict ); err != nil {
@@ -72,7 +90,7 @@ func CompileWorkflowWithValidation(compiler *workflow.Compiler, filePath string,
7290
7391// CompileWorkflowDataWithValidation compiles from already-parsed WorkflowData with validation
7492// This avoids re-parsing when the workflow data has already been parsed
75- func CompileWorkflowDataWithValidation (compiler * workflow.Compiler , workflowData * workflow.WorkflowData , filePath string , verbose bool , runZizmorPerFile bool , runPoutinePerFile bool , runActionlintPerFile bool , strict bool ) error {
93+ func CompileWorkflowDataWithValidation (compiler * workflow.Compiler , workflowData * workflow.WorkflowData , filePath string , verbose bool , runZizmorPerFile bool , runPoutinePerFile bool , runActionlintPerFile bool , strict bool , validateActionSHAs bool ) error {
7694 // Compile the workflow using already-parsed data
7795 if err := compiler .CompileWorkflowData (workflowData , filePath ); err != nil {
7896 return err
@@ -98,6 +116,24 @@ func CompileWorkflowDataWithValidation(compiler *workflow.Compiler, workflowData
98116 return fmt .Errorf ("generated lock file is not valid YAML: %w" , err )
99117 }
100118
119+ // Validate action SHAs if requested
120+ if validateActionSHAs {
121+ compileLog .Print ("Validating action SHAs in lock file" )
122+ // Find git root for action cache
123+ gitRoot , err := findGitRoot ()
124+ if err != nil {
125+ compileLog .Printf ("Unable to find git root for action cache: %v" , err )
126+ // Continue without validation if we can't find git root
127+ } else {
128+ // Create action cache for validation
129+ actionCache := workflow .NewActionCache (gitRoot )
130+ if err := workflow .ValidateActionSHAsInLockFile (lockFile , actionCache , verbose ); err != nil {
131+ // Action SHA validation warnings are non-fatal
132+ compileLog .Printf ("Action SHA validation completed with warnings: %v" , err )
133+ }
134+ }
135+ }
136+
101137 // Run zizmor on the generated lock file if requested
102138 if runZizmorPerFile {
103139 if err := runZizmorOnFile (lockFile , verbose , strict ); err != nil {
@@ -281,7 +317,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
281317 workflowDataList = append (workflowDataList , workflowData )
282318
283319 compileLog .Printf ("Starting compilation of %s" , resolvedFile )
284- if err := CompileWorkflowDataWithValidation (compiler , workflowData , resolvedFile , verbose , zizmor && ! noEmit , poutine && ! noEmit , actionlint && ! noEmit , strict ); err != nil {
320+ if err := CompileWorkflowDataWithValidation (compiler , workflowData , resolvedFile , verbose , zizmor && ! noEmit , poutine && ! noEmit , actionlint && ! noEmit , strict , validate && ! noEmit ); err != nil {
285321 // Always put error on a new line and don't wrap with "failed to compile workflow"
286322 fmt .Fprintln (os .Stderr , err .Error ())
287323 errorMessages = append (errorMessages , err .Error ())
@@ -422,7 +458,7 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
422458 }
423459 workflowDataList = append (workflowDataList , workflowData )
424460
425- if err := CompileWorkflowDataWithValidation (compiler , workflowData , file , verbose , zizmor && ! noEmit , poutine && ! noEmit , actionlint && ! noEmit , strict ); err != nil {
461+ if err := CompileWorkflowDataWithValidation (compiler , workflowData , file , verbose , zizmor && ! noEmit , poutine && ! noEmit , actionlint && ! noEmit , strict , validate && ! noEmit ); err != nil {
426462 // Print the error to stderr (errors from CompileWorkflow are already formatted)
427463 fmt .Fprintln (os .Stderr , err .Error ())
428464 errorCount ++
@@ -610,7 +646,7 @@ func watchAndCompileWorkflows(markdownFile string, compiler *workflow.Compiler,
610646 if verbose {
611647 fmt .Fprintf (os .Stderr , "🔨 Initial compilation of %s...\n " , markdownFile )
612648 }
613- if err := CompileWorkflowWithValidation (compiler , markdownFile , verbose , false , false , false , false ); err != nil {
649+ if err := CompileWorkflowWithValidation (compiler , markdownFile , verbose , false , false , false , false , false ); err != nil {
614650 // Always show initial compilation errors on new line without wrapping
615651 fmt .Fprintln (os .Stderr , err .Error ())
616652 stats .Errors ++
@@ -722,7 +758,7 @@ func compileAllWorkflowFiles(compiler *workflow.Compiler, workflowsDir string, v
722758 if verbose {
723759 fmt .Printf ("🔨 Compiling: %s\n " , file )
724760 }
725- if err := CompileWorkflowWithValidation (compiler , file , verbose , false , false , false , false ); err != nil {
761+ if err := CompileWorkflowWithValidation (compiler , file , verbose , false , false , false , false , false ); err != nil {
726762 // Always show compilation errors on new line
727763 fmt .Fprintln (os .Stderr , err .Error ())
728764 stats .Errors ++
@@ -779,7 +815,7 @@ func compileModifiedFiles(compiler *workflow.Compiler, files []string, verbose b
779815 fmt .Fprintf (os .Stderr , "🔨 Compiling: %s\n " , file )
780816 }
781817
782- if err := CompileWorkflowWithValidation (compiler , file , verbose , false , false , false , false ); err != nil {
818+ if err := CompileWorkflowWithValidation (compiler , file , verbose , false , false , false , false , false ); err != nil {
783819 // Always show compilation errors on new line
784820 fmt .Fprintln (os .Stderr , err .Error ())
785821 stats .Errors ++
0 commit comments