Sub topic 13
Nesting reusable workflows and platform limits
This chapter assumes you can already define a reusable workflow with workflow_call, call it from a job, and pass inputs, secrets and outputs. Here you will see how a reusable workflow can call another one, and which limits to design around.
How nesting works
A reusable workflow can call another reusable workflow. The same jobs.<job_id>.uses syntax applies. The workflow at the top is the top-level caller. Each workflow it calls can call further workflows.
Here is a middle-level workflow that calls two others:
# .github/workflows/release.yml
name: Release
on:
workflow_call:
inputs:
version:
type: string
required: true
secrets:
npm_token:
required: true
jobs:
build:
uses: ./.github/workflows/build.yml
publish:
needs: build
uses: ./.github/workflows/publish.yml
with:
version: ${{ inputs.version }}
secrets:
npm_token: ${{ secrets.npm_token }}The top-level caller passes version and npm_token to release.yml. That workflow then forwards what publish.yml needs. Each level must pass data on explicitly, or use secrets: inherit.
Limits to design around
The limits below come from the current GitHub documentation. Check the docs before you rely on exact numbers, because GitHub has raised them over time.
| Limit | Value |
|---|---|
| Nesting depth | Up to 10 levels: the top-level caller plus up to 9 levels of reusable workflows |
| Unique reusable workflows per workflow file | Up to 50, counting the workflows called by nested workflows |
| Loops | Not allowed. A workflow cannot call itself, directly or through another workflow. |
A job that uses uses: is a call job. It cannot also have steps or runs-on. If you need to run a script before the call, put it in a separate job and connect the two with needs.
What flows through the chain
- Permissions can only stay the same or shrink at each level. A nested workflow can never gain more
GITHUB_TOKENaccess than its caller gave it. - Secrets reach a nested workflow only if each level passes them.
secrets: inheritpasses along all secrets the caller can access, and you can repeat it at each level. - Outputs travel upward one level at a time. To expose a nested output to the top-level caller, map it again in each
workflow_call.outputsblock. - Workflow-level
envset in a caller is not propagated to the called workflow. Pass values as inputs instead.
# In release.yml: re-export an output from the nested build workflow
on:
workflow_call:
outputs:
artifact-name:
value: ${{ jobs.build.outputs.artifact-name }}
jobs:
build:
uses: ./.github/workflows/build.ymlFor jobs.build.outputs.artifact-name to resolve, build.yml must declare that output under its own workflow_call.outputs.
Common failures
- Startup failure with a depth or count error. The chain is too deep, or one file references too many unique workflows. Flatten the structure by combining small workflows.
- A cycle. Workflow A calls B, and B calls A. GitHub rejects this, so redraw the dependency as a one-way chain.
- Empty secret in a nested workflow. An intermediate workflow did not declare the secret, or did not forward it.
- Missing output at the top. One level in the chain did not re-map the output.
Design guidance
Deep chains are hard to debug. The run log shows each called workflow as a nested group, and every level adds an interface of inputs, secrets and outputs that you must keep in sync. Prefer two or three levels at most. When you only need to share a few steps, a composite action avoids the nesting entirely.
Exercise
The top-level workflow ci.yml calls release.yml, which calls publish.yml. publish.yml reads secrets.npm_token, but the value is empty. ci.yml uses secrets: inherit. Name one likely cause in release.yml.
Show answer
release.yml did not pass the secret on to publish.yml. It needs either secrets: inherit on the publish job or an explicit secrets: npm_token: ${{ secrets.npm_token }} mapping (with npmtoken also declared under workflowcall.secrets).
Exercise
Can a job that calls a reusable workflow also include a steps list?
Show answer
No. A job with uses: cannot have steps or runs-on. Put those steps in a separate job and order the two with needs.