How to Set Default Input Values in a Custom Action
The default key on an input supplies a value when the caller omits it in with.
Add default: under an input. When a workflow does not pass that input, the runner uses the default, which stays a string like every other input.
Steps
- Declare the input under
inputs:inaction.yml. - Add
default:with the fallback value. - Callers may still override it with
with:.
action.yml
action.yml
inputs:
node-version:
description: 'Node major version'
default: '20'
cache:
description: 'Enable dependency cache'
default: 'true'
runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}Gotchas
- Defaults are strings; a boolean-looking default is still
'true'or'false'. - An input with a default cannot also be
required: truemeaningfully.
Related guides
How to Mark an Input Required in a Custom ActionMark a custom action input as required in action.yml and validate it at runtime, since the runner does not ha…
How to Add Inputs and Outputs to a Composite ActionDeclare inputs and outputs on a composite action, read inputs with the inputs context, and map a step output…
How to Validate Inputs in a Custom ActionValidate custom action inputs at runtime by checking allowed values and formats, then failing with ::error::…