Skip to content

Add compiler validation to detect @include/@import directives inside template regions#1256

Merged
pelikhan merged 3 commits intomainfrom
copilot/add-template-region-checks
Oct 6, 2025
Merged

Add compiler validation to detect @include/@import directives inside template regions#1256
pelikhan merged 3 commits intomainfrom
copilot/add-template-region-checks

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 6, 2025

Problem

The compiler was not validating that @include and @import directives are used correctly with template conditional blocks. This created ambiguity because:

  • Template conditionals ({{#if...}}{{/if}}) are processed at runtime by GitHub Actions
  • Include directives are processed at compile time by the compiler
  • Having includes inside conditionals would create confusion about when to expand them

Solution

Added a new validation function validateNoIncludesInTemplateRegions() that:

  1. Scans markdown content for all {{#if...}}{{/if}} template regions
  2. Checks each line within template blocks for @include or @import directives
  3. Handles indented includes by trimming whitespace before pattern matching
  4. Returns a clear error message indicating the problematic directive and its location

The validation is integrated into ParseWorkflowFile() before include expansion, ensuring we catch issues early with the raw markdown content.

Example

Before - This would compile without error (causing confusion):

{{#if github.event.issue.number}}
@include shared/tools.md
This creates ambiguity!
{{/if}}

After - Now raises a clear error:

✗ failed to parse workflow file: template region validation failed: 
@include/@import directives cannot be used inside template regions 
({{#if...}}{{/if}}): found '@include shared/tools.md' at line 2 within template block

Correct usage - Includes outside templates work as expected:

@include shared/tools.md

{{#if github.event.issue.number}}
Content here is fine!
{{/if}}

Testing

  • Added 18 unit tests covering various scenarios (nested templates, indented includes, optional includes, section references)
  • Added 4 integration tests with the compiler
  • All existing tests continue to pass
  • make agent-finish validates all checks pass

Fixes the issue where includes inside template regions could cause compilation or runtime confusion.

Original prompt

Add a compiler checks that detects usage of @include/import commands inside template regions ({{#if...). Raise an error.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 6, 2025 16:34
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add compiler checks for template region commands Add compiler validation to detect @include/@import directives inside template regions Oct 6, 2025
Copilot AI requested a review from pelikhan October 6, 2025 16:47
@pelikhan pelikhan marked this pull request as ready for review October 6, 2025 18:30
@pelikhan pelikhan merged commit b87faa2 into main Oct 6, 2025
@pelikhan pelikhan deleted the copilot/add-template-region-checks branch October 6, 2025 18:30
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