5

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

  1. Fork this repository.
  2. Enable GitHub actions on the fork.
  3. Push a commit to your fork.
  4. See that only the random-number variable is set while the random-number-bash` is set (See this example workflow).
3
  • 1
    In this workflow run, it seems to have worked fine? Commented Feb 17, 2023 at 21:01
  • 1
    The run you link to has both outputs, the one from the script is set to test, as you set it in the script. Commented Feb 17, 2023 at 21:03
  • Ah, you're right. Thanks for pointing that out. The last commits I did apparently fix the issue. It looks like in the broken version, the id item was missing (see github.com/rickstaa/hello-world-composite-action-output-bug/…). Commented Feb 18, 2023 at 9:23

1 Answer 1

7

I found my issue using @benjamin-w's comment. The problem was that the goodbye.sh step should contain an id key for the created output to be referenced correctly. The correct syntax should be:

action.yml

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 }}
  random-number-bash:
    description: "Random number bash"
    value: ${{ steps.random-number-generator-bash.outputs.random-number-bash }}
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
      id: random-number-generator-bash
      shell: bash

And the correct syntax for creating the output in the goodbye.sh script should be:

Goodbye.sh

echo "Goodbye"
echo "random-number-bash=$(echo 123)" >> $GITHUB_OUTPUT

Which then can be tested using the following workflow file:

Test workflow

on: [push]

jobs:
  hello_world_job:
    runs-on: ubuntu-latest
    name: A job to say hello
    steps:
      - uses: actions/checkout@v3
      - id: foo
        uses: rickstaa/hello-world-composite-action-output-bug@main
        with:
          who-to-greet: 'Mona the Octocat'
      - run: echo random-number ${{ steps.foo.outputs.random-number }}
        shell: bash
      - run: echo random-number ${{ steps.foo.outputs.random-number-bash }}
        shell: bash
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.