๐ฎ Slack Message Broker #1719
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 sends a message to the plutus-ci channel whenever a status check fails, | |
# and tried to notify the author of the commit that caused the failure. | |
name: "๐ฎ Slack Message Broker" | |
on: | |
check_run: | |
types: [completed] | |
workflow_run: | |
workflows: | |
- "๐ Broken Links" | |
- "๐ฝ Cardano Constitution Tests" | |
- "๐ฐ Cost Model Benchmark" | |
- "๐ฆ Docusaurus Site" | |
- "๐ Haddock Site" | |
- "๐ฉบ Longitudinal Benchmark" | |
- "๐ฎ Metatheory Site" | |
- "๐ Nightly Testsuite" | |
- "๐ Papers & Specs" | |
- "๐๏ธ PlutusTx Template" | |
jobs: | |
Send: | |
runs-on: [ubuntu-latest] | |
steps: | |
- name: Prepare Slack Message | |
uses: actions/github-script@main | |
id: prepare-slack-message | |
if: > | |
(github.event_name == 'workflow_run' && !github.event.workflow_run.pull_requests[0].draft) || | |
(github.event_name == 'check_run' && !github.event.check_run.check_suite.pull_requests[0].draft) | |
with: | |
script: | | |
console.log(${{ toJson(github.event) }}); | |
function getSlackMemberToBeNotified() { | |
const senderLogin = "${{ github.event.sender.login }}"; | |
const slackMemberIds = { | |
"zeme-wana": "U03HGDNDRKR", | |
"effectfully": "UBH8K0ZU2", | |
"kwxm": "UCF4SL4BT", | |
"Unisay": "U02V796524S", | |
"ramsay-t": "U05T49F9FV1", | |
"ana-pantilie": "U05V2854W86", | |
"zliu41": "U03BP2HTKDK", | |
"bezirg": "UQ1LUSR8B", | |
"erikd": "U914V9D2B" | |
}; | |
if (senderLogin in slackMemberIds) { | |
return `<@${slackMemberIds[senderLogin]}>`; | |
} else { | |
return "@{senderLogin}"; | |
} | |
} | |
let message = ""; | |
let shouldSendMessage = false; | |
let slackMember = getSlackMemberToBeNotified(); | |
function handleWorkflowRunEvent() { | |
const name = "${{ github.event.workflow_run.name }}"; | |
const url = "${{ github.event.workflow_run.html_url }}"; | |
const status = "${{ github.event.workflow_run.status }}"; | |
const conclusion = "${{ github.event.workflow_run.conclusion }}"; | |
const failureConclusions = [ "failure", "null", "action_required", "neutral", "timed_out" ]; | |
if (failureConclusions.includes(conclusion)) { | |
message = `โ ${name} \`${conclusion}\` <${url}|View Logs> ${slackMember}`; | |
shouldSendMessage = true; | |
} else { | |
message = `${name} \`${status}\` \`${conclusion}\` <${url}|View Logs> ${slackMember}`; | |
shouldSendMessage = false; | |
} | |
} | |
function handleCheckRunEvent() { | |
const name = "${{ github.event.check_run.name }}"; | |
const status = "${{ github.event.check_run.status }}"; | |
const conclusion = "${{ github.event.check_run.conclusion }}"; | |
const url = "${{ github.event.check_run.html_url }}"; | |
const checkRunWatchlist = [ | |
"ci/hydra-build:aarch64-darwin.required", | |
"ci/hydra-build:x86_64-darwin.required", | |
"ci/hydra-build:x86_64-linux.required", | |
"ci/eval" | |
]; | |
if (conclusion == "failure" && checkRunWatchlist.includes(name)) { | |
message = `โ ${name} \`${conclusion}\` <${url}|View Logs> ${slackMember}`; | |
shouldSendMessage = true; | |
} else { | |
message = `${name} \`${status}\` \`${conclusion}\` <${url}|View Logs> ${slackMember}`; | |
shouldSendMessage = false; | |
} | |
} | |
if ("${{ github.event_name }}" == "workflow_run") { | |
handleWorkflowRunEvent(); | |
} else if ("${{ github.event_name }}" == "check_run") { | |
handleCheckRunEvent(); | |
} else { | |
message = `Unknown event: ${{ github.event_name }}`; | |
shouldSendMessage = true; | |
} | |
console.log(`message: ${message}`); | |
console.log(`shouldSendMessage: ${shouldSendMessage}`); | |
core.setOutput("message", message); | |
core.setOutput("shouldSendMessage", shouldSendMessage); | |
- name: Notify Slack | |
uses: slackapi/[email protected] | |
if: ${{ steps.prepare-slack-message.outputs.shouldSendMessage == 'true' }} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
channel-id: C07A1GSNZEE # plutus-ci | |
payload: | | |
{ | |
"text": "${{ steps.prepare-slack-message.outputs.message }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "${{ steps.prepare-slack-message.outputs.message }}" | |
} | |
} | |
] | |
} | |