A Github Action Slack Notifier:
- that can use Slack Block Kit for messages...
- which provides a way to customize the notification message with templates...
- that can possibly make build notifications look pretty...pretty...good
- Uses Slack Block Kit with
eta
templates - Uses Octokit Jobs API to fetch running jobs and steps
- Uses Octokit GraphQL API to get details of the commit. This makes it possible to have:
- the commit message on a PR trigger
- the PR title and body on a merge trigger
- the commit and PR for a non code event (for example
repository_dispatch
) using a SHA override
uses: navilan\slack-action-status@v2
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
botToken: "testBotToken"
channelId: "testChannelId"
templateFile: .github/workflows/slack-blocks.json.eta
status: "Testing Action"
inclusionSuffix: "!!"
indicators: |
- completed: ":white_check_mark:"
- running: ":hourglass:"
- queued: ":double_vertical_bar:"
- unclear: ":grey_question:"
- failed: ":x:"
- cancelled: ":octogonal_sign:"
- skipped: ":large_green_square:"
-
githubToken (Required)
${{ secrets.GITHUB_TOKEN }}
. This is used to get the running jobs and steps from the octokit API. -
botToken (Required)
Slack documentation on how to setup your app and get the bot token.
-
templateFile (Optional)
You can use slack block kit to create a message template. eta template engine in its default configuration is used to generate the message. These variables(see below) are available in the
it
context of the template.View the template used by this repository.
If the template file is not provided, the
status
parameter is used as plain text message.
-
status (Required)
Current status.
-
params (Optional)
A list of key, value pairs to feed the template.
params: | - key1: value1 - key2: value2
Note the pipe that makes it a string value
-
indicators (Optional)
Key value pairs of indicators - plain text or slack emoji as status prefixes for jobs and steps
indicators: | - completed: ":white_check_mark:" - inProgress: ":hourglass:"
Note the pipe that makes it a string value
-
inclusionSuffix (Optional)
Steps that have a name suffixed with this pattern are included in the Slack notification message. Default: All steps are shown.
-
messageId (Optional)
A slack message that needs to be updated. If this is not provided, a new message is created.
-
forceSuccess (Optional)
Forces the current job status to be a success regardless of the API result. This can be used in the final action to indicate workflow completion.
Important: If you are using this parameter, ensure that you do not give your job a descriptive name.
-
forceFailure (Optional)
Forces the current job status to be a failure regardless of the API result. This can be used in the final action to indicate workflow completion.
Important: If you are using this parameter, ensure that you do not give your job a descriptive name.
The context variables are well typed. They can be accessed through the default template root variable it
.
You can see the type definition here: Template Variables Typescript definition
Slack Action Status is used by remote dev teams on production systems. It is fairly compete in terms of the provided feature set. Bug reports, feature requests, fixes and enhancements are welcome as Issues / PRs.