Skip to content

Keep SHA pins in same-repo composite actions - #298

Merged
nodeselector merged 6 commits into
mainfrom
nodeselector-composite-action-lock-bug
Nov 18, 2026
Merged

nodeselector merged 6 commits into
mainfrom
nodeselector-composite-action-lock-bug

Conversation

@nodeselector

Copy link
Copy Markdown
Collaborator

Fixes #264

  • A full commit SHA in a same-repo $/… composite action is no longer rewritten to a tag. Other repos that use the action don't have your lockfile, so the SHA is the only pin they get.
  • That SHA is locked as written in every workflow that reaches the action, and it doesn't get the sha-as-ref warning anymore.
  • If the action's repo was renamed, the pin still moves to the new name and keeps its SHA, including when a workflow already uses the new name at the same commit.
  • Only step-level uses: values get rewritten now. Job-level reusable workflow calls and uses keys under with: are left alone.
  • Other refs inside $/… actions (tags, branches) are still narrowed like before.
  • README and troubleshooting docs note the exemption.
  • Longer term we'd like composite actions to ship their own lockfiles, so repos that use them get the pins too. That's a future thing and not part of this PR.

Building on the sub-path guard, restrict RewriteActionRefs,
ValidateRequiredActionRefRewrites and UsesValues to step-level uses:
values using walkUses' position rules. An action-shaped uses: key under
with: is input data and was still rewritten and counted.

Refs #261
A full-SHA uses: inside a same-repository $/ action is no longer
rewritten to the tag it resolves to. Other repositories run that action
without this lockfile, so the SHA is the only pin they get. The ref is
still locked, under its SHA spelling, in every workflow that reaches it.

Fixes #264
The lockfile records a renamed repository under its new name, so a
full-SHA uses: in a $/ action must follow the rename to stay covered.
The rename keeps the SHA.
A workflow that uses a renamed repository's new name at the commit a
same-repository action pins under the old name could narrow the shared
dependency to a tag and carry that tag into the action file with the
rename.
@nodeselector
nodeselector requested a review from a team as a code owner November 18, 2026 19:49
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 19:49
@nodeselector
nodeselector merged commit 86027a4 into main Nov 18, 2026
13 checks passed

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.

🟡 Changes recommended

UsesValues can miss aliased step dependencies, allowing a still-used root to be removed and causing --verify-local to report ref-changed.

1 open issue
What changed in this PR

Addresses #264 by preserving SHA pins in same-repository composite actions, protecting external consumers that do not have the action repository’s lockfile.

Changes:

  • Keep full-SHA refs locked for every calling workflow without sha-as-ref warnings.
  • Preserve SHAs across repository renames and restrict rewrites to step-level uses:.
  • Update documentation and regression coverage.
File Description
README.md Documents the composite-action SHA exemption.
internal/​workflowfile/​workflowfile.go Adds node-aware traversal of step references.
internal/​workflowfile/​rewrite.go Limits rewriting, validation, and inventory to step references.
internal/​workflowfile/​rewrite_test.go Tests exclusion of workflow calls and input data.
internal/​pipeline/​parse.go Excludes composite-action SHA pins from narrowing.
internal/​pipeline/​parse_test.go Tests filtering rules and the non-nil empty subset.
internal/​pipeline/​checks/​structural.go Suppresses warnings for exempt SHA pins.
internal/​pipeline/​checks/​run_test.go Tests the warning exemption.
internal/​pin/​plan.go Keeps exempt references eligible for repository rename updates.
docs/​troubleshooting.md Explains the SHA warning exemption.
cmd/​gh-actions-lock/​selfrepository_test.go Tests SHA preservation and repository renames.
cmd/​gh-actions-lock/​run_test.go Tests SHA coverage across workflows sharing an action.
cmd/​gh-actions-lock/​command_test.go Tests that reusable workflow calls retain their SHA.

Review effort: Max (adaptive)

steps := stepUsesNodes(&f.root)
walkYAMLNodes(&f.root, func(keyNode, valueNode *yaml.Node) {
if keyNode != nil && valueNode != nil && keyNode.Value == "uses" && valueNode.Kind == yaml.ScalarNode {
if keyNode != nil && valueNode != nil && keyNode.Value == "uses" && valueNode.Kind == yaml.ScalarNode && steps[valueNode] {
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.

Bug: gh actions-lock rewrote a composite action, but did not lock it

2 participants