Add --relock to bump moved branch and version refs by nodeselector · Pull Request #88 · github/gh-actions-lock · GitHub
Skip to content

Add --relock to bump moved branch and version refs - #88

Merged
nodeselector merged 4 commits into
mainfrom
nodeselector-issue-751-relock-branch-refs
Jul 24, 2026
Merged

nodeselector merged 4 commits into
mainfrom
nodeselector-issue-751-relock-branch-refs

Conversation

@nodeselector

Copy link
Copy Markdown
Collaborator

What

Adds a --relock flag that re-resolves mutable refs (branches like main, partial versions like v4) whose upstream head has advanced, and rewrites the lockfile to the current SHA.

gh actions-lock --relock

Why

Mutable refs are trusted from the lockfile and only verified under --rescan, which emits a benign ref-moved warning but never advances the pin. Because a ref-moved finding doesn't make a workflow "need attention", the re-pin path never ran — so there was no way to bump what main points at. This is the gap reported in github/actions-dispatch#751.

How it works

  • --relock implies --rescan (it must hit the network to detect what moved).
  • pruneStaleInventory prunes ref-moved deps under relock so they re-resolve live; unreachable-pin stays --accept-moved-only.
  • needsRepin routes ref-moved workflows through the live re-pin path instead of the trust-inventory fast path.
  • informationalEntries no longer records ref-moved for investigation when the run re-pins it, so a clean relock exits zero.

Safety

Unlike --accept-moved, --relock does not accept unreachable-pin findings — a pin whose recorded commit is no longer reachable upstream (possible tampering) stays a hard error. Use --accept-moved to re-resolve those deliberately.

Shared finding classification (NeedsAttention/IsValid/checks categories) is untouched.

Tests

  • internal/pin/relock_test.go: prune/route logic for relock vs accept-moved.
  • cmd/gh-actions-lock/command_test.go: fix-mode --relock rewrites the lockfile from the stale SHA to the live head; a default run leaves a trusted branch ref untouched.
  • verify_test.go: --relock implies --rescan; --relock --verify-local conflicts.

Resolves github/actions-dispatch#751

Mutable refs (branches like main, partial versions like v4) are trusted
from the lockfile and only verified under --rescan, which emits a benign
ref-moved warning without advancing the pin. Because a ref-moved finding
doesn't make a workflow "need attention", the re-pin path never ran, so
there was no way to bump what main points at.

Add a --relock flag that re-resolves refs whose upstream ref legitimately
advanced (ref-moved) and rewrites the lockfile to the current SHA. It
implies --rescan (must detect movement) and, unlike --accept-moved, does
NOT accept unreachable-pin findings, so a pin whose commit is no longer
reachable upstream stays a hard error.

Implementation:
- pruneStaleInventory prunes ref-moved deps under relock (unreachable-pin
  stays accept-moved-only) so the moved dep re-resolves live.
- needsRepin routes ref-moved workflows through the live re-pin path when
  relocking/accepting instead of the trust-inventory fast path.
- informationalEntries no longer records ref-moved for investigation when
  the run re-pins it, so a clean relock exits zero.
- Shared checks classification (NeedsAttention/IsValid) is untouched.

Resolves github/actions-dispatch#751
@nodeselector
nodeselector requested a review from a team as a code owner July 13, 2026 22:15
Copilot AI review requested due to automatic review settings July 13, 2026 22:15

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.

⚠️ Not ready to approve

Relock can miss moved transitive pins and rewrite unreachable transitive pins before returning an error.

Pull request overview

Adds --relock to refresh moved mutable action references while intending to preserve unreachable-pin safety.

Changes:

  • Wires --relock into CLI validation and rescan behavior.
  • Adds relock-specific pin planning and inventory pruning.
  • Documents and tests direct branch relocking.
File summaries
File Description
README.md Documents relock usage and safety.
internal/pin/relock_test.go Tests relock planning helpers.
internal/pin/plan.go Implements relock planning behavior.
cmd/gh-actions-lock/verify.go Makes relock imply rescan.
cmd/gh-actions-lock/verify_test.go Tests flag implications and conflicts.
cmd/gh-actions-lock/run.go Adds and propagates the CLI flag.
cmd/gh-actions-lock/command_test.go Tests direct branch relocking.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Medium

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


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

Comment thread internal/pin/plan.go Outdated
Comment thread internal/pin/plan.go Outdated
… pins

Address two review findings on the --relock path:

- A moved *transitive* dep is pruned from inventory but is not a direct
  ActionRef, so partitionByInventory marked nothing unrecorded and the
  verified fast path silently dropped it at its stale SHA. Force the
  workflow's direct roots through recursive resolution when a ref-moved
  finding is present under --relock/--accept-moved, so the moved
  transitive is re-pinned to its current SHA.

- --relock must not rewrite a workflow that still carries an
  unreachable-pin finding: re-resolving a moved sibling pulls the whole
  tree (including the possibly-tampered, possibly-transitive unreachable
  dep) through resolution and would commit it at a live SHA before the
  hard-error gate runs. Leave such workflows untouched; the unreachable
  pin still fails the run. --accept-moved is exempt by design.

Add pin unit tests for both behaviours and a --relock stub scenario to
the shared catalog that bumps a moved branch ref to the live head.
@nodeselector
nodeselector merged commit 7d18df0 into main Jul 24, 2026
11 checks passed
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.

2 participants