-
Notifications
You must be signed in to change notification settings - Fork 481
179 lines (144 loc) ยท 6.66 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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"
- "๐ท Cabal Build All"
- "๐ฝ 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
with:
script: |
console.log(${{ toJson(github.event) }});
function getSlackMembersToBeNotified() {
const senderLogin = "${{ github.event.sender.login }}";
const workflowName = "${{ github.event.workflow.name }}";
const slackMemberIds = {
"zeme-wana": ["U03HGDNDRKR"],
"effectfully": ["UBH8K0ZU2"],
"kwxm": ["UCF4SL4BT"],
"Unisay": ["U02V796524S"],
"ramsay-t": ["U05T49F9FV1"],
"ana-pantilie": ["U05V2854W86"],
"zliu41": ["U03BP2HTKDK"],
"bezirg": ["UQ1LUSR8B"],
"erikd": ["U914V9D2B"]
};
const workflowOwners = {
"๐ฝ Cardano Constitution Tests": ["UQ1LUSR8B"],
"๐ฉบ Longitudinal Benchmark": ["UBH8K0ZU2"],
"๐ฐ Cost Model Benchmark": ["UBH8K0ZU2"],
"๐ Nightly Testsuite": ["UQ1LUSR8B"]
};
function at(ids) {
return ids.reduce((acc, id) => acc + `<@${id}> `, "");
}
if (workflowName in workflowOwners) {
return at(workflowOwners[workflowName]);
} else if (senderLogin in slackMemberIds) {
return at(slackMemberIds[senderLogin]);
} else {
return `@${senderLogin}`;
}
}
const isWorkflowRunEvent = "${{ github.event_name }}" == "workflow_run";
const isCheckRunEvent = "${{ github.event_name }}" == "check_run";
function isDraftPullRequest() {
const workflowRunPrIsNull = "${{ github.event.workflow_run.pull_requests == null }}" === "true";
const isDraftPrWorkflowRun = "${{ github.event.workflow_run.pull_requests[0][0].draft }}" === "true";
const checkRunPrIsNull = "${{ github.event.check_run.pull_requests == null }}" === "true";
const isDraftPrCheckRun = "${{ github.event.check_run.pull_requests[0][0].draft }}" === "true";
console.log(`isWorkflowRunEvent: ${isWorkflowRunEvent}`);
console.log(`isCheckRunEvent: ${isCheckRunEvent}`);
console.log(`workflowRunPrIsNull: ${workflowRunPrIsNull}`);
console.log(`checkRunPrIsNull: ${checkRunPrIsNull}`);
console.log(`isDraftPrWorkflowRun: ${isDraftPrWorkflowRun}`);
console.log(`isDraftPrCheckRun: ${isDraftPrCheckRun}`);
return isDraftPrWorkflowRun || isDraftPrCheckRun;
}
const slackMembers = getSlackMembersToBeNotified();
const isDraftPR = isDraftPullRequest();
let message;
let shouldSendMessage;
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> ${slackMembers}`;
shouldSendMessage = true;
} else {
message = `${name} \`${status}\` \`${conclusion}\` <${url}|View Logs> ${slackMembers}`;
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> ${slackMembers}`;
shouldSendMessage = true;
} else {
message = `${name} \`${status}\` \`${conclusion}\` <${url}|View Logs> ${slackMembers}`;
shouldSendMessage = false;
}
}
if (!isDraftPR && isWorkflowRunEvent) {
handleWorkflowRunEvent();
} else if (!isDraftPR && isCheckRunEvent) {
handleCheckRunEvent();
} else {
message = `Unknown event or draft PR: ${{ 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/slack-github-action@v1.27.0
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 }}"
}
}
]
}