Sub topic 5
Keeping Pins Readable with Version Comments
This chapter assumes you can read a workflow file, know that uses: references an action, and understand the difference between a Git tag and a commit. It also assumes you have seen why a full-length commit SHA is safer than a tag. Here the focus is on the cost of that safety: a 40-character hash tells a human almost nothing.
The readability problem
Compare these two lines:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683The first is easy to read. The second is safe but opaque. In a review you cannot tell which release it is, whether it is old, or whether someone swapped in a different commit. A trailing YAML comment fixes the first two problems without affecting how the workflow runs.
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2GitHub ignores everything after #. The comment is for people and for tools that read it. It does not change what runs.
What to write in the comment
Use the most specific version you resolved, not just the major tag.
| Comment | Quality | Reason |
|---|---|---|
| `# v4` | Weak | A moving tag. Many commits could match it over time. |
| `# v4.2.2` | Good | Names one release, so a reader can look it up. |
| `# latest` | Poor | Says nothing about the code you actually run. |
| `# main` | Poor | Records a branch, which is the thing you were avoiding. |
Keep the comment on the same line as uses:. Tools that update pins look for it there.
The comment is not verified
This is the main gotcha. GitHub does not check that the comment matches the SHA. Someone can change the hash and leave # v4.2.2 in place, and the file still runs. A reviewer who trusts the comment is then misled.
You can check one pin by asking the remote repository which commit a tag resolves to:
git ls-remote https://github.com/actions/checkout 'refs/tags/v4.2.2' 'refs/tags/v4.2.2^{}'If the tag is annotated, the second line (the one ending in ^{}) gives the commit. That value should equal the SHA in your workflow. If the tag is lightweight, only the first line appears, and it is already the commit.
How comments and updates work together
Dependabot reads the version comment, and it rewrites both the SHA and the comment when it proposes an update. A pull request then looks like this:
# Before
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# After (Dependabot rewrites the SHA and the comment together)
- uses: actions/checkout@<new-40-character-sha> # v4.3.0Because the comment is updated in the same change, the diff shows both the new hash and a human-readable jump from one version to another. Reviewers can judge the size of the change from the comment, then spot-check the hash. If you edit pins by hand, update the comment in the same commit, or the file will drift out of sync.
flowchart TDHabits that keep pins readable
- Put the full version, such as
v4.2.2, in a comment on the same line. - Update the comment whenever you change the SHA.
- Use the same comment style across all workflows so searches work. For example,
grep -rn "uses:.*# v"lists every annotated pin. - Search for pins that lack a comment and fix them.
grep -rnE "uses: [^ ]+@[0-9a-f]{40}\s*$" .github/workflowsThis command prints lines that have a 40-character SHA and nothing after it, which are the pins missing a version comment.
Exercise
A pull request changes uses: actions/checkout@<sha-A> # v4.2.2 to uses: actions/checkout@<sha-B> # v4.2.2. The comment did not change. What should the reviewer do, and why?
Show answer
Treat it as suspicious or incomplete. The SHA changed but the version comment did not, so either the author forgot to update the comment, or the new SHA does not correspond to v4.2.2. The reviewer should run git ls-remote against the action's repository for the tag named in the comment and compare the result to sha-B. If they differ, ask for a correction. GitHub does not validate comments, so the check must be done by a person or a tool.