MCPcopy Create free account
hub / github.com/github/gh-aw / validateExpressions

Method validateExpressions

pkg/workflow/compiler_validators.go:18–52  ·  view source on GitHub ↗

validateExpressions checks expression safety and runtime-import file references embedded in the workflow's markdown content. It is the first validator called in validateWorkflowData and guards against unsafe GitHub Actions expressions.

(workflowData *WorkflowData, markdownPath string)

Source from the content-addressed store, hash-verified

16// embedded in the workflow's markdown content. It is the first validator called in
17// validateWorkflowData and guards against unsafe GitHub Actions expressions.
18func (c *Compiler) validateExpressions(workflowData *WorkflowData, markdownPath string) error {
19 // Validate expression safety - check that all GitHub Actions expressions are in the allowed list
20 if strings.Contains(workflowData.MarkdownContent, "${{") {
21 workflowLog.Printf("Validating expression safety")
22 if err := validateExpressionSafety(workflowData.MarkdownContent); err != nil {
23 return formatCompilerError(markdownPath, "error", err.Error(), err)
24 }
25 }
26
27 // Validate expressions in runtime-import files at compile time
28 if strings.Contains(workflowData.MarkdownContent, "{{#runtime-import") {
29 workflowLog.Printf("Validating runtime-import files")
30 // Go up from .github/workflows/file.md to repo root
31 workflowDir := filepath.Dir(markdownPath) // .github/workflows
32 githubDir := filepath.Dir(workflowDir) // .github
33 workspaceDir := filepath.Dir(githubDir) // repo root
34 subAgentWarnings, err := validateRuntimeImportFiles(workflowData.MarkdownContent, workspaceDir)
35 // Emit best-effort sub-agent frontmatter warnings through the normal warning path
36 // so they are counted and consistently formatted with all other warnings.
37 for _, w := range subAgentWarnings {
38 expressionValidationLog.Printf("%s", w)
39 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(w))
40 c.IncrementWarningCount()
41 }
42 if err != nil {
43 return formatCompilerError(markdownPath, "error", err.Error(), err)
44 }
45 }
46
47 // Warn when the prompt explicitly references /tmp/ or /tmp/gh-aw/ directly instead
48 // of the recommended /tmp/gh-aw/agent/ subtree.
49 c.validatePromptTmpPaths(workflowData, markdownPath)
50
51 return nil
52}
53
54// tmpNeedle is the literal prefix to scan for in prompt content.
55const tmpNeedle = "/tmp/"

Callers 2

TestValidateExpressionsFunction · 0.95
validateWorkflowDataMethod · 0.95

Calls 8

IncrementWarningCountMethod · 0.95
FormatWarningMessageFunction · 0.92
validateExpressionSafetyFunction · 0.85
formatCompilerErrorFunction · 0.85
PrintfMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestValidateExpressionsFunction · 0.76