Sub topic 1
What a uses: reference points to
Every uses: line in a workflow tells GitHub which code to download and run. This chapter covers the parts of that line, the kinds of targets it can name, and what the part after @ actually identifies. Later chapters build on this when they pin references and enforce pinning.
Prerequisites
This chapter assumes you have:
- Written a GitHub Actions workflow with jobs and steps, and used
uses:at least once. - Used Git commits, tags, and branches, and know that a commit has a 40-character SHA.
- Seen semantic version tags such as
v4orv4.2.2. - Used a lockfile in a package manager such as npm or pip, so the idea of recording resolved versions is familiar.
The anatomy of a reference
A uses: value has up to three parts: a repository, an optional path inside it, and a ref after @.
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/analyze@v3In the first line:
actionsis the owner, an organization or user.checkoutis the repository.v4is the ref, which is the name of a tag, a branch, or a commit SHA.
In the second line, analyze is a path inside the repository github/codeql-action. One repository can host several actions in subdirectories. The ref applies to the whole repository, not to one subdirectory. All actions in that repository come from the same commit.
GitHub resolves the ref to a commit. The runner downloads the repository contents at that commit and reads an action.yml (or action.yaml) file from the root, or from the named subdirectory. That file declares how the action runs.
What the runner does with a reference
The runner resolves your references when the job starts, before any of your steps run. In the "Set up job" section of the log you will see lines like this:
Download action repository 'actions/checkout@v4' (SHA:11bd71901bbe5b1630ceea73d27597364c9af683)The log shows both the reference you wrote and the commit SHA it resolved to on that run. That second value is the code that executed. If you rerun the job later and the tag has moved, the SHA in the log changes while your workflow file stays the same.
The branch in the middle is the important part. A tag and a branch are names that can be moved. A full SHA is not a name. It is the commit's identity. Later chapters return to this difference.
The kinds of targets
The uses: key accepts several forms. They differ in where the code comes from and in what the ref means.
| Form | Example | Where the code comes from |
|---|---|---|
| Public or private action | `actions/setup-node@v4` | Another repository, at the given ref |
| Action in a subdirectory | `github/codeql-action/init@v3` | A path inside another repository |
| Local action | `./.github/actions/setup-tools` | The same repository, at the commit being built |
| Docker image | `docker://alpine:3.20` | A container registry, by tag or digest |
| Reusable workflow | `org/repo/.github/workflows/ci.yml@v1` | A workflow file in another repository |
Two of these have no @ref at all, and each lacks one for a different reason:
- Local actions (
./path) take no ref because they come from the checkout of the repository the workflow runs in. They are as fixed as your own commit. Your own code review covers them. - Docker images use the registry's own syntax, where the version after the colon is a tag and
@sha256:...is a digest.
Here is a workflow that uses several forms together:
name: ci
on: [push]
jobs:
call-shared-ci:
# A reusable workflow is referenced at the job level, not in steps
uses: my-org/shared-workflows/.github/workflows/ci.yml@v1
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-tools
- uses: docker://alpine:3.20
with:
args: echo helloNote where uses: appears. In steps, it runs an action. At the job level, it calls a reusable workflow, and that job then has no steps or runs-on of its own. Both places use the same @ref syntax, and both have the same mutability risks.
Three kinds of action
The action.yml file at the target declares one of three ways to run:
- JavaScript action. Runs a Node.js entry point directly on the runner. The code in the repository is the code that executes, often as a bundled file committed to the repository.
- Docker container action. Builds a Dockerfile or pulls an image, then runs it. The
image:field inaction.ymlcan itself point at a registry tag or digest. - Composite action. Lists a sequence of steps, and those steps can call
run:commands or other actions with their ownuses:.
This matters for what a reference really covers. When you reference a composite action, you get its action.yml at your ref. Any uses: inside it resolves by its own ref, which its author chose. Docker actions behave the same way for their image: value. A later chapter looks at that gap.
What the ref can be
After the @ you can write three things.
A tag. A tag such as v4.2.2 is a name for one commit when it is created. Many actions also publish a moving major tag such as v4. The maintainer deliberately advances it to each new v4.x.y release, so users get fixes automatically. Moving it is routine and expected.
A branch. A branch such as main points at whatever commit is at its head right now. Every push to the branch changes what your workflow runs.
A full-length commit SHA. This is the 40-character hexadecimal ID of one commit. Git computes it from the commit's contents, so no one can make the same SHA point to different code.
steps:
- uses: actions/checkout@v4 # moving major tag
- uses: actions/[email protected] # specific release tag
- uses: actions/checkout@main # branch head
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # full SHAAll four lines resolve to a commit on a given day. Only the last one resolves to the same commit tomorrow.
Which refs can change
The table summarizes how each ref type behaves. "Changes without editing your workflow" is the property that matters for supply-chain risk.
| Ref type | Example | Changes without editing your workflow? | Who can change it |
|---|---|---|---|
| Moving major tag | `v4` | Yes, by design | Maintainer, or anyone with write access |
| Release tag | `v4.2.2` | Possible | Maintainer, or anyone with write access |
| Branch | `main` | Yes, on every push | Anyone who can push to it |
| Full commit SHA | `11bd7190...` | No | Nobody |
A release tag looks fixed, but Git allows deleting a tag and creating it again at a different commit. Whoever has write access to the action's repository can do this, and so can an attacker who has stolen that access or a maintainer's credentials. Nothing in your repository changes when that happens. Your next run simply downloads different code.
That code then runs inside your job. It can read the repository contents, use the job's GITHUB_TOKEN, and read any secrets that your workflow passes to the step or exposes to the job. This is why the next chapter treats mutable references as a supply-chain risk.
Common mistakes when reading a uses: line
- Treating
v4as a version. It is a name. It tells you which line of releases the maintainer intends, not which code you get. - Assuming the code is reviewed in your repository. The action's code lives in another repository. Pull requests to your workflow show the reference change only, not the action's code.
- Forgetting job-level
uses:. Reusable workflow references are easy to miss when searchingstepsfor actions. Search the whole file. - Overlooking nested references. An action you reference may reference others. Your
uses:line is only the first level. - Reading the file but not the log. The workflow file shows what you asked for. The "Set up job" log shows what ran.
Reading your own workflows
A quick audit of what you depend on can start with a plain search for every uses: line:
grep -rn "uses:" .github/workflows .github/actionsFor each result, note three facts: whether the target is local, Docker, or a remote repository; whether it sits in steps or at the job level; and whether the ref is a tag, a branch, or a full SHA. This list is the starting inventory for the rest of the tutorial. Remote references with tags or branches are the ones that can change under you.
Exercise
A workflow contains these three lines. For each, say where the code comes from and whether the reference can change without anyone editing the workflow file: (1) uses: actions/setup-node@v4, (2) uses: ./.github/actions/lint, (3) uses: my-org/tools/.github/workflows/test.yml@4f2a9c1e7b0d3a58c6e1f9b2d4a7c0e3b5d8f1a6.
Show answer
(1) The code comes from the actions/setup-node repository at whatever commit the v4 tag points to. The maintainer moves v4 on each release, so it can change without any edit to your file. (2) The code comes from the same repository, at the commit being built. It changes only when a commit in your repository changes it, so it goes through your own review. (3) This is a reusable workflow in my-org/tools, pinned to a full 40-character commit SHA. It cannot change without an edit to your workflow, because a SHA identifies one commit.
Exercise
In a job log you see "Download action repository 'actions/checkout@v4' (SHA:11bd71901bbe5b1630ceea73d27597364c9af683)". Next week the same job's log shows a different SHA, though nobody edited the workflow. What most likely happened, and where do you look to confirm it?
Show answer
The maintainers moved the v4 tag to a newer release commit, so the same reference resolved to different code. Confirm by comparing the "Set up job" section of both runs, which shows the resolved SHA each time, and by checking the tag history in the action's repository.