Skip to content

Brymastr/slack-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

slack-action

Build

Send custom slack messages given a slack block template

Usage

- uses: Brymastr/slack-action@v1
  name: Slack notification
  env:
    SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
  with:
    template: './template.json'
    example_key1: example value 1
    job_status: ${{ job.status }}

template.json

{
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Example: {{ example_key1 }} and {{ job_status }}"
      }
    }
  ]
}

Use of this action requires a GitHub secret called SLACK_WEBHOOK. The value should include the channel id and look something like one of these:

  • https://hooks.slack.com/services/11111ZZZZ/22222XXXX/1a2B3c4e5F6G7h8I9j0k
  • 11111ZZZZ/22222XXXX/1a2B3c4e5F6G7h8I9j0k

See Creating and using encrypted secrets for assistance with GitHub Secrets.

See Sending messages using Incoming Webhooks for assistance with Slack Webhooks.

Required Arguments

  • SLACK_WEBHOOK - provided as an env variable, this is the full webhook url for your bot channel.
  • template - provided in the with args, is the path to the message template json file. This path should be relative from the project root.

Optional Arguments

Any other custom arguments can be provided and will be included in the template. From the example above all occurrences of {{ example_key1 }} in the template.json file will be replace with example value 1.
NOTE: template names in the json file must be lower case.

Default and Computed Properties

Most github context properties are included by default without needing to pass them in through a with argument. Some properties have been renamed to make a bit more sense. See Contexts for more info.

Property Name Replacement Variable
github.sha commit
github.repository repo
github.ref ref
github.head_ref head_ref
github.base_ref base_ref
github.actor actor
github.event_name event
github.workflow workflow

In addition to these github context properties there are 2 computed properties that could be useful

Replacement Variable Description
repo_url the URL of the github repo
actions_url the URL of the github actions workflow run for the commit

Notes

Check out the examples directory for some examples

Try the Slack Block Kit Builder for message template inspiration

Motivation

Slack notifications are a common feature in automated build pipelines. There are already a few existing GitHub Actions that send slack messages but most use a predetermined format and only allow for title or subject customization. This action allows for full block customization. I would like this action to serve as a simple, solid, and customizable slack notification action with as few dependencies as possible.

Alternatives