Sub topic 3
Referencing an action with uses
This chapter assumes you can read a workflow file and know its parts: events, jobs, and steps. It covers the syntax of the uses keyword, the three forms a reference can take, and the errors that appear when a reference is wrong.
What a reference contains
A step runs either a shell command (run) or an action (uses). A step cannot have both. The value of uses tells the runner where to find the action's code and which version to fetch.
For an action hosted on GitHub, the pattern is:
{owner}/{repo}@{ref}owneris the user or organization that owns the repository.repois the repository that contains the action.refis a Git tag, branch, or commit SHA. It selects the version.
In actions/checkout@v4, the owner is actions, the repository is checkout, and the ref is the tag v4. The runner downloads that repository at that ref before the step runs.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20The ref is required for actions from GitHub repositories. Writing uses: actions/checkout fails with a parse error.
Three kinds of location
The same keyword can point at three places.
| Form | Example | Where the code comes from |
|---|---|---|
| Repository action | `actions/checkout@v4` | A public repository on GitHub |
| Action in a subdirectory | `owner/repo/path/to/action@v1` | A folder inside a repository |
| Local action | `./.github/actions/my-action` | A folder in your own repository |
| Docker image | `docker://alpine:3.20` | A container image from a registry |
Three details matter here.
- Some repositories hold several actions, each in its own folder. You add the folder path after the repository name and before the
@. For example,github/codeql-action/init@v3andgithub/codeql-action/analyze@v3are two different actions from one repository. - A local action uses a path that starts with
./and has no@ref. It is read from the checked-out workspace, so you must runactions/checkoutfirst. Without it, the path does not exist yet. - A Docker reference runs an image directly. Pin it to a specific tag, or better, a digest.
How the runner resolves a reference
Resolution happens at the start of the job, before any step runs. If a reference cannot be resolved, the job fails immediately, and no earlier steps in that job will have executed.
Choosing the ref
The ref decides how much the action's behavior can change under you. A short summary follows, and a later chapter covers the trade-offs in detail.
- A major tag such as
@v4is easy to read and receives compatible fixes automatically. The maintainer can move the tag, so the code behind it can change. - A full tag such as
@v4.1.7is more specific, but tags can still be moved or deleted. - A full-length commit SHA is immutable and gives you exactly the code you reviewed.
steps:
# Replace the placeholder with the full 40-character commit SHA you reviewed.
- uses: actions/checkout@<full-length-commit-sha> # v4A short SHA is not accepted. Use all 40 characters.
Common errors
| Message or symptom | Likely cause | Fix |
|---|---|---|
| `Unable to resolve action, repository not found` | A typo in `owner/repo`, or the repository is private and not shared with yours | Check spelling and the repository's visibility |
| `Unable to resolve action, unable to find version` | The tag, branch, or SHA does not exist | Check the ref on the repository's tags or releases page |
| `Can't find 'action.yml'` | The path points at a folder with no `action.yml` or `action.yaml` | Correct the subdirectory path |
| A local action cannot be found | `actions/checkout` has not run yet | Add the checkout step before the local reference |
| The step is rejected by policy | The repository or organization restricts which actions may run | Ask an administrator to allow it |
Exercise
A workflow has the step - uses: ./.github/actions/lint as the first step of a job, and it fails with a message that the action cannot be found, even though the folder exists in the repository. What is wrong, and how do you fix it?
Show answer
Local actions are read from the workspace, and the workspace is empty until the repository is checked out. Add - uses: actions/checkout@v4 as a step before the local action.
Exercise
What are the owner, repository, subdirectory, and ref in github/codeql-action/analyze@v3?
Show answer
The owner is github, the repository is codeql-action, the subdirectory is analyze, and the ref is v3.