Skip to content

Fix post-steps indentation errors in YAML workflow generation#1868

Merged
pelikhan merged 7 commits intomainfrom
copilot/fix-post-steps-indentation
Oct 17, 2025
Merged

Fix post-steps indentation errors in YAML workflow generation#1868
pelikhan merged 7 commits intomainfrom
copilot/fix-post-steps-indentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 17, 2025

Problem

The generatePostSteps function was generating post-steps with incorrect indentation, causing YAML schema validation failures when compiling agentic workflows. Post-steps were rendered with 4-space indentation instead of the required 6-space indentation for GitHub Actions workflow steps.

This resulted in validation errors like:

workflow schema validation failed: failed to parse YAML for schema validation: 
[1249:5] non-map value is specified
> 1249 |     - name: Post AI Step
             ^

Solution

Updated the generatePostSteps function in pkg/workflow/compiler.go to generate correct indentation that matches GitHub Actions schema requirements:

  • List items (- name:): 6 spaces instead of 4
  • Properties (run:, uses:, with:): 8 spaces instead of 4
  • Nested properties (under with:): 10 spaces instead of 6

Before (Incorrect)

jobs:
  agent:
    steps:
      - name: AI Execution
        run: ./run-ai
    - name: Post AI Step              # ❌ 4 spaces (should be 6)
    run: echo "test"                  # ❌ 4 spaces (should be 8)

After (Correct)

jobs:
  agent:
    steps:
      - name: AI Execution
        run: ./run-ai
      - name: Post AI Step            # ✅ 6 spaces
        run: echo "test"              # ✅ 8 spaces

Additional Improvements

  • Added trailing whitespace trimming to prevent stray spaces in generated YAML
  • Added explicit empty line handling to avoid generating blank lines with whitespace
  • Improved code comments to document the expected indentation levels

Testing

  • Added comprehensive test TestPostStepsIndentationFix that validates indentation at all nesting levels
  • Added test agentic workflow .github/workflows/test-post-steps.md to catch future compile issues with post-steps
  • All existing post-steps tests continue to pass
  • Successfully compiled all 65 workflow files in the repository with make recompile
  • Manual verification confirms workflows now validate successfully

Fixes #1867

Original prompt

This section details on the original issue you should resolve

<issue_title>post-steps intendation errors</issue_title>
<issue_description>locally copilot made these to workaround:

• Here's the tiny patch I made to the githubnext/gh-aw CLI so post-steps render with valid YAML indentation:

  diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go
  index d212984..2d4f67d 100644
  --- a/pkg/workflow/compiler.go
  +++ b/pkg/workflow/compiler.go
  @@ -2936,11 +2936,15 @@ func (c *Compiler) generatePostSteps(yaml *strings.Builder, data *WorkflowData)
           lines := strings.Split(data.PostSteps, "\n")
           if len(lines) > 1 {
               for _, line := range lines[1:] {
  -                // Remove 2 existing spaces, add 6
  -                if strings.HasPrefix(line, "  ") {
  -                    yaml.WriteString("    " + line[2:] + "\n")
  -                } else {
  -                    yaml.WriteString("    " + line + "\n")
  -                }
  +                trimmed := strings.TrimRight(line, " ")
  +                if strings.TrimSpace(trimmed) == "" {
  +                    yaml.WriteString("\n")
  +                    continue
  +                }
  +                if strings.HasPrefix(line, "  ") {
  +                    yaml.WriteString("        " + line[2:] + "\n")
  +                } else {
  +                    yaml.WriteString("      " + line + "\n")
  +                }
               }
           }

  What changed and why

  - The generator previously prepended only four spaces, which produced YAML like     - name: … under jobs.agent.steps. GitHub's workflow schema expects list items there
    to start at six spaces (      - …), so schema validation failed whenever we added a post-steps block.
  - I also trim right-hand whitespace and skip empty lines explicitly so the compiler doesn't spew stray spaces when authors leave blank lines inside post-steps.

  After rebuilding (go1.24.5 build ./cmd/gh-aw) and copying the new binary to ~/.local/share/gh/extensions/gh-aw/gh-aw, gh aw compile emits correctly indented YAML, and
  all five workflows now compile without errors.
```</issue_description>

<agent_instructions>Fix the issue reported .</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #1867


✨ 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 17, 2025 15:28
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 17, 2025 15:47
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan
Copy link
Copy Markdown
Collaborator

Add 1 test agentic workflow with post jobs to catch compile issues.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot Add 1 test agentic workflow with post jobs to catch compile issues.

Copilot AI changed the title [WIP] Fix post-steps indentation errors in compiler Fix post-steps indentation errors in YAML workflow generation Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 15:49
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot Add 1 test agentic workflow with post jobs to catch compile issues.

Added test-post-steps.md workflow in .github/workflows/ that demonstrates post-steps compilation with proper indentation validation. The workflow includes multiple post-steps with various configurations (conditional execution, artifact upload, step summary) and compiles successfully. See commit for details.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan merged commit 1f067c8 into main Oct 17, 2025
8 of 14 checks passed
@pelikhan pelikhan deleted the copilot/fix-post-steps-indentation branch October 17, 2025 16:25
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.

post-steps intendation errors

2 participants