Add sentinel comment to managed workflow files by nodeselector · Pull Request #61 · github/gh-actions-lock · GitHub
Skip to content

Add sentinel comment to managed workflow files - #61

Merged
nodeselector merged 4 commits into
mainfrom
nodeselector/sentinel-comment-managed-wfs
Jun 18, 2026
Merged

nodeselector merged 4 commits into
mainfrom
nodeselector/sentinel-comment-managed-wfs

Conversation

@nodeselector

Copy link
Copy Markdown
Collaborator

When gh actions-lock rewrites a workflow file to pin action refs, there's no
visible indicator that the file is under lockfile management. This makes it easy
for someone editing a workflow to not realize their uses: lines are locked and
will be overwritten on the next pin run.

This adds a sentinel comment -- # This workflow is managed by gh actions-lock.
-- prepended to workflow files during the commit phase. The comment is:

  • Idempotent: skipped if the sentinel is already present, so re-pinning
    doesn't stack duplicate comments.
  • Minimal: a single line at the top of the file, separated from the YAML
    body by a blank line (or merged with existing leading comments).
  • Scoped to rewrites: only applied when rewriteWorkflow actually changes
    uses: lines -- workflows with no rewrites are untouched.

Inspired by this Slack thread
discussing how to signal lockfile management at a glance.

Prepend "# This workflow is managed by gh actions-lock." to the top of
workflow files when they are rewritten during pin commit. The comment is
idempotent — skipped if already present — and separated from the YAML
body by a blank line.
Copilot AI review requested due to automatic review settings June 18, 2026 17:24
GitHub Advanced Security started work on behalf of nodeselector June 18, 2026 17:24
GitHub Advanced Security finished work on behalf of nodeselector June 18, 2026 17:26
Previously rewriteWorkflow bailed early when there were no rewrites,
so already-pinned workflows never got the sentinel comment. Now every
workflow in the plan gets EnsureSentinel applied, with a bytes.Equal
check to avoid unnecessary disk writes.
GitHub Advanced Security started work on behalf of nodeselector June 18, 2026 17:28

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

Sentinel insertion logic and commit-phase application don’t fully match the stated “only when uses: lines actually change” behavior and can fail to prepend the sentinel when the text appears later in the file.

Pull request overview

Adds a single-line sentinel comment to the top of workflow files that gh actions-lock rewrites, so it’s obvious the workflow is lockfile-managed.

Changes:

  • Introduce EnsureSentinel (and SentinelComment) to prepend # This workflow is managed by gh actions-lock. to workflow content.
  • Add unit tests covering sentinel insertion behavior.
  • Call EnsureSentinel during the commit-phase workflow rewrite.
File summaries
File Description
internal/workflowfile/rewrite.go Adds sentinel constant and helper to prepend the management comment to rewritten workflow content.
internal/workflowfile/rewrite_test.go Adds tests for sentinel insertion/idempotency scenarios.
internal/pin/commit.go Applies the sentinel during workflow rewrites in the commit phase.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

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/workflowfile/rewrite.go
Comment thread internal/pin/commit.go Outdated
GitHub Advanced Security finished work on behalf of nodeselector June 18, 2026 17:29
bytes.Contains would miss prepending if the sentinel text appeared
elsewhere in the file (e.g. in a run: block or unrelated comment).
Switch to bytes.HasPrefix so we only skip when it is already at the
top.
GitHub Advanced Security started work on behalf of nodeselector June 18, 2026 18:33
GitHub Advanced Security finished work on behalf of nodeselector June 18, 2026 18:34
Every workflow that goes through planWorkflow now gets a WorkflowPlan
entry even when there are no rewrites (already pinned, partial failure,
impostor blocked, etc). The rewriteWorkflow function applies
EnsureSentinel to all of them, with bytes.Equal preventing unnecessary
disk writes when nothing changed.
GitHub Advanced Security started work on behalf of nodeselector June 18, 2026 19:09
GitHub Advanced Security finished work on behalf of nodeselector June 18, 2026 19:11
@nodeselector
nodeselector merged commit bba6c96 into main Jun 18, 2026
12 of 13 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