Sub topic 9
Building on other actions
This chapter covers calling other actions from inside a composite action. It assumes you can write an action.yml with inputs and composite steps, and that you know why every run step needs a shell.
Calling an action with uses
A composite action can call another action with uses, the same way a workflow job does. This lets you wrap common setup actions, such as actions/setup-node, together with your own steps. Callers then need only one uses line.
Steps that call an action differ from run steps in two ways:
- They do not take a
shellkey, because the called action defines how it runs. - They pass data through
with, andwithvalues can read your action's inputs through theinputscontext.
The example below installs Node.js, installs dependencies, and optionally runs tests.
name: Node setup and test
description: Install Node.js, install dependencies and optionally run tests
inputs:
node-version:
description: Node.js version
required: false
default: "20"
run-tests:
description: Set to 'true' to run the test suite
required: false
default: "true"
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
- shell: bash
run: npm ci
- if: ${{ inputs.run-tests == 'true' }}
shell: bash
run: npm testThe first step passes the action's node-version input to setup-node. The last step is skipped unless run-tests equals the string 'true'.
Conditions and input types
Inputs are always strings, even when a caller writes run-tests: true. Compare against the string form, as in inputs.run-tests == 'true'. Comparing against a boolean can behave in ways you do not expect.
A step's if works as it does in workflows. Without it, a step runs only while previous steps have succeeded. Add if: ${{ always() }} or failure() when you need cleanup or reporting.
Pin the versions you call
Every action you call becomes a dependency of your action. Keep these habits:
- Pin to a major tag, such as
@v4, for convenience. - Pin to a full commit SHA for third-party actions when supply-chain safety matters more than convenience.
- Update pinned versions on purpose, and test after each update.
Common errors
- Adding
shellto ausesstep. Remove it. It is only forrunsteps. - Passing a boolean and comparing it as one. Compare strings.
- Expecting secrets inside the called action. The
secretscontext is not available in composite actions. Pass secrets in as inputs from the workflow and forward them withwith. - Assuming the checkout exists. A composite action runs in the caller's workspace. If your action needs the repository's files, the workflow must run
actions/checkoutfirst. Theusessteps inside your action do not do this for you.
Exercise
A composite action has an input run-tests with default "true". A caller passes run-tests: false. Which if expression correctly skips the test step, and why does a boolean comparison risk being wrong?
Show answer
Use if: ${{ inputs.run-tests == 'true' }}. The step runs only when the string equals 'true', so the string 'false' skips it. Inputs reach the action as strings, so a comparison written as if the value were a boolean can behave unexpectedly.
Exercise
You add shell: bash to a step that has uses: actions/setup-node@v4. What should you do, and why?
Show answer
Remove shell. It is only valid on run steps. A uses step runs the called action's own definition.