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

Method validateExpressionSizes

pkg/workflow/runtime_validation.go:64–105  ·  view source on GitHub ↗

validateExpressionSizes validates that no expression values in the generated YAML exceed GitHub Actions limits. GitHub Actions enforces a 21,000-character limit on YAML string values that contain template expressions (${{ }}). This check covers two cases: 1. Single-line values: each YAML line is c

(yamlContent string)

Source from the content-addressed store, hash-verified

62// block contains at least one ${{ }} expression AND its total length exceeds 21,000
63// characters, GitHub Actions rejects the workflow with "Exceeded max expression length".
64func (c *Compiler) validateExpressionSizes(yamlContent string) error {
65 lines := strings.Split(yamlContent, "\n")
66 runtimeValidationLog.Printf("Validating expression sizes: yaml_lines=%d, max_size=%d", len(lines), MaxExpressionSize)
67 maxSize := MaxExpressionSize
68
69 for lineNum, line := range lines {
70 // Check the line length (actual content that will be in the YAML)
71 if len(line) > maxSize {
72 // Extract the key/value for better error message
73 trimmed := strings.TrimSpace(line)
74 key := ""
75 if colonIdx := strings.Index(trimmed, ":"); colonIdx > 0 {
76 key = strings.TrimSpace(trimmed[:colonIdx])
77 }
78
79 // Format sizes for display
80 actualSize := console.FormatFileSize(int64(len(line)))
81 maxSizeFormatted := console.FormatFileSize(int64(maxSize))
82
83 var errorMsg string
84 if key != "" {
85 errorMsg = fmt.Sprintf("expression value for %q (%s) exceeds maximum allowed size (%s) at line %d. GitHub Actions has a 21KB limit for expression values including environment variables. Consider chunking the content or using artifacts instead.",
86 key, actualSize, maxSizeFormatted, lineNum+1)
87 } else {
88 errorMsg = fmt.Sprintf("line %d (%s) exceeds maximum allowed expression size (%s). GitHub Actions has a 21KB limit for expression values.",
89 lineNum+1, actualSize, maxSizeFormatted)
90 }
91
92 return errors.New(errorMsg)
93 }
94 }
95
96 // Check multi-line YAML block scalars that contain template expressions.
97 // A run: | or any other block-scalar value is a single string from GitHub Actions'
98 // perspective; if it contains ${{ }} AND is longer than 21,000 characters the
99 // runner rejects it with "Exceeded max expression length".
100 if err := validateBlockScalarExpressionSizes(lines, maxSize); err != nil {
101 return err
102 }
103
104 return nil
105}
106
107// validateBlockScalarExpressionSizes scans the YAML lines for multi-line block scalars
108// (literal | or folded >) and returns an error when any such block both contains a

Callers 1

Calls 3

FormatFileSizeFunction · 0.92
PrintfMethod · 0.45

Tested by

no test coverage detected