I have this GitHub Actions workflow which runs tests, but now I am integrating slack notification in it. I want to get the output of the Run tests
step and send it as a message in the slack step.
- name: Run tests run: | mix compile --warnings-as-errors mix format --check-formatted mix ecto.create mix ecto.migrate mix test env: MIX_ENV: test PGHOST: localhost PGUSER: postgres - name: Slack Notification uses: rtCamp/action-slack-notify@master env: SLACK_MESSAGE: Run tests output SLACK_TITLE: CI Test Suite SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
GitHub Actions has a workflow command called set-output . This can be used to capture the output from a shell command in step. That output value can then be used in a later step. A useful example of this is reading the version of a tool from a dot-file to tell a later step what version of that tool to install.
You should use run: echo "$GITHUB. REPOSITORY" and run: echo "$GITHUB. REPOSITORY_OWNER" to see them directly on your workflow. Tip: You can identify most of the variables that can be shown with echo through the Github Context using run: echo "$GITHUB_CONTEXT" in your workflow.
This action checks-out your repository under $GITHUB_WORKSPACE , so your workflow can access it. Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags.
You need to do 3 things:
id
to the step you want the output fromset-output
command- name: Run tests run: | echo "::set-output name=mix-compile--warnings-as-errors::$(mix compile --warnings-as-errors)\n" echo "::set-output name=mix-format--check-formatted::$(mix format --check-formatted)\n" echo "::set-output name=mix-ecto_create::$(mix ecto.create)\n" echo "::set-output name=mix-ecto_migrate::$(mix ecto.migrate)\n" echo "::set-output name=mix-test::$(mix test)\n" 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With