Repository navigation
[aw-compat] Add codemods for run-expression hoisting, engine latest pinning, and toolset permission synthesis - #32341
Conversation
…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 add testing and fuzz testing for Run-expression hoisting codemod expansion |
There was a problem hiding this comment.
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-envto hoist${{ github.token }}and${{ env.NAME }}into stepenvbindings, in addition tosecrets.*. - Introduce
pin-engine-versioncodemod that removesengine.version: latest, and register it in the codemod ordering. - Generalize
dependabot-toolset-permissionsto compute missing scopes from all declared toolsets viaworkflow.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 |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed in caf5669 (plus follow-up cleanup in 1c2bebc): added expanded unit coverage for run-expression hoisting and a dedicated fuzz test ( |
|
@copilot review all comments |
… to warning 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 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>
Implemented in 10f3cd1. Complex sensitive run expressions are now hoisted as well (including forms like |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Bug Fix
What was the bug?
The daily cross-repo compatibility sweep still had 3 deterministic
gh aw fix --writemisses: inline${{ github.token }}/${{ env.* }}inrun:blocks surviving into compiled workflows,engine.version: latestfailing strict mode, and missingpermissions.<scope>: readfor declaredtools.github.toolsets.How did you fix it?
Run-expression hoisting codemod expansion
steps-run-secrets-to-envto also rewrite:${{ github.token }}→$GH_AW_GITHUB_TOKEN+ stepenvbinding${{ env.NAME }}→$GH_AW_ENV_NAME+ stepenvbinding${{ ... }}out ofrun:for strict-mode compatibility.Engine version codemod
pin-engine-version.engine.version: latestis present, the codemod removesversionso workflow compilation uses gh-aw’s pinned default engine version.Toolset-permission synthesis codemod
dependabot-toolset-permissionsfrom a single-scope patch to full permission synthesis fromtools.github.toolsets.permissions.<scope>: readentries (excluding GitHub App-only scopes).Codemod registry + tests
pin-engine-versionin codemod ordering.github.token/env.*run hoisting behaviorengine.version: latestmigrationissues).Example