Sub topic 10
Generating, reviewing, and updating a lockfile
This chapter covers the day-to-day work of keeping a workflow dependency lockfile. It assumes you have read the earlier chapters. You should know how a uses: reference resolves to a commit and why a top-level SHA pin leaves nested actions unpinned. You should also be comfortable reading a git diff and a pull request.
Lockfile tooling for workflows is still young, and command names and file formats differ between tools. The file format below is a small teaching format, not the format of a specific product. The lifecycle is the same for any tool: generate, review, verify, update. Where the chapter says "your tool", substitute its generate and update commands.
What the lockfile records
A package lockfile such as package-lock.json records the exact resolved version of every direct and transitive dependency. A workflow lockfile does the same for actions and reusable workflows. For each dependency it needs three things:
- The reference as written in your workflow, such as
actions/checkout@v4. - The full-length commit SHA that reference resolved to when the lockfile was generated.
- The references that dependency itself uses, so nested actions are covered too.
Here is an example in the teaching format. The checkout SHA is the one used earlier in this tutorial. The other SHA is a placeholder.
{
"version": 1,
"dependencies": {
"actions/checkout@v4": {
"sha": "11bd71901bbe5b1630ceea73d27597364c9af683",
"resolved": "v4.2.2",
"requires": []
},
"some-org/some-action@v1": {
"sha": "0123456789abcdef0123456789abcdef01234567",
"resolved": "v1.3.0",
"requires": ["other-org/inner-action@v2"]
},
"other-org/inner-action@v2": {
"sha": "89abcdef0123456789abcdef0123456789abcdef",
"resolved": "v2.0.4",
"requires": []
}
}
}Your workflow files keep the readable reference (@v4). The lockfile supplies the SHA at run time. This is the main difference from manual pinning, where the SHA is written into every uses: line and nested actions stay out of your reach.
The lifecycle
Generating the lockfile
Generation reads every workflow and composite action in the repository. For each uses: reference it resolves the tag or branch to a commit SHA, then repeats this for the action's own references until nothing new appears.
A few points matter when you first generate one:
- Generate from a clean default branch. If you generate on a branch with half-finished workflow edits, the lockfile records dependencies you may drop.
- Expect a large first diff. A workflow with five direct actions can pull in a dozen nested ones. Every one of those nested actions was already running in your pipeline. The lockfile only makes them visible.
- Treat the first lockfile as a baseline you must audit once. Generation records what the tags point to right now. It cannot tell you whether that is what the tags pointed to last month. If you suspect a past compromise, check the commits against release notes and the upstream repository before you trust the baseline.
- Commit it next to the workflows. The lockfile belongs in the same pull request as the workflow change that required it, so reviewers see both together.
If a reference cannot be resolved, for example a deleted tag or a private action your token cannot read, generation should fail. A tool that skips unresolved entries leaves a silent gap.
Verifying the lockfile in CI
A lockfile helps only if something checks that it matches the workflows. Otherwise someone adds a new uses: line, forgets to regenerate, and the new dependency is unpinned again. Your tool may include a check command. Where it doesn't, a small script covers the basics. This one is a standalone Python 3 script that uses only the standard library and the teaching format above. It reports workflow references missing from the lockfile, entries that are not valid 40-character SHAs, nested references that have no entry, and stale entries nothing uses.
import json
import re
import sys
from pathlib import Path
USES = re.compile(r"^\s*-?\s*uses:\s*(\S+)", re.M)
SHA = re.compile(r"^[0-9a-f]{40}$")
def workflow_refs(root: Path) -> set[str]:
refs = set()
for path in sorted((root / ".github" / "workflows").glob("*.y*ml")):
for raw in USES.findall(path.read_text()):
ref = raw.split("#")[0].strip("\"'")
if ref.startswith(("./", "docker://")):
continue # local actions and image refs are handled elsewhere
refs.add(ref)
return refs
def main() -> int:
root = Path(".")
deps = json.loads((root / ".github" / "workflows.lock.json").read_text())["dependencies"]
direct = workflow_refs(root)
nested = {r for entry in deps.values() for r in entry.get("requires", [])}
problems = []
for ref in sorted(direct):
if ref not in deps:
problems.append(f"missing from lockfile: {ref}")
for ref in sorted(nested):
if ref not in deps:
problems.append(f"nested dependency has no entry: {ref}")
for ref, entry in sorted(deps.items()):
if not SHA.match(entry.get("sha", "")):
problems.append(f"not a full-length SHA: {ref}")
if ref not in direct and ref not in nested:
problems.append(f"stale entry, nothing uses it: {ref}")
for line in problems:
print(line)
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main())Run it as a CI step before any job that uses third-party actions, and make the step required for merging. The script checks consistency only. It does not re-resolve tags, so it cannot tell you the SHAs are correct. Your tool's own verify command should do that.
Reviewing a lockfile diff
Reviewing is where a lockfile earns its place. A change to a floating tag normally produces no diff at all. A change to the lockfile produces a diff you can read.
Read each changed entry in this order:
- Which dependencies changed? Compare the list with what you expected. An update bot that bumps checkout should not also change an unrelated action.
- Did any new nested dependency appear? A new entry in
requiresmeans an action you already use started calling something new. This is the most important thing to notice, because it is code you never reviewed before. - Does the
resolvedversion look like a normal progression?v4.2.1tov4.2.2is routine. A jump across a major version, or a SHA change whileresolvedstays the same, needs an explanation. - What changed between the old and new commit? Look at the upstream comparison, not just the version number.
For the last step you can ask the GitHub API for the comparison between two commits. This prints how many commits the update contains and the files it touches:
OLD=11bd71901bbe5b1630ceea73d27597364c9af683
NEW=<new-sha-from-the-lockfile-diff>
gh api "repos/actions/checkout/compare/${OLD}...${NEW}" \
--jq '{ahead_by: .ahead_by, files: [.files[].filename]}'Look closely at changes to action.yml, shell scripts, and any bundled dist/ output. Bundled JavaScript is hard to read, so also confirm that the source change explains the bundle change.
Also confirm that the new SHA belongs to the repository you meant. A SHA in a lockfile entry can name a commit that exists only in a fork. The earlier chapter on impostor commits explains the mechanism. In review, check that the commit appears in the upstream repository's history or in a release.
Updating the lockfile
Updates have two sources. A bot proposes them on a schedule, or a developer runs the update command by hand. Both should produce the same artifact: a pull request whose diff is the lockfile, plus a workflow edit only if the reference itself changed.
- Update one dependency at a time when you can. Small diffs are reviewable, and a failing build points at one cause.
- Separate security updates from routine ones. A fix for a known vulnerability should merge fast, and a batch of weekly bumps should not delay it.
- Regenerate rather than hand-edit. Editing a SHA by hand skips resolution, so the nested
requireslist falls out of date. - Keep Dependabot for direct references. If some workflows still pin by SHA directly, the Dependabot configuration from the earlier chapter keeps working beside the lockfile. Check that your tool does not produce two competing pull requests for the same action.
After each merge, CI should run the verify step again. If the update pull request was approved but an unrelated workflow edit landed first, the lockfile may no longer match.
Failure modes
| Problem | Symptom | Response |
|---|---|---|
| Lockfile out of date | Verify step reports a missing entry | Regenerate in the same pull request as the workflow edit |
| Generation fails on one reference | Tag deleted or repository private | Fix the reference. Do not skip it |
| Bot opens an enormous diff | Many nested changes in one bump | Review upstream changes, or update one dependency at a time |
| SHA not found upstream | Commit exists only in a fork | Reject. Re-resolve against the intended repository |
| Reviewers approve without reading | Lockfile diffs look like noise | Require the nested-dependency check in the review template |
What the lockfile still does not do
The lockfile fixes what runs. It does not make what runs trustworthy. A pinned malicious commit stays malicious. Docker images referenced by tag inside an action, and scripts an action downloads at run time, are outside what a uses: lockfile can record unless your tool says it covers them. Keep that boundary in mind when you decide how much review the update pull requests deserve.
Exercise
A pull request updates a workflow lockfile. The only visible change is that some-org/some-action@v1 moves to a new SHA, and its requires list gains a new entry, unknown-org/helper@main. The resolved version label is unchanged. Name two things you would check before approving and one reason this change deserves extra scrutiny.
Show answer
Check that the new SHA belongs to the intended upstream repository and see what changed between the old and new commits, for example with the compare API. Also check why resolved did not change and why the action now depends on unknown-org/helper. The change deserves extra scrutiny because a new nested dependency is code your pipeline never ran before. It is also referenced by the branch main, which is a mutable reference, so the lockfile entry for it will pin whatever main pointed to at generation time and may later change on update.