actions-slack-status

Slack publishing status message (replacement for circleci_slack_status orb)

MPL-2.0 License

Stars
1
Committers
4

For internal HashiCorp use only. The output of this action is specifically designed to satisfy the needs of our internal deployment system, and may not be useful to other organizations.

Slack workflow status action Heimdall CI

No bells, no whistles, just status a status message.

Example

See also some implementations in the wild:

Notifications will be emitted with some simple formatting:

Usage

  1. Create a webhook

Use either Technique 2 or Technique 3 here. Alternatively, Release Engineering may provision one on your behalf for status notifications from our Release Bot.

Do not use Slack's Workflow Builder integration to generate the webhook link.

  1. Add the step to the workflow

To use, add a step that tests the job status (success, failure, cancelled):

steps:
  # ...
  - run: |
      echo "This run failed!" 1>&2
      exit 1
  - uses: hashicorp/actions-slack-status@v1
    if: ${{always()}}
    with:
      success-message: "A *bolded success* message."
      failure-message: "A failure message."
      #cancelled-message: "Operation cancelled, but that's okay!"
      status: ${{job.status}}
      slack-webhook-url: ${{secrets.slack_webhook_url}}

Or more advanced usage with, pass a specific step conclusion (success, failure, cancelled, skipped):

steps:
  # ...
  - if: ${{ 'skip-me' == 'true' }}  # this demo will always skip, use a real test instead :)
    id: demo
    run: |
      exit 0
  - uses: hashicorp/actions-slack-status@v1
    with:
      skipped-message: "A successfully skipped `cmd` message."
      success-message: "A success message."
      status: ${{steps.demo.conclusion}}
      slack-webhook-url: ${{secrets.slack_webhook_url}}

Note: Normally, if a ${status}-message is not defined for a given status a GH warning will be emitted on the action and no message will be sent to slack. To avoid this, one can use an approprate if statement to skip this step.

In this example, success messages are never sent and no GHA warning will be emitted regarding this omission.

steps:
  - run: |
      exit 0
  - uses: hashicorp/actions-slack-status@v1
    if: failure()
    with:
      failure-message: "Since our job never fails, this message will never send nor will it warn about a missing success-message field"
      status: 'failure'
      slack-webhook-url: ${{secrets.slack_webhook_url}}

Job Status Meanings

In the examples we used different ways of obtaining the statuses. Their usage can be nuanced, but generally they are:

If in doubt, use ${{jobs.status}}. The specific step status can be useful if we need to report skips or when multiple steps are mutually exclusive, and we would like to notify exactly which one fired.

Step conclusion and outcome can differ depending on whether continue-on-error is set. In otherwords, if a step's continue-on-error: true, the outcome may be failure or success but the conclusion would be success.