How do I get the output of a specific step in GitHub Actions?

You need to do 3 things:

  1. Add an id to the step you want the output from
  2. Create the outputs using the GITHUB_OUTPUT environment variable
  3. Use the id and the output name in another step to get the outputs and then join them into one message for slack
- name: Run tests
  run: |
    echo "mix-compile--warnings-as-errors=$(mix compile --warnings-as-errors)\n" >> $GITHUB_OUTPUT
    echo "mix-format--check-formatted=$(mix format --check-formatted)\n" >> $GITHUB_OUTPUT
    echo "mix-ecto_create=$(mix ecto.create)\n" >> $GITHUB_OUTPUT
    echo "mix-ecto_migrate=$(mix ecto.migrate)\n" >> $GITHUB_OUTPUT
    echo "mix-test=$(mix test)\n" >> $GITHUB_OUTPUT
  id: run_tests
  env:
    MIX_ENV: test
    PGHOST: localhost
    PGUSER: postgres

- name: Slack Notification
  uses: rtCamp/action-slack-notify@v2
  env:
    SLACK_MESSAGE: ${{join(steps.run_tests.outputs.*, '\n')}}
    SLACK_TITLE: CI Test Suite
    SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

See Metadata Syntax for outputs name description

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)