Sub topic 6
Outputs: from a step to the action's result
This chapter assumes you can read basic workflow syntax (jobs, steps, uses, run), write simple bash, and know that a composite action lives in an action.yml file with runs.using: composite. It covers how a value computed inside one step becomes a value the calling workflow can read.
Two levels of outputs
A composite action has outputs at two levels, and most mistakes come from mixing them up.
- A step output is set by a single step while the action runs. Later steps in the same action read it with
steps.<id>.outputs.<name>. - An action output is declared under the top-level
outputs:key ofaction.yml. The calling workflow reads it withsteps.<caller-step-id>.outputs.<name>.
Nothing connects the two automatically. A step output does not become an action output unless you map it in action.yml.
Step 1: set a step output
A step sets an output by appending a name=value line to the file whose path is in the GITHUB_OUTPUT environment variable. The step needs an id so that other steps can refer to it.
- id: build
shell: bash
env:
WHO: ${{ inputs.who-to-greet }}
run: echo "greeting=Hello, ${WHO}" >> "$GITHUB_OUTPUT"Notes on this step:
id: buildis the handle. Without it, nothing can read the output.- The older
::set-outputworkflow command is deprecated. Use theGITHUB_OUTPUTfile. - Output values are always strings. A number or boolean you write is read back as text.
- Each step gets its own
GITHUB_OUTPUTfile, so two steps can use the same output name without colliding. They are distinguished by step id.
Step 2: declare the action output
Add an outputs: block at the top level of action.yml. In a composite action, each output needs a value that points to a step output.
outputs:
greeting:
description: The greeting text
value: ${{ steps.build.outputs.greeting }}Details that matter:
descriptionis required for each output.valueis required for composite actions. JavaScript and Docker actions do not usevalue, because the action code sets outputs itself.- The
valueis an expression, so it can reference any context available in the composite action, not onlysteps. For example,${{ inputs.who-to-greet }}is valid, though echoing an input back is rarely useful. - The output name is what the caller uses. It does not have to match the step output name, though keeping them the same avoids confusion.
The complete action
Here is the full action.yml, with one input, one output, and a shell on every run step.
name: Greet
description: Build a greeting and expose it as an output
inputs:
who-to-greet:
description: Name to greet
required: false
default: World
outputs:
greeting:
description: The greeting text
value: ${{ steps.build.outputs.greeting }}
runs:
using: composite
steps:
- id: build
shell: bash
env:
WHO: ${{ inputs.who-to-greet }}
run: echo "greeting=Hello, ${WHO}" >> "$GITHUB_OUTPUT"
- shell: bash
env:
GREETING: ${{ steps.build.outputs.greeting }}
run: echo "$GREETING"The second step reads the first step's output within the action. It passes the value through env rather than interpolating it directly into the script. The input-safety chapter explains why, but the habit is worth forming now.
Step 3: read the output in the caller
The calling workflow gives the action's step an id, then reads the output through that id.
name: CI
on: [push]
jobs:
greet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: hello
uses: ./.github/actions/greet
with:
who-to-greet: Octocat
- run: echo "${{ steps.hello.outputs.greeting }}"The id hello belongs to the caller. The id build inside the action is private and is not visible to the caller. The caller can only see what the action exposes under outputs:.
If the caller's step has no id, the output is unreachable. This is the most common reason for an empty value on the calling side.
Multi-line values
The name=value form works only for single-line values. A newline would end the line and corrupt the file. For multi-line output, use a delimiter.
- id: report
shell: bash
run: |
{
echo "summary<<EOF_SUMMARY"
git log -3 --oneline
echo "EOF_SUMMARY"
} >> "$GITHUB_OUTPUT"The syntax is name<<DELIMITER, then the content, then the delimiter alone on a line. Choose a delimiter that cannot appear in the content. If the content comes from an untrusted source, a value that contains your delimiter on its own line lets an attacker inject extra outputs. A random delimiter avoids this:
- id: report
shell: bash
run: |
delimiter="EOF_$(openssl rand -hex 8)"
{
echo "summary<<${delimiter}"
git log -3 --pretty=%s
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"Several outputs and derived values
An action can declare as many outputs as it needs. Each one maps independently, and different outputs can come from different steps.
outputs:
version:
description: Version read from package.json
value: ${{ steps.meta.outputs.version }}
cache-hit:
description: Whether the dependency cache was restored
value: ${{ steps.setup.outputs.cache-hit }}The second output above comes from a step that uses another action (actions/setup-node exposes a cache-hit output). Outputs from nested actions are read the same way as outputs from run steps, as long as the step has an id.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Caller sees an empty string | Caller's step has no `id`, or the `id` is misspelled | Add `id:` and use the same name in `steps.<id>.outputs` |
| Caller sees an empty string, step output is set | The action's `outputs:` block is missing, or `value` points to the wrong step id | Check the mapping in `action.yml` |
| Action fails to load with a validation error | `value` missing on a composite output | Add `value: ${{ steps.<id>.outputs.<name> }}` |
| Output set but later step reads nothing | The step wrote to the wrong place, such as `echo "x=1"` without `>> "$GITHUB_OUTPUT"` | Redirect to `$GITHUB_OUTPUT` |
| Value is truncated at a newline | Multi-line value written as `name=value` | Use the `name<<DELIMITER` form |
| `if: steps.x.outputs.ok == true` never matches | Outputs are strings, and the comparison is against a boolean | Compare to the string: `== 'true'` |
Behavior worth knowing
- Failed steps. If a step fails, later steps do not run by default, and outputs they would have set stay empty. The action's output is then an empty string, not an error.
- Skipped steps. A step skipped by
ifproduces no outputs. An action output mapped to it resolves to an empty string. If you need a fallback, use an expression such as${{ steps.a.outputs.x || steps.b.outputs.x }}. - Size. Each output is limited in size (about 1 MB per output, and a total per job). For large data, write a file and pass its path as the output.
- Secrets. GitHub masks registered secrets in logs, but an output that holds a secret may be skipped by the runner when passed between jobs. Do not use outputs to carry secrets.
- Across jobs. An action output is only visible to later steps of the same job. To pass it to another job, map it in the calling job's
outputs:and read it withneeds.<job>.outputs.<name>.
jobs:
greet:
runs-on: ubuntu-latest
outputs:
greeting: ${{ steps.hello.outputs.greeting }}
steps:
- uses: actions/checkout@v4
- id: hello
uses: ./.github/actions/greet
consume:
needs: greet
runs-on: ubuntu-latest
steps:
- run: echo "${{ needs.greet.outputs.greeting }}"Exercise
A composite action has a step with id: version that runs echo "number=1.4.2" >> "$GITHUB_OUTPUT". The action's action.yml has no outputs: block. The caller's step has id: tool and runs echo "${{ steps.tool.outputs.number }}". What does the caller print, and what two changes make it print 1.4.2?
Show answer
It prints an empty line. The step output exists inside the action, but nothing maps it to an action output. Add outputs: number: { description: ..., value: ${{ steps.version.outputs.number }} } to action.yml. The caller's expression steps.tool.outputs.number is then correct, because tool is the caller's step id and number is the declared action output name.
Exercise
Why can the output of a step skipped by if still appear in an action output, and what value does the caller get?
Show answer
The action output's value is just an expression, and it is evaluated even when the step it references did not run. A skipped step sets no outputs, so the expression resolves to an empty string, and the caller reads an empty string rather than an error.