📮 Slack Message Broker #9675
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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@v7 | |
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/[email protected] | |
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 }} |