Sub topic 5
Passing inputs
This chapter assumes you can write a basic workflow, and that you have seen workflow_call and a jobs.<job_id>.uses call. Here you will see how a caller sends values to a reusable workflow and how the called workflow reads them.
How inputs flow
A reusable workflow declares its inputs under on.workflow_call.inputs. The caller supplies values with with: on the job that uses the workflow. Inside the called workflow, you read each value through the inputs context.
Declaring inputs
Each input has these fields:
| Field | Meaning |
|---|---|
| `type` | Required. One of `string`, `number`, or `boolean`. |
| `required` | Whether the caller must supply a value. |
| `default` | Value used when the caller omits the input. |
| `description` | Optional text for readers. |
This is the called workflow from the spine:
# .github/workflows/node-test.yml
name: Node test
on:
workflow_call:
inputs:
node-version:
description: Node.js version to use
type: string
required: false
default: '20'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm ci
- run: npm testThe version is quoted because '20' must be a string. An unquoted 20 is a YAML number and does not match type: string.
Supplying inputs from the caller
The caller passes values under with:. The names must match the declared inputs.
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
call-test:
uses: my-org/shared-workflows/.github/workflows/node-test.yml@v1
with:
node-version: '22'If the caller leaves out node-version, the called workflow uses '20'.
Using inputs in a matrix
Inputs can come from expressions, including the matrix context. This starts one run of the called workflow for each Node version:
jobs:
test:
strategy:
matrix:
node: ['18', '20', '22']
uses: ./.github/workflows/node-test.yml
with:
node-version: ${{ matrix.node }}What `with:` accepts
Values in with: can be literals or expressions that use the github, needs, vars, and inputs contexts, plus matrix when the job has a strategy. The env context is not available there, and neither is secrets. Secrets have their own secrets: block, covered in the next chapter.
Inputs are plain data. Do not pass sensitive values as inputs, because inputs can appear in logs and in the workflow run's metadata.
Common errors
- Unexpected input. The caller passes a name the called workflow does not declare. The run fails validation. Check spelling and case.
- Missing required input. An input has
required: trueand no value was supplied. The workflow fails before any job starts. - Type mismatch. The caller passes a value that does not fit the declared type, for example a string where
type: booleanis declared. Usetrueorfalse, not'true'. - Unquoted version numbers.
node-version: 20is a number. Fortype: string, quote it. Unquoted3.10also becomes3.1. - Using the
envcontext inwith:. Theenvcontext is unavailable on a job that calls a workflow. Usevarsor a literal instead.
Exercises
Exercise
A reusable workflow declares retries with type: number and default: 3. The caller does not set retries. What does ${{ inputs.retries }} evaluate to inside the called workflow?
Show answer
It evaluates to 3, the declared default. Defaults apply whenever the caller omits the input.
Exercise
A caller job uses a reusable workflow and writes with: { dry-run: 'true' }, but the called workflow declares dry-run as type: boolean. What is wrong, and how do you fix it?
Show answer
The value is a string, which does not match the boolean type. Write dry-run: true without quotes.