This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
75 lines (70 loc) · 2.58 KB
/
notifications.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
name: Notification
on:
workflow_run:
branches: main
workflows:
- "CI"
- "CodeQL"
- "Fossa"
- "Lint"
types:
- completed
jobs:
on-failure:
runs-on: ubuntu-20.04
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Data
uses: actions/github-script@v6
continue-on-error: true
id: data
with:
script: |
const message = context.payload.workflow_run.head_commit.message
message_sanitized = message.split('\n')[0]
const check_data = (await github.rest.checks.listForRef({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
ref: context.payload.workflow_run.head_commit.id,
})).data.check_runs.filter(check_run => check_run.conclusion === 'failure')[0]
return {
job_name: check_data.name,
job_url: check_data.html_url,
commit_message: message_sanitized,
}
- name: Send Notification
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
username: 'Github',
icon_emoji: ':github:',
mention: 'channel',
attachments: [{
title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ github.event.workflow_run.event }})',
color: 'danger',
fields: [{
title: 'Commit',
value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ fromJSON(steps.data.outputs.result).commit_message }}>`,
short: true
},
{
title: 'Failed Job',
value: `<${{ fromJSON(steps.data.outputs.result).job_url }}|${{ fromJSON(steps.data.outputs.result).job_name }}>`,
short: true
},
{
title: 'Author',
value: `${{ github.event.workflow_run.head_commit.author.name }}`,
short: true
},
{
title: 'Pipeline URL',
value: `<https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|${{ github.event.workflow_run.id }}>`,
short: true
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}