Skip to content

[aw-compat] Add codemods for run-expression hoisting, engine latest pinning, and toolset permission synthesis - #32341

Merged
pelikhan merged 14 commits into
mainfrom
copilot/daily-aw-cross-repo-compatibility
May 15, 2026
Merged

pelikhan merged 14 commits into
mainfrom
copilot/daily-aw-cross-repo-compatibility

Conversation

Copilot AI commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Bug Fix

What was the bug?

The daily cross-repo compatibility sweep still had 3 deterministic gh aw fix --write misses: inline ${{ github.token }} / ${{ env.* }} in run: blocks surviving into compiled workflows, engine.version: latest failing strict mode, and missing permissions.<scope>: read for declared tools.github.toolsets.

How did you fix it?

  • Run-expression hoisting codemod expansion

    • Extended steps-run-secrets-to-env to also rewrite:
      • ${{ github.token }} → $GH_AW_GITHUB_TOKEN + step env binding
      • ${{ env.NAME }} → $GH_AW_ENV_NAME + step env binding
    • Keeps inline ${{ ... }} out of run: for strict-mode compatibility.
  • Engine version codemod

    • Added new codemod: pin-engine-version.
    • When engine.version: latest is present, the codemod removes version so workflow compilation uses gh-aw’s pinned default engine version.
  • Toolset-permission synthesis codemod

    • Generalized dependabot-toolset-permissions from a single-scope patch to full permission synthesis from tools.github.toolsets.
    • Uses existing permission validation mapping to compute missing scopes and inject required permissions.<scope>: read entries (excluding GitHub App-only scopes).
  • Codemod registry + tests

    • Registered pin-engine-version in codemod ordering.
    • Added focused tests for:
      • github.token/env.* run hoisting behavior
      • engine.version: latest migration
      • non-dependabot toolset permission backfill (e.g. issues).

Example

# before
engine:
  id: copilot
  version: latest
tools:
  github:
    toolsets: [issues]
steps:
  - run: echo "${{ env.RUNTIME_TOKEN }} ${{ github.token }}"
permissions:
  contents: read

# after gh aw fix --write
engine:
  id: copilot
tools:
  github:
    toolsets: [issues]
steps:
  - env:
      GH_AW_ENV_RUNTIME_TOKEN: ${{ env.RUNTIME_TOKEN }}
      GH_AW_GITHUB_TOKEN: ${{ github.token }}
    run: echo "$GH_AW_ENV_RUNTIME_TOKEN $GH_AW_GITHUB_TOKEN"
permissions:
  contents: read
  issues: read

Copilot AI and others added 4 commits May 15, 2026 12:15
…pression hoisting

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>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compatibility issues in daily AW cross-repo sweep [aw-compat] Add codemods for run-expression hoisting, engine latest pinning, and toolset permission synthesis May 15, 2026
Copilot AI requested a review from pelikhan May 15, 2026 12:21
@pelikhan
pelikhan marked this pull request as ready for review May 15, 2026 12:21
Copilot AI review requested due to automatic review settings May 15, 2026 12:21
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add testing and fuzz testing for Run-expression hoisting codemod expansion

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds and extends three codemods in gh aw fix to close the remaining strict-mode/compatibility gaps in compiled workflows: run-expression hoisting now covers ${{ github.token }} and ${{ env.* }}, a new codemod strips engine.version: latest, and the dependabot-only permission codemod is generalized to backfill any missing read permissions implied by tools.github.toolsets.

Changes:

  • Extend steps-run-secrets-to-env to hoist ${{ github.token }} and ${{ env.NAME }} into step env bindings, in addition to secrets.*.
  • Introduce pin-engine-version codemod that removes engine.version: latest, and register it in the codemod ordering.
  • Generalize dependabot-toolset-permissions to compute missing scopes from all declared toolsets via workflow.ValidatePermissions, skipping GitHub App-only scopes.
Show a summary per file
File Description
pkg/cli/fix_codemods.go Register the new pin-engine-version codemod in the ordered list.
pkg/cli/fix_codemods_test.go Update expected codemod list/order to include pin-engine-version.
pkg/cli/codemod_steps_run_secrets_env.go Replace secret-only rewrite with a general expression mapper handling secrets.*, env.*, and github.token.
pkg/cli/codemod_steps_run_secrets_env_test.go Add tests for hoisting github.token and env.* expressions.
pkg/cli/codemod_engine_latest_version.go New codemod removing engine.version: latest.
pkg/cli/codemod_engine_latest_version_test.go Tests for the new pin-engine-version codemod.
pkg/cli/codemod_dependabot_permissions.go Rework into a general toolset permission synthesizer using ValidatePermissions.
pkg/cli/codemod_dependabot_permissions_test.go Add coverage for non-dependabot toolset (issues) permission backfill.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 1

func mapRunExpressionToEnvBinding(body string) (string, string, bool) {
if secretMatch := stepsSecretBodyExprRe.FindStringSubmatch(body); len(secretMatch) == 2 {
secretName := secretMatch[1]
return secretName, fmt.Sprintf("${{ secrets.%s }}", secretName), true
Copilot AI and others added 2 commits May 15, 2026 12:34
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add testing and fuzz testing for Run-expression hoisting codemod expansion

Addressed in caf5669 (plus follow-up cleanup in 1c2bebc): added expanded unit coverage for run-expression hoisting and a dedicated fuzz test (FuzzStepsRunSecretsToEnvCodemod) covering section variants, expression combinations, and binding dedup behavior.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review all comments

Copilot AI and others added 2 commits May 15, 2026 13:03
… to warning

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI and others added 2 commits May 15, 2026 13:14
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review all comments

Reviewed all comments and addressed the remaining actionable one in 2ec3cb2 (with follow-up clarification in efcd33b): fallback expressions like ${{ secrets.NAME || ... }} are now left unchanged, with test coverage added.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot all expressions that may lead to shell injection should be hoisted, including complex like ${{ secrets.NAME || ... }}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot all expressions that may lead to shell injection should be hoisted, including complex like ${{ secrets.NAME || ... }}

Implemented in 10f3cd1. Complex sensitive run expressions are now hoisted as well (including forms like ${{ secrets.NAME || ... }}), with full expression preservation in env bindings and collision-safe synthesized variable names.

Copilot AI and others added 2 commits May 15, 2026 13:40
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit ef35a7b into main May 15, 2026
@pelikhan
pelikhan deleted the copilot/daily-aw-cross-repo-compatibility branch May 15, 2026 13:44
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] Daily AW cross-repo compatibility (2026-05-15): 3/20 still failing after fix — 3 codemod candidates

3 participants