Sub topic 4
Calling a reusable workflow from a job
This chapter assumes you can write a workflow with events, jobs and steps. It also assumes you have read the previous chapter, where a workflow declares on: workflow_call. Here you call that workflow from another one.
Calling is a job-level operation
You call a reusable workflow with the uses key on a job. This differs from calling an action, where uses sits on a step. A job that has uses is a caller job. It runs no steps of its own. Its whole body is the called workflow.
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
call-test:
uses: ./.github/workflows/node-test.ymlThis job calls node-test.yml from the same repository. The path starts with ./ and points into .github/workflows. A same-repository call runs the called file from the same commit as the caller. The two files cannot drift apart on a branch.
Calling a workflow in another repository
For a workflow in a different repository, use {owner}/{repo}/{path}@{ref}.
jobs:
call-test:
uses: my-org/shared-workflows/.github/workflows/node-test.yml@v1
with:
node-version: '22'
secrets:
npm_token: ${{ secrets.NPM_TOKEN }}The @ref part is required here. It can be a tag, a branch, or a full commit SHA. Later chapters cover how to choose one. The with: and secrets: keys feed the inputs and secrets that the called workflow declared. Those keys get their own chapters.
What a caller job may contain
A caller job accepts only a small set of keys.
| Key | Purpose |
|---|---|
| `uses` | Path to the reusable workflow |
| `with` | Input values |
| `secrets` | Secret values, or `inherit` |
| `needs` | Run after other jobs |
| `if` | Run conditionally |
| `permissions` | Limit the `GITHUB_TOKEN` |
| `strategy` | Run the call as a matrix |
| `concurrency` | Control concurrent runs |
| `name` | Label in the run graph |
Keys that describe where and how steps run do not belong here. These include runs-on, steps, env, defaults and container. The called workflow defines its own runners and steps.
You can order caller jobs like any other jobs:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "lint passed"
call-test:
needs: lint
if: github.event_name == 'pull_request'
uses: ./.github/workflows/node-test.ymlHere a normal job and a caller job share one workflow. call-test waits for lint and runs only on pull requests.
How a call looks at run time
In the run graph, the called jobs appear nested under the caller job. Their names combine both parts, such as call-test / test. Use the name: key on the caller job to make this readable.
Common errors
useson a step. A step'susesaccepts actions, not workflow files. Move the call to the job level.- Adding
stepsorruns-onto the caller job. The workflow file is invalid. Remove them. - Expressions in
uses. A value such as@${{ vars.REF }}is not allowed. Write the path and ref literally. - Missing
workflow_call. If the called file lackson: workflow_call, the call fails. - Wrong path. The file must be directly in
.github/workflows. Subdirectories are not supported.
Exercise
A teammate writes a job with runs-on: ubuntu-latest, uses: ./.github/workflows/build.yml, and a steps: list. Why does this fail, and how do you fix it?
Show answer
A job that sets uses to a workflow file is a caller job, and caller jobs cannot have runs-on or steps. Remove both keys from that job. If extra steps are needed, put them in build.yml or in a separate normal job that uses needs to order it.