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

Method generateInterpolationAndTemplateStep

pkg/workflow/template.go:97–145  ·  view source on GitHub ↗

generateInterpolationAndTemplateStep generates a step that interpolates GitHub expression variables and renders template conditionals in the prompt file. This combines both variable interpolation and template filtering into a single step. Parameters: - yaml: The string builder to write the YAML to

(yaml *strings.Builder, expressionMappings []*ExpressionMapping, data *WorkflowData)

Source from the content-addressed store, hash-verified

95// - Sets GH_AW_EXPR_* environment variables with the actual GitHub expressions (${{ ... }})
96// - Runs interpolate_prompt.cjs script to replace placeholders and render template conditionals
97func (c *Compiler) generateInterpolationAndTemplateStep(yaml *strings.Builder, expressionMappings []*ExpressionMapping, data *WorkflowData) {
98 // Check if we need interpolation
99 hasExpressions := len(expressionMappings) > 0
100
101 // Check if we need template rendering
102 hasTemplatePattern := strings.Contains(data.MarkdownContent, "{{#if ")
103 hasGitHubContext := hasGitHubTool(data.ParsedTools)
104 hasInlineSubAgents := inlineSubAgentPattern.MatchString(data.MarkdownContent)
105 hasTemplates := hasTemplatePattern || hasGitHubContext || hasInlineSubAgents
106
107 // Skip if neither interpolation nor template rendering is needed
108 if !hasExpressions && !hasTemplates {
109 templateLog.Print("No interpolation or template rendering needed, skipping step generation")
110 return
111 }
112
113 templateLog.Printf("Generating interpolation and template step: expressions=%d, hasPattern=%v, hasGitHubContext=%v, hasInlineSubAgents=%v",
114 len(expressionMappings), hasTemplatePattern, hasGitHubContext, hasInlineSubAgents)
115
116 yaml.WriteString(" - name: Interpolate variables and render templates\n")
117 fmt.Fprintf(yaml, " uses: %s\n", getCachedActionPin("actions/github-script", data))
118 yaml.WriteString(" env:\n")
119 yaml.WriteString(" GH_AW_PROMPT: /tmp/gh-aw/aw-prompts/prompt.txt\n")
120 if data.EngineConfig != nil && data.EngineConfig.ID != "" {
121 fmt.Fprintf(yaml, " GH_AW_ENGINE_ID: \"%s\"\n", data.EngineConfig.ID)
122 }
123
124 // Add environment variables for extracted expressions (deduplicated by EnvVar)
125 seen := make(map[string]struct{})
126 for _, mapping := range expressionMappings {
127 if setutil.Contains(seen, mapping.EnvVar) {
128 continue
129 }
130 seen[mapping.EnvVar] = struct{}{}
131
132 // Write the environment variable with the original GitHub expression
133 fmt.Fprintf(yaml, " %s: ${{ %s }}\n", mapping.EnvVar, mapping.Content)
134 }
135
136 yaml.WriteString(" with:\n")
137 yaml.WriteString(" script: |\n")
138
139 // Load interpolate_prompt script from external file
140 // Use setup_globals helper to store GitHub Actions objects in global scope
141 yaml.WriteString(" const { setupGlobals } = require('${{ runner.temp }}/gh-aw/actions/setup_globals.cjs');\n")
142 yaml.WriteString(" setupGlobals(core, github, context, exec, io, getOctokit);\n")
143 yaml.WriteString(" const { main } = require('${{ runner.temp }}/gh-aw/actions/interpolate_prompt.cjs');\n")
144 yaml.WriteString(" await main();\n")
145}

Calls 5

ContainsFunction · 0.92
hasGitHubToolFunction · 0.85
getCachedActionPinFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45