Sub topic 9
Workflow dependency lockfiles: the idea
This chapter assumes you can read a GitHub Actions workflow, know that uses: references an action, and have used a lockfile such as package-lock.json or requirements.txt with hashes. The previous chapters covered pinning by hand. Here you learn what a lockfile adds, before the next chapter shows how to work with one.
The gap that manual pinning leaves
Pinning actions/checkout to a full-length commit SHA fixes the code of that one action. But an action can call other actions. A composite action lists its own steps, and each step can have its own uses: line. A reusable workflow can do the same.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/setup-tools # local composite action
# If setup-tools internally uses: some-org/some-action@v1,
# that inner reference is resolved by its own tag, not by a pin here.Your workflow can be fully pinned and still run code that nobody pinned. The inner reference is controlled by the author of the outer action. If they used a tag, that tag can move. These are transitive dependencies: dependencies of your dependencies.
You can pin the inner actions yourself only if you read every action's source and copy each inner reference into your workflow, which doesn't scale. Even then, your pin on the outer action would not stop its inner references from changing, unless the outer action is also pinned to a commit whose own references are SHAs.
What a lockfile is
If you have used npm or pip, you already know the idea. A package.json states what you want, such as ^4.0.0. A lockfile records what the resolver chose: exact versions of every direct and transitive package, usually with integrity hashes. Installs then reproduce the same tree until someone deliberately updates the lockfile.
A workflow dependency lockfile applies this to uses: references. The workflow keeps readable references, and the lockfile holds the resolved result.
| Piece | Role | Who edits it |
|---|---|---|
| Workflow file | States intent, such as `actions/checkout@v4` | You |
| Lockfile | Records the commit SHA that each reference resolved to, for the whole dependency tree | A tool, then reviewed by you |
A lockfile entry needs enough information to identify one piece of code exactly:
- The action or reusable workflow, by repository and path.
- The reference you asked for, such as a tag.
- The full commit SHA it resolved to.
- Which dependency pulled it in, so nested entries trace back to a top-level one.
How it differs from manual pinning
Manual pinning puts the SHA in the workflow. A lockfile separates the two concerns, and the lock covers more ground.
| Question | Manual SHA pinning | Lockfile |
|---|---|---|
| Where is the exact commit recorded? | Inline in each `uses:` line | In a separate generated file |
| Are transitive dependencies covered? | Only if their authors pinned them | Yes, they are resolved and recorded |
| Is the workflow easy to read? | Needs version comments | Keeps the readable reference |
| How does an update look in review? | One changed line per action | A diff of resolved entries, including nested ones |
The last row matters most for security. When a nested dependency changes, a lockfile diff shows it. With manual pinning, the change never reaches your repository's history at all.
What a lockfile does not do
A lockfile guarantees repeatability, not safety. If you lock a malicious commit, you reproduce the malicious commit every time. You still need to review what changes when the lock is updated. A lockfile also protects only the workflows and tools that read it. A pinned reference that bypasses the lock is still pinned manually.
The next chapter shows how to generate, review, and update a lockfile.
Exercise
A workflow pins some-org/deploy@<full SHA>. The deploy action is a composite action whose steps use helper-org/cache@v3. Does the pin protect you if the v3 tag of helper-org/cache is moved to a malicious commit? How would a lockfile change that?
Show answer
No. The pin fixes only the deploy action's code. Its inner reference helper-org/cache@v3 is still resolved by tag, so the moved tag would run the new commit. A lockfile resolves and records the SHA of helper-org/cache as a transitive dependency, so the workflow keeps using the recorded commit. Any change would then show up as a reviewable diff in the lockfile.