Skip to content

📮 Slack Message Broker #31

📮 Slack Message Broker

📮 Slack Message Broker #31

# This workflow is triggered whenever any of the workflows listed in on.workflow_run.workflows
# has been cancelled or has failed, and will send a message to the specified Slack channel ids.
# TODO turn this into a standalone GitHub action so that it can be used in other repositories.
name: Slack Message Broker
on:
workflow_run:
workflows: [Script Evaluation Test, Benchmark, Build and Deploy to Github Pages]
types: [completed, requested, in_progress]
jobs:
slack-broker:
runs-on: [ubuntu-latest]
if: contains(fromJson('["cancelled", "failure"]'), github.event.workflow_job.status)
steps:
- name: Prepare Slack Message
uses: actions/github-script@v6
id: prepare-slack-message
with:
script: |
const name = "${{ github.event.workflow_job.name }}";
const url = "${{ github.event.workflow_job.html_url }}";
const status = "${{ github.event.workflow_job.status }}";
const emojy = { failure: "❌", cancelled: "✋" }[status];
const conclusion = "${{ github.event.workflow_job.conclusion }}";
const action = "${{ github.event.action }}";
const message = `${emojy} \`${name}\` *${action}* | *${status}* | *${conclusion}* 👉🏻 <${url}|view logs>`;
core.setOutput("message", message);
- name: Notify Slack
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: my-private-channel
payload: |
{
"text": "${{ steps.prepare-slack-message.outputs.message }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ steps.prepare-slack-message.outputs.message }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}