Skip to content

[plan] Fix YAML splicing corruption in jobs.{pre_activation,activation}.pre-steps #27746

@github-actions

Description

@github-actions

Context

Reported in #27670. When jobs.pre_activation.pre-steps or jobs.activation.pre-steps are set, injected pre-steps get spliced inside the auto-generated Setup Scripts step instead of after it, producing invalid YAML with duplicate uses:/with: keys that fails actionlint and GitHub Actions at runtime.

Root Cause

In pkg/workflow/compiler_jobs.go, insertPreStepsAfterSetupBeforeCheckout uses the regex (?m)^\s*id:\s*setup\s*$ to find the splice point, then sets insertIdx = lastSetupIdx + 1.

However, generateSetupStep in pkg/workflow/compiler_yaml_step_generation.go emits the Setup Scripts step as multiple separate []string entries (one per YAML line):

  • index N: - name: Setup Scripts\n
  • index N+1: id: setup\n ← regex matches here
  • index N+2: uses: ...\n ← splice happens here, mid-step

This splits the step's YAML block in half.

Objective

Fix the splice-point logic so pre-steps are inserted after the complete Setup Scripts step.

Approach

Choose Option A (preferred) from the issue:

  • Detect the end of the Setup Scripts step by finding the next entry that starts a new step (begins with - at the same indentation level), and use that index as the splice point — rather than lastSetupIdx + 1.

Alternatively:

  • Emit the Setup Scripts step as a single []string entry containing the full multi-line YAML block.

Files to Modify

  • pkg/workflow/compiler_jobs.go — fix insertPreStepsAfterSetupBeforeCheckout splice logic
  • pkg/workflow/compiler_yaml_step_generation.go — (if taking single-entry approach) adjust generateSetupStep
  • pkg/workflow/compiler_jobs_test.go — add regression tests

Acceptance Criteria

Generated by Plan Command for issue #27670 · ● 242.8K ·

  • expires on Apr 24, 2026, 2:47 AM UTC

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions