-
Notifications
You must be signed in to change notification settings - Fork 479
47 lines (45 loc) · 1.92 KB
/
slack-message-broker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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/[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 }}