Sub topic 9
Building on other actions
What you can call from a composite action
A composite action is a list of steps, and each step can be a run step or a uses step. A uses step calls another action. It can be a marketplace action, an action in another repository, or an action in the same repository.
This lets you build on existing work. You don't reimplement Node.js installation or caching. You wrap actions/setup-node or actions/cache and add your project's conventions around it.
This chapter assumes you know how a composite action declares inputs and outputs, and why every run step needs a shell. It covers how the pieces fit together when your action calls other actions.
A uses step in practice
This action installs Node.js, installs dependencies, and optionally runs the tests. It combines a nested action with run steps.
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 testThree points about the uses step:
- It takes no
shell. The nested action decides how it runs. Onlyrunsteps needshell. - Its
withblock can read the composite action's own inputs through theinputscontext. Hereinputs.node-versionflows intoactions/setup-node. - It runs in the same job and on the same runner as the caller's other steps. The Node.js installation therefore stays available to later steps in the calling workflow.
The last point matters. A composite action isn't a separate job. Anything it installs, writes to disk, or adds to PATH is visible to later steps in the caller's job.
Reading outputs from a nested action
Give the uses step an id. You can then read its outputs through steps.<id>.outputs.<name>, just as you would for a run step. To expose one of those values from your own action, map it in the outputs block.
name: Cached dependencies
description: Restore npm's download cache and report whether it hit
inputs:
cache-key:
description: Key for the cache entry
required: true
outputs:
cache-hit:
description: "'true' when an exact cache match was restored"
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: composite
steps:
- id: cache
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ inputs.cache-key }}
- shell: bash
env:
HIT: ${{ steps.cache.outputs.cache-hit }}
run: echo "Cache hit was '${HIT}'"Outputs are always strings. The value of cache-hit is the text true or false, not a boolean, and it can be an empty string if the nested action never set it. Compare it as text, for example steps.cache.outputs.cache-hit == 'true'.
Choosing the reference form
The uses value tells the runner where to find the nested action. These forms are the ones you will use most.
| Form | Example | Resolves to |
|---|---|---|
| Repository, tag | `actions/setup-node@v4` | The action at the repository root, at tag `v4` |
| Repository, commit SHA | `actions/setup-node@<full-sha>` | The exact commit |
| Repository subdirectory | `my-org/shared-actions/node-ci@v1` | `node-ci/action.yml` in that repository |
| Local path | `./.github/actions/greet` | A directory in the caller's workspace |
The local path form has a trap. A path that starts with ./ is resolved against the workspace of the job that is running, not against the repository that holds your composite action. When another repository calls your action, ./.github/actions/greet points into that caller's checkout, where it probably doesn't exist.
Pinning the nested version
A nested action is code that runs with your caller's permissions, so its version is a security decision.
- A tag such as
@v4is easy to read and receives patch updates. The tag's owner can move it, so you trust that owner. - A full commit SHA is immutable. It's the safest choice for third-party actions, and a trailing comment such as
# v4.1.0keeps it readable. Tools like Dependabot can update SHA-pinned references. - A branch name such as
@mainchanges whenever the branch does. Avoid it for anything you ship.
Pin the actions that your composite action calls. A caller who pins your action to a SHA only fixes your files. Whatever you reference with a floating tag can still change underneath them.
Nesting and where it stops
A composite action can call another composite action, which can call another, and so on. GitHub limits this to 10 levels of nesting. The limit rarely matters, but deep chains are hard to debug because each level adds its own group of log lines. Prefer a flat list of steps unless a sub-action is reused elsewhere.
Steps and context inside nested calls
Some details differ from a normal workflow job:
envon ausesstep. You can setenvon the step. The nested action sees it as environment variables, which is how many actions accept optional settings.secretscontext. A composite action cannot readsecretsdirectly. The caller passes a secret in as an input, and you forward it withwith: token: ${{ inputs.token }}. The secrets chapter covers this in more detail.ifconditions. You can putifonusessteps. Useinputs.*andsteps.*values in the condition, and compare strings.- Post steps. If the nested action has a post step, such as
actions/cachesaving the cache, it runs at the end of the caller's job, not at the end of your composite action. Cleanup happens later than you might expect.
Common mistakes
- Adding
shellto ausesstep. It is not valid there. Remove it. - Forgetting the checkout for local references. A
./path only exists afteractions/checkouthas run in the caller's job. - Comparing an input to a boolean.
inputs.run-tests == truedoes not behave as you expect, because inputs are strings. Use== 'true'. - Reading a nested output without an
id. Without anidon theusesstep,steps.<id>has nothing to refer to. - Leaving nested versions floating. An unpinned
@mainmakes your action's behavior depend on code you did not review.
Exercise
A composite action in my-org/shared-actions contains the step uses: ./.github/actions/lint. It passes when tested inside shared-actions but fails when my-org/web-app calls it. Why does it fail, and how do you fix it?
Show answer
A ./ path resolves against the workspace of the running job. In web-app's job that is the web-app checkout, which has no .github/actions/lint. Fix it by referencing the sibling action with its full form, such as my-org/shared-actions/lint@v1, optionally pinned to a commit SHA.
Exercise
You wrap actions/cache@v4 with id: cache and want your composite action to expose whether the cache was restored. Write the outputs entry, and explain what type its value has when the caller reads it.
Show answer
Under outputs, add cache-hit with a description and value: ${{ steps.cache.outputs.cache-hit }}. The caller receives a string, true or false (possibly empty), so it should compare with == 'true', not treat it as a boolean.