Sub topic 3
Defining composite steps with runs.using: composite
This chapter assumes you can read basic workflow syntax (jobs, steps, uses, run), write YAML, and run simple bash commands. It covers the runs block of action.yml, which turns a list of steps into a composite action.
What `runs.using: composite` does
Every action has a runs block that tells the runner how to execute it. For a composite action, you set using: composite and list the steps under steps. The runner runs those steps in order, inside the calling job, on the same runner.
name: Print versions
description: Print tool versions for debugging
runs:
using: composite
steps:
- shell: bash
run: node --version
- shell: bash
run: git --versionBecause the steps run inside the caller's job, they share its filesystem and its working directory. A file that step one writes is visible to step two, and also to later steps in the workflow.
What a composite step can contain
A step in a composite action looks like a workflow step, with a few differences. The common keys are:
| Key | Purpose |
|---|---|
| `run` | A shell command. Requires `shell`. |
| `shell` | The shell that runs the command, such as `bash`. Required with `run`. |
| `uses` | Calls another action. |
| `with` | Passes inputs to a `uses` step. |
| `id` | Names the step so later steps can read its outputs. |
| `env` | Sets environment variables for that step. |
| `if` | Runs the step only when the condition is true. |
| `working-directory` | Sets the directory for a `run` step. |
| `name` | A label shown in the log. |
A step has either run or uses, never both.
How the steps are shown in the log
The runner shows the whole composite action as one step in the caller's job log. Your inner steps appear as nested groups under it. Give important steps a name so the log is readable.
runs:
using: composite
steps:
- name: Create build directory
shell: bash
run: mkdir -p build
- name: Write marker file
shell: bash
run: echo "built" > build/marker.txtFailure behavior
If a step exits with a non-zero status, the composite action stops and fails, and the calling job fails unless the caller set continue-on-error. You can also set continue-on-error: true on an individual inner step.
Common errors
- Missing
shell. Omittingshellon arunstep makes the action invalid. Add it to everyrunstep. - Missing
description. Composite actions need adescriptionat the top level, as in the examples above. - Using
using: compositewithmain. Themainkey belongs to JavaScript actions. A composite action has onlysteps. - Assuming a separate environment. Changes to files and to
$GITHUB_ENVaffect the whole job, not only the action.
Exercise
A composite action has a step with run: echo hi and no other keys besides name. The workflow fails when it loads the action. What is missing, and where do you add it?
Show answer
The step needs a shell key, for example shell: bash, added to that same step next to run. Every run step in a composite action requires it.
Exercise
A composite action has three steps. The second one exits with status 1. Does the third step run, and does the calling job fail?
Show answer
The third step does not run, because a non-zero exit stops the action. The calling job fails unless the caller set continue-on-error on the step that uses the action.