Sub topic 6
Outputs: from a step to the action's result
This chapter assumes you can read basic workflow syntax and bash, and that you know how an action.yml declares inputs. Here you will learn how a value computed inside a composite action reaches the workflow that called it.
Two layers of outputs
A composite action has two kinds of outputs, and they are easy to confuse.
- A step output is written by one step inside the action. Later steps in the same action can read it.
- An action output is declared under
outputs:inaction.yml. The calling workflow reads it.
Step outputs do not leave the action on their own. You must map each action output to a step output explicitly.
Writing a step output
A step sets an output by appending name=value to the file named by $GITHUB_OUTPUT. The step needs an id so that other steps can refer to it.
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 step with id: build writes greeting. The second step reads it with steps.build.outputs.greeting. The outputs.greeting.value entry exposes the same value to the caller.
Mapping the output
Each entry under outputs: needs a description and a value. In a composite action, value is an expression. It usually points at steps.<id>.outputs.<name>.
If the value is missing or the step id is misspelled, the caller receives an empty string. GitHub does not report an error, so check these two names first when an output is empty.
Reading the output in a workflow
The caller gives the action step an id, then reads steps.<id>.outputs.<name>.
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 }}"Without id: hello on the calling step, there is nothing to reference.
Common errors
| Symptom | Likely cause |
|---|---|
| Caller sees an empty output | The `value` expression names the wrong step id or output name |
| Step output is empty inside the action | The step has no `id`, or it wrote to stdout instead of `$GITHUB_OUTPUT` |
| Output is cut off after a line break | `name=value` supports one line only |
| Boolean comparison fails | Outputs are always strings, so compare with `== 'true'` |
Exercise
A composite action declares an output version with value: ${{ steps.ver.outputs.version }}. The caller prints an empty string. Name two things to check.
Show answer
First, confirm that the step in the action has id: ver. Second, confirm that the step appends version=... to $GITHUB_OUTPUT and does not just echo it to stdout. Also check that the calling step has an id and that the caller reads steps.<that id>.outputs.version.