Sub topic 4
Finding and verifying the SHA for a release
This chapter assumes you can read a workflow file and know what a Git tag is. It also assumes you have git installed and, optionally, the GitHub CLI (gh). By the end you will be able to turn a version such as v4.2.2 into the commit SHA that goes in uses:, and check that the SHA is the right one.
Why the lookup needs care
A uses: line pinned to a SHA must contain the full 40-character commit SHA. Short SHAs are rejected. A tag is only a name that points at something, and that something can be one of two kinds of object:
- A lightweight tag points directly at a commit.
- An annotated tag is its own Git object with a message and an author. That object points at a commit.
If you copy the tag object's SHA into uses:, the workflow will not resolve, because the value must be a commit. So you need the commit the tag finally points to.
Resolve a tag with git ls-remote
git ls-remote queries the remote repository without cloning it. Ask for the tag and for its dereferenced form, which is the tag name followed by ^{}:
git ls-remote https://github.com/actions/checkout 'refs/tags/v4.2.2' 'refs/tags/v4.2.2^{}'The output has one line per ref, with the SHA first and the ref name second:
<tag-object-sha> refs/tags/v4.2.2
11bd71901bbe5b1630ceea73d27597364c9af683 refs/tags/v4.2.2^{}Read the result by line count:
- Two lines means the tag is annotated. Use the SHA on the
^{}line. - One line means the tag is lightweight. Use that SHA directly.
Resolve a tag with the GitHub CLI
If you use gh, the commits endpoint accepts a tag name and returns the commit it resolves to, so you do not have to handle the annotated case yourself:
gh api repos/actions/checkout/commits/v4.2.2 --jq .shaThe command prints one 40-character SHA. It should match the ^{} line from git ls-remote. Running both gives you two independent lookups of the same fact.
Write the pin
Paste the commit SHA into uses: and put the version in a trailing comment:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2The comment is for people and tools that read the file. GitHub ignores it, so nothing checks that it is accurate. That is why the verification steps below matter.
Verify the commit
Resolving a SHA tells you what the tag says today. It does not tell you the commit is trustworthy. Check the following before you commit the change:
- Confirm the SHA is exactly 40 hexadecimal characters.
- Open
https://github.com/actions/checkout/commit/<sha>and check that the repository in the URL is the one you meant. A look-alike owner or a misspelled repository name is a common mistake. - Look for a banner on the commit page saying the commit does not belong to any branch of this repository. That banner means the commit may come from a fork. The [Impostor commits](#) chapter covers this case, so here it is enough to treat the banner as a reason to stop.
- Compare the SHA with the one shown on the project's release page for that version, if the release page lists it.
- Resolve the tag a second time with the other method, and confirm both results agree.
Common mistakes
| Mistake | Symptom | Fix |
|---|---|---|
| Using the annotated tag object's SHA | The workflow fails to resolve the action | Use the SHA on the `^{}` line |
| Using a short SHA | The reference is rejected | Use all 40 characters |
| Wrong version in the comment | The comment misleads reviewers | Re-resolve the tag and fix the comment |
| Typo in the repository owner | The commit comes from another repository | Check the owner and name in the commit URL |
Exercise
You run git ls-remote for refs/tags/v2.1.0 and refs/tags/v2.1.0^{} and get two lines. Which SHA goes in uses:, and why?
Show answer
Use the SHA on the refs/tags/v2.1.0^{} line. Two lines mean the tag is annotated, so the first line is the tag object. The ^{} line is the commit the tag points to, and uses: needs a commit SHA.
Exercise
Name two independent ways to resolve a tag to a commit SHA, and say why you would run both.
Show answer
Run git ls-remote with the tag and tag^{} refs, and run gh api repos/OWNER/REPO/commits/TAG --jq .sha. Comparing the results confirms that your lookup was not mistaken or mis-copied. Then check the commit URL for the right repository.