Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Template conditionals like {{#if github.event.issue.number}} were being wrapped with ${{ }} after expression extraction, creating invalid YAML syntax in heredocs:

{{#if ${{ github.event.issue.number }} }}  # ❌ Invalid - GitHub Actions tries to evaluate this

Root cause: Expression wrapping happened after extraction, so newly created ${{ }} expressions were never replaced with placeholders.

Fix: Reorder compilation to wrap conditionals before extracting expressions:

// Before (wrong order)
extractExpressions()      // Extracts ${{ github.event.issue.number }}
replaceWithPlaceholders() // Replaces with __GH_AW_*__
wrapConditionals()        // Creates NEW ${{ }} that never get extracted ❌

// After (correct order)  
wrapConditionals()        // Creates {{#if ${{ github.event.issue.number }} }}
extractExpressions()      // Extracts ALL ${{ }} including wrapped ones
replaceWithPlaceholders() // Replaces ALL with __GH_AW_*__ ✅

Result:

{{#if __GH_AW_GITHUB_EVENT_ISSUE_NUMBER__ }}  # ✅ Valid - placeholder replaced at runtime

Changes:

  • Moved wrapExpressionsInTemplateConditionals() before expression extraction in compiler_yaml.go
  • Updated tests to validate placeholder replacement instead of direct expression wrapping
Original prompt

The conditional template experssion in {{#if ... }} should expanded to github action expression and then replaced by environment variables before being written to heredoc.

You can see this with

https://github.com/githubnext/gh-aw/blob/main/.github/workflows/cloclo.md?plain=1#L66C1-L66C34

The rendered lock file results in an invalid expression that breaks the yaml file.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Move wrapExpressionsInTemplateConditionals before expression extraction
to ensure that GitHub Actions expressions created by wrapping {{#if }}
conditionals are also extracted and replaced with environment variable
placeholders. This prevents invalid YAML syntax in compiled workflows.

Before: {{#if ${{ github.event.issue.number }} }}
After:  {{#if __GH_AW_GITHUB_EVENT_ISSUE_NUMBER__ }}

Updated tests to validate correct placeholder replacement behavior.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid expression in YAML rendered from heredoc Fix template conditional expressions creating invalid YAML in heredocs Jan 8, 2026
Copilot AI requested a review from pelikhan January 8, 2026 00:31
@pelikhan pelikhan marked this pull request as ready for review January 8, 2026 01:06
@pelikhan pelikhan merged commit 6f1e440 into main Jan 8, 2026
113 checks passed
@pelikhan pelikhan deleted the copilot/fix-invalid-yaml-expression branch January 8, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants