For one of my projects, I am setting an action output from within a bash script that is executed inside a composite action. I found that GitHub has excellent documentation on how to create a GitHub composite action output. It states that this can be done using the following action.yml file.
name: 'Hello World'
description: 'Greet someone'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
outputs:
random-number:
description: "Random number"
value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
using: "composite"
steps:
- run: echo Hello ${{ inputs.who-to-greet }}.
shell: bash
- id: random-number-generator
run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
shell: bash
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- run: goodbye.sh
shell: bash
I checked the results using the following action workflow, and it works.
on: [push]
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- uses: actions/checkout@v3
- id: foo
uses: actions/hello-world-composite-action@v1
with:
who-to-greet: 'Mona the Octocat'
- run: echo random-number ${{ steps.foo.outputs.random-number }}
shell: bash
My use case, however, differs from the example above in that I have to set the output variable inside the goodbye.sh script. According to the documentation, this should be done using the GITHUB_OUTPUT variable:
echo "{name}={value}" >> $GITHUB_OUTPUT
After some testing, this method is not working for composite actions. As this could also be a bug or not supported, I created a bug report at https://github.com/orgs/community/discussions/47775. However, I quickly wanted to double-check if there may be something wrong with my syntax.
Steps to reproduce
- Fork this repository.
- Enable GitHub actions on the fork.
- Push a commit to your fork.
- See that only the random-number variable is set while the random-number-bash` is set (See this example workflow).
test, as you set it in the script.iditem was missing (see github.com/rickstaa/hello-world-composite-action-output-bug/…).