Skip to content

Don't apply an action's sub-path rewrite to reusable workflow calls - #263

Merged
nodeselector merged 2 commits into
github:mainfrom
suzuki-shunsuke:fix-reusable-workflow-rewrite
Nov 5, 2026
Merged

nodeselector merged 2 commits into
github:mainfrom
suzuki-shunsuke:fix-reusable-workflow-rewrite

Conversation

@suzuki-shunsuke

Copy link
Copy Markdown
Contributor

Fixes #261

Cause

RewriteActionRefs looks up every uses: value with LookupRewrite. When there is no exact key, subpathRewriteLookup maps owner/repo/<path>@ref onto an owner/repo@ref rewrite and replaces the ref.

Some planners key rewrites by owner/repo@ref without the sub-path: reverseLookupRewrites, narrowDirectDeps, and the semver branch of narrowVerifiedEntries. So when a step uses an action from the same repository (e.g. owner/repo/restore@<sha>), the reusable workflow call owner/repo/.github/workflows/x.yml@<sha> matches the same key and is rewritten to the tag too.

The lockfile doesn't lock reusable workflow calls, so the full commit SHA is the only pin they have.

Change

subpathRewriteLookup now returns no match for values that parserlock.ParseActionRef doesn't parse as an action. ParseActionRef returns nil for any YAML file under .github/workflows/. The rest of the lookup is unchanged, and so are sub-path actions such as owner/repo/restore@ref and owner/repo/.github/actions/foo@ref.

The exact-key path is left as it is: no planner keys a rewrite by a reusable workflow call today. I added a note to the LookupRewrite doc comment so this assumption isn't lost if reusable workflow calls get locked (#179).

This also changes ValidateRequiredActionRefRewrites. Before, a reusable workflow call matched through the sub-path fallback was counted in changed but not in matches, so a required rewrite failed with "required action rewrite matched 1 uses: values but could update only 2".

Tests

  • TestSubpathRewriteLookup: a reusable workflow call and a nested workflow file don't match; a non-workflow path under .github/ still matches.
  • TestRewriteActionRefs_SkipsReusableWorkflowCalls: the reproduction from Fix mode unpins a reusable workflow call when the same repository is also used as a step action #261 keeps the reusable workflow call's ref and comment, and a workflow-shaped value under with: keeps its value.
  • TestValidateRequiredActionRefRewrites (new): a reusable workflow call next to a step from the same repository isn't counted as a rewrite.

All of these except the non-workflow path case fail without the change. make test, make fmt-check and make vet pass.

I also ran the reproduction from #261 with the built binary: the step is rewritten to @v0.0.10, the reusable workflow call keeps its SHA and comment, --no-fix reports "All 1 workflow valid", and a second run doesn't change anything.

Related issues not fixed here

This is a narrow fix inside the fallback. I found these while reading the code; I haven't reproduced them.

  1. RewriteActionRefs, ValidateRequiredActionRefRewrites and UsesValues visit every key named uses, while walkUses only visits step and job positions. An action-shaped with: { uses: owner/repo/restore@<sha> } is still rewritten by a step action's rewrite.
  2. subpathRewriteLookup keeps the old owner/repo and replaces only the ref. A redirect rewrite from transferRewrites (old/repo@<sha> -> new/repo@v1) can turn old/repo/sub@<sha> into old/repo/sub@v1, a ref that may not exist on the old repository. ValidateRequiredActionRefRewrites can then also report a count mismatch.
  3. The root of 1, 2 and Fix mode unpins a reusable workflow call when the same repository is also used as a step action #261 is that some planners key rewrites without the sub-path while others (the SHA branch of narrowVerifiedEntries, transferRewrites) use the full name. Keying every rewrite by the full uses: value would make the fallback unnecessary, but cases where the workflow has no matching uses: (e.g. $/… action files) need checking first.

🤖 Generated with Claude Code

suzuki-shunsuke and others added 2 commits November 3, 2026 13:18
subpathRewriteLookup mapped any owner/repo/<path>@ref onto an
owner/repo@ref rewrite, including owner/repo/.github/workflows/<file>@ref.
When a step used an action from the same repository pinned by the same
SHA, fix mode rewrote the reusable workflow call to the tag as well,
although the lockfile doesn't lock reusable workflow calls.

Skip values that parserlock.ParseActionRef doesn't parse as an action.

Fixes github#261

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check replacements for the owner/repo@ref key before running
parserlock.ParseActionRef, so values without a matching rewrite skip the
full validation. Drop the inline comment that repeated, too narrowly,
what LookupRewrite's doc comment says, and the nested workflow file test
case, which only exercised ParseActionRef.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@suzuki-shunsuke
suzuki-shunsuke marked this pull request as ready for review November 3, 2026 04:38
@suzuki-shunsuke
suzuki-shunsuke requested a review from a team as a code owner November 3, 2026 04:38
Copilot AI adaptive review requested due to automatic review settings November 3, 2026 04:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change preserving reusable workflow commit-SHA pins during action sub-path rewrites.

No open issues 🎉

What changed in this PR

Fixes #261 by preventing action sub-path rewrites from changing reusable workflow calls. This preserves their commit-SHA pins while reusable workflows remain outside lockfile coverage.

Changes:

  • Restricts fallback matching to values parsed as action references, leaving exact-key matching unchanged.
  • Documents the exact-key assumption and adds regression tests for preserved workflow refs, action rewrites, and required-rewrite counts.
File Description
internal/​workflowfile/​rewrite.go Guards fallback matching and documents exact-key behavior.
internal/​workflowfile/​rewrite_test.go Tests workflow-call preservation, supported action paths, and rewrite counts.

Review effort: Max (auto)

@nodeselector
nodeselector merged commit a4c16a7 into github:main Nov 5, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this to Done in main Nov 5, 2026
@suzuki-shunsuke
suzuki-shunsuke deleted the fix-reusable-workflow-rewrite branch November 5, 2026 03:49
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.

Fix mode unpins a reusable workflow call when the same repository is also used as a step action

3 participants