Sub topic 3
Defining composite steps with runs.using: composite
This chapter covers the runs block of an action.yml file. It explains how a composite action runs its steps and which step keys it supports. It also covers the errors people hit most often. It assumes you can read basic workflow syntax (jobs, steps, uses, run), you are comfortable with YAML, and you know basic bash. The action.yml file itself, inputs and outputs get their own chapters, so this chapter uses them only in small examples.
What `runs.using: composite` means
Every action's metadata file has a runs block. It tells the runner how to execute the action. For a JavaScript action, using names a Node runtime. For a Docker action, it is docker. For a composite action, it is composite, and the block then holds a steps list.
runs:
using: composite
steps:
- shell: bash
run: echo "first step"
- shell: bash
run: echo "second step"When a workflow job calls this action, the runner expands the action into its steps and runs them in order. The caller sees the whole action as one step. The log groups the inner steps under that one entry.
The working model has four parts:
- Same job, same runner. Composite steps run on the machine of the job that called the action. They share its filesystem, its installed tools and its environment. A file written by an earlier step is visible to a later step, including steps in the calling workflow.
- Sequential. Steps run top to bottom. There is no
needs, nostrategyand no parallelism inside a composite action. - One level of abstraction. The action has no jobs. It is a list of steps and nothing else.
- Fail fast by default. If a step fails, later steps are skipped unless they use a status function such as
always()orfailure()in anif.
Which keys a composite step accepts
A composite step looks like a workflow step, but it supports fewer keys. The table lists the common ones.
| Key | Purpose | Notes |
|---|---|---|
| `run` | Shell command to execute | Requires `shell` |
| `shell` | Shell that runs the command | Required for every `run` step |
| `uses` | Call another action | Cannot be combined with `run` |
| `with` | Inputs for the action named in `uses` | Only with `uses` |
| `id` | Name for reading step outputs | Needed for `steps.<id>.outputs` |
| `name` | Label in the log | Optional |
| `if` | Condition to run the step | Evaluated per step |
| `env` | Environment variables for this step | Preferred way to pass inputs to scripts |
| `working-directory` | Directory for a `run` step | Applies to that step only |
| `continue-on-error` | Let the step fail without failing the action | Optional |
A step is either a run step or a uses step. Mixing the two in one step is invalid.
Keys that belong to jobs do not exist here. You cannot set runs-on, timeout-minutes on a whole action, strategy, services or container in a composite action. The calling job controls those.
A worked example
This action installs dependencies, builds a project and prints a summary. It uses an id, env, working-directory and a uses step together.
name: Build project
description: Install dependencies, build, and report the build size
inputs:
directory:
description: Folder that contains package.json
required: false
default: "."
runs:
using: composite
steps:
- name: Install dependencies
shell: bash
working-directory: ${{ inputs.directory }}
run: npm ci
- name: Build
id: build
shell: bash
working-directory: ${{ inputs.directory }}
run: |
npm run build
size=$(du -sk dist | cut -f1)
echo "size-kb=${size}" >> "$GITHUB_OUTPUT"
- name: Report size
shell: bash
env:
SIZE: ${{ steps.build.outputs.size-kb }}
run: echo "Build output is ${SIZE} KB"Three details are worth noting. The id: build lets a later step read steps.build.outputs.size-kb. The step writes its output by appending name=value to the file named by $GITHUB_OUTPUT. Each run step starts a new shell process, so shell variables such as size do not carry over to the next step. Files, $GITHUB_OUTPUT, $GITHUB_ENV and $GITHUB_PATH do carry over.
Sharing data between steps
Because each step gets a fresh shell, you have four ways to move data forward:
- Step outputs. Write
key=valueto$GITHUB_OUTPUT, then read it withsteps.<id>.outputs.<key>. - Environment files. Write
KEY=valueto$GITHUB_ENV. Every later step, including steps in the calling workflow, seesKEY. Use this sparingly, because it leaks into the caller's job. - Path additions. Write a directory to
$GITHUB_PATHto put its tools onPATHfor later steps. - Files. Write to the workspace or to
$RUNNER_TEMP.
Prefer step outputs for values that the action itself uses. They stay scoped to the action. Use $GITHUB_ENV only when you intend to change the caller's environment.
Contexts available inside composite steps
Inside a composite action you can use the github, runner, env, steps, inputs and job contexts. The secrets context is not available. The action receives secrets only if the caller passes them as inputs. The steps context holds only the steps of this action, so a composite action cannot read steps.<id> from the calling workflow, and the caller cannot read the action's inner steps. The only way out is through the action's declared outputs.
The env context shows the caller's environment, so a variable set by the workflow with env: is visible inside the action. The reverse holds for $GITHUB_ENV, as described above.
Defaults that do not carry over
Settings at the workflow or job level do not all reach composite steps:
defaults.run.shellfrom the workflow does not apply. Eachrunstep must set its ownshell.defaults.run.working-directoryfrom the caller does not apply either. Setworking-directoryper step, or usecdinside the script.- The working directory starts as the caller's workspace, which is the repository the caller checked out. It is not the action's folder. Use
github.action_pathto refer to files that ship with the action.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| `Required property is missing: shell` | A `run` step has no `shell` | Add `shell: bash` to every `run` step |
| Step is skipped after an earlier failure | Default status check is `success()` | Add `if: ${{ always() }}` or `if: ${{ failure() }}` to the cleanup step |
| `Can't find 'action.yml'` for a local action | The caller did not run `actions/checkout` first | Check out the repository before the `uses: ./path` step |
| An output is empty in the caller | The action output was not mapped to a step output, or the step has no `id` | Add `id` to the step and map `value: ${{ steps.<id>.outputs.<key> }}` |
| A variable is missing in the next step | Each `run` step is a new shell | Use `$GITHUB_OUTPUT`, `$GITHUB_ENV` or a file |
| `if` on a boolean input always runs | Inputs are strings, and a non-empty string is truthy in some forms | Compare with `== 'true'` |
Failure behavior and cleanup
A failing step stops the action. To run a cleanup step regardless, give it an explicit condition.
runs:
using: composite
steps:
- name: Start test database
shell: bash
run: docker run -d --name testdb -p 5432:5432 -e POSTGRES_PASSWORD=test postgres:16
- name: Run integration tests
shell: bash
run: npm run test:integration
- name: Remove test database
if: ${{ always() }}
shell: bash
run: docker rm -f testdbComposite actions have no post: hook, unlike JavaScript actions. If the job is cancelled, or a step before your cleanup hangs, always() still tries to run the cleanup step, but the action cannot register cleanup that runs after the caller's later steps. For cleanup that must wait until the end of the job, either ask the caller to add a final step or use a JavaScript action.
Use continue-on-error: true only for steps whose failure you accept, such as an optional cache upload. A failing step with continue-on-error is reported as a success to later success() checks.
Exit codes and shell options
On Linux and macOS runners, shell: bash runs the script with bash --noprofile --norc -eo pipefail {0}. The -e option stops the script at the first failing command. The pipefail option makes a pipeline fail if any command in it fails. Plain shell: sh runs with -e only, and no pipefail. Because of this, the same script can behave differently under bash and sh.
If you need a different behavior, set it in the script itself:
runs:
using: composite
steps:
- name: Tolerate a missing file
shell: bash
run: |
set +e
grep -q "needle" notes.txt
status=$?
echo "grep exit code: ${status}"
exit 0On Windows runners, bash is available through Git for Windows, but pwsh and cmd are also valid values for shell. If your action must run on all three operating systems, bash on every step is the simplest portable choice.
Exercise
A composite action has two steps. Step one runs MY_VAR=hello in bash. Step two runs echo "$MY_VAR" in bash. The second step prints an empty line. Explain why, and show one way to fix it so that step two prints hello.
Show answer
Each run step starts its own shell process, so a shell variable set in step one is gone when step two starts. To fix it, give step one an id (for example set) and write the value to the output file: echo "my-var=hello" >> "$GITHUB_OUTPUT". In step two, pass it through env: env: MY_VAR: ${{ steps.set.outputs.my-var }}. Then echo "$MY_VAR" prints hello. Writing echo "MY_VAR=hello" >> "$GITHUB_ENV" in step one also works, but it changes the environment of every later step in the caller's job.
Exercise
You want a composite action to stop a Docker container named testdb at the end of the action, even when a test step fails. Which if condition do you put on the cleanup step, and why is the default not enough?
Show answer
Use if: ${{ always() }} (or if: ${{ failure() }} if you only want cleanup after a failure). A step without if gets an implicit success() check, so it is skipped once an earlier step has failed.