Skip to content

Add auto-hoist-run-expressions codemod: hoist all ${{ ... }} run-block expressions to env bindings#32533

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/aw-compat-missing-codemod
Draft

Add auto-hoist-run-expressions codemod: hoist all ${{ ... }} run-block expressions to env bindings#32533
Copilot wants to merge 8 commits into
mainfrom
copilot/aw-compat-missing-codemod

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

The existing steps-run-secrets-to-env codemod only handles secrets.*, env.*, and github.token — leaving expressions like github.repository, inputs.*, or steps.*.outputs.* in run: scripts, which triggers the compiler's hard "compiler regression detected" guardrail error with no automated fix path.

New codemod: auto-hoist-run-expressions

Covers every ${{ ... }} expression that slips past steps-run-secrets-to-env, registered immediately after it in the codemod chain.

Naming convention:

  • Simple property chains → EXPR_ + sanitised uppercase body: github.tokenEXPR_GITHUB_TOKEN, inputs.my-inputEXPR_INPUTS_MY_INPUT
  • Complex expressions (operators, function calls) → EXPR_<fnv32-8hex> for collision safety

PowerShell awareness: steps with shell: pwsh or shell: powershell get $env:VARNAME instead of $VARNAME.

Before / After (the failing microsoft/aspire pattern):

# Before
- name: Capture token
  run: |
    echo "GH_TOKEN=${{ github.token }}" >> "$GITHUB_OUTPUT"

# After
- name: Capture token
  env:
    EXPR_GITHUB_TOKEN: ${{ github.token }}
  run: |
    echo "GH_TOKEN=$EXPR_GITHUB_TOKEN" >> "$GITHUB_OUTPUT"

Changes

  • pkg/cli/codemod_auto_hoist_run_expressions.go — codemod implementation; reuses shared parseStepKeyLine / effectiveStepLineIndentLen / hashedBindingName helpers from the existing codemod
  • pkg/cli/codemod_auto_hoist_run_expressions_test.go — 18 test cases covering: block and inline run forms, simple/complex/PowerShell/multi-expression/dedup/pre-existing-binding scenarios
  • pkg/cli/fix_codemods.go — registers codemod after steps-run-secrets-to-env
  • pkg/cli/fix_codemods_test.go — updates expected count (48 → 49) and order
  • docs/ — adds codemod to cli.md and gh-aw-as-mcp-server.md
  • .changeset/ — minor release entry

Copilot AI and others added 3 commits May 16, 2026 02:46
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…on hoisting

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 codemod to auto-hoist run-block ${{ ... }} expressions Add auto-hoist-run-expressions codemod: hoist all ${{ ... }} run-block expressions to env bindings May 16, 2026
Copilot AI requested a review from pelikhan May 16, 2026 02:55
Comment thread pkg/cli/fix_codemods_test.go Outdated
Comment on lines +156 to +157
"steps-run-secrets-to-env",
"auto-hoist-run-expressions",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot aren't those codemods the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're distinct and complementary:

  • steps-run-secrets-to-env handles only secrets.*, env.*, and github.token, producing names like MY_TOKEN, GH_AW_ENV_FOO, GH_AW_GITHUB_TOKEN.
  • auto-hoist-run-expressions is a catch-all for every remaining ${{ ... }} expression (e.g. github.repository, inputs.*, steps.*.outputs.*) that slips past the first codemod, using the EXPR_ prefix naming convention.

Because steps-run-secrets-to-env runs first and replaces its specific patterns, auto-hoist-run-expressions never sees those expressions again — it only picks up anything the first codemod didn't handle.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge both code modes, move all expressions out of runs

Copilot AI and others added 2 commits May 16, 2026 04:11
Extend the existing codemod to handle ALL ${{ ... }} expressions in
run: blocks, not just secrets.*, env.*, and github.token. Non-legacy
expressions receive EXPR_* names. PowerShell steps (shell: pwsh /
powershell) get $env:VARNAME syntax. Remove the separate
auto-hoist-run-expressions codemod.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 16, 2026

@copilot merge both code modes, move all expressions out of runs

Done. auto-hoist-run-expressions has been merged into steps-run-secrets-to-env:

  • The catch-all EXPR_ logic (for github.repository, inputs.*, steps.*.outputs.*, etc.) and PowerShell awareness ($env:VARNAME) are now part of steps-run-secrets-to-env.
  • The separate codemod_auto_hoist_run_expressions.go file and its registration in fix_codemods.go are removed.
  • The codemod count drops from 49 → 48.

Commit: the latest two commits on this branch.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot recompile, add tests, fuzz tests

Copilot AI and others added 2 commits May 16, 2026 04:44
- Update FuzzStepsRunSecretsToEnvCodemod: check no ${{ ... }} remains
  in run line (was checking only specific patterns)
- Add FuzzStepsRunSecretsToEnvCodemodExpr: covers EXPR_* naming for
  generic property-access chains (github.X, inputs.X, etc.)
- Add FuzzStepsRunSecretsToEnvCodemodPowerShell: verifies $env:VARNAME
  output for pwsh/powershell steps
- Add sanitizeHoistPropertySegment helper for generating valid
  property-chain segments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 16, 2026

@copilot recompile, add tests, fuzz tests

Done. Build passes. Three fuzz functions now cover the merged codemod:

  • FuzzStepsRunSecretsToEnvCodemod (updated) — validation now checks that no ${{ ... }} remains in run lines (previously only checked specific secrets/env/github.token patterns)
  • FuzzStepsRunSecretsToEnvCodemodExpr (new) — covers EXPR_* catch-all for generic property-access chains (github.X, inputs.X, etc.), verifying correct EXPR_GITHUB_X naming and dedup
  • FuzzStepsRunSecretsToEnvCodemodPowerShell (new) — verifies that pwsh/powershell steps receive $env:VARNAME instead of bare $VARNAME

Commits: the last two on this branch.

@github-actions github-actions Bot mentioned this pull request May 16, 2026
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot recompile, add tests

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.

[aw-compat] Missing codemod: auto-hoist run-block $\{\{ ... }} expressions to env: bindings

2 participants