This is explained in the Github Actions docs, but is not explicitly clear : https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
It is explained in this issue : github/docs#21529
Here is my example :
runs:
using: "composite"
steps:
- name: Run command
id: command
shell: bash
run: |
res=$( ls -al )
echo "myresult<<EOF" >> "$GITHUB_OUTPUT"
echo $res >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: DEBUG
if: ${{ always() }}
run: |
echo "result = ${{ steps.command.outputs.myresult }}"
In this example :
- the result of
ls
is stored in theres
variable - this value is echoed out into GITHUB_OUTPUT over several lines
- the first line holds the name of the output variable
myresult
- the output is available in the
myresult
output of thecommand
step - the output is on one single line, so that is easy to use if it is JSON, for example