diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index 6853cc26d06..b1d2107b480 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -79,19 +79,23 @@ func (c *Compiler) CompileWorkflow(markdownPath string) error { // including expressions, features, permissions, and configurations. func (c *Compiler) validateWorkflowData(workflowData *WorkflowData, markdownPath string) error { // Validate expression safety - check that all GitHub Actions expressions are in the allowed list - log.Printf("Validating expression safety") - if err := validateExpressionSafety(workflowData.MarkdownContent); err != nil { - return formatCompilerError(markdownPath, "error", err.Error(), err) + if strings.Contains(workflowData.MarkdownContent, "${{") { + log.Printf("Validating expression safety") + if err := validateExpressionSafety(workflowData.MarkdownContent); err != nil { + return formatCompilerError(markdownPath, "error", err.Error(), err) + } } // Validate expressions in runtime-import files at compile time - log.Printf("Validating runtime-import files") - // Go up from .github/workflows/file.md to repo root - workflowDir := filepath.Dir(markdownPath) // .github/workflows - githubDir := filepath.Dir(workflowDir) // .github - workspaceDir := filepath.Dir(githubDir) // repo root - if err := validateRuntimeImportFiles(workflowData.MarkdownContent, workspaceDir); err != nil { - return formatCompilerError(markdownPath, "error", err.Error(), err) + if strings.Contains(workflowData.MarkdownContent, "{{#runtime-import") { + log.Printf("Validating runtime-import files") + // Go up from .github/workflows/file.md to repo root + workflowDir := filepath.Dir(markdownPath) // .github/workflows + githubDir := filepath.Dir(workflowDir) // .github + workspaceDir := filepath.Dir(githubDir) // repo root + if err := validateRuntimeImportFiles(workflowData.MarkdownContent, workspaceDir); err != nil { + return formatCompilerError(markdownPath, "error", err.Error(), err) + } } // Validate feature flags diff --git a/pkg/workflow/compiler_performance_benchmark_test.go b/pkg/workflow/compiler_performance_benchmark_test.go index 6bf07b5f3a6..b97a9a94d78 100644 --- a/pkg/workflow/compiler_performance_benchmark_test.go +++ b/pkg/workflow/compiler_performance_benchmark_test.go @@ -295,13 +295,22 @@ Test validation performance. compiler.SetStrictMode(true) compiler.SetQuiet(true) + workflowData, err := compiler.ParseWorkflowFile(testFile) + if err != nil { + b.Fatal(err) + } + // Warm up: run once before timing to prime one-time caches (schema compilation, etc.) - _ = compiler.CompileWorkflow(testFile) + if err := compiler.validateWorkflowData(workflowData, testFile); err != nil { + b.Fatal(err) + } b.ResetTimer() b.ReportAllocs() for b.Loop() { - _ = compiler.CompileWorkflow(testFile) + if err := compiler.validateWorkflowData(workflowData, testFile); err != nil { + b.Fatalf("validateWorkflowData failed: %v", err) + } } }