Skip to content

Commit 3a786ae

Browse files
authored
Update Slack notification (#94)
1 parent 83aa27c commit 3a786ae

File tree

3 files changed

+75
-103
lines changed

3 files changed

+75
-103
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,58 +69,3 @@ jobs:
6969
run: make test
7070
env:
7171
NGINX_PLUS_VERSION: nightly
72-
73-
notify:
74-
name: Notify
75-
runs-on: ubuntu-20.04
76-
needs: build
77-
if: always() && github.ref == 'refs/heads/main'
78-
steps:
79-
- name: Workflow Status
80-
id: check
81-
uses: martialonline/workflow-status@v2
82-
- name: Output Variables
83-
id: commit
84-
run: |
85-
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
86-
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
87-
- name: Send Notification
88-
uses: 8398a7/action-slack@v3
89-
if:
90-
steps.check.outputs.status == 'failure' ||
91-
steps.check.outputs.status == 'cancelled'
92-
with:
93-
status: custom
94-
custom_payload: |
95-
{
96-
username: 'Github',
97-
icon_emoji: ':octocat:',
98-
mention: 'channel',
99-
attachments: [{
100-
title: '[${{ steps.commit.outputs.repo }}] ${{ github.workflow }} pipeline has failed',
101-
color: '${{ steps.check.outputs.status }}' == 'failure' ? 'danger' : 'warning',
102-
fields: [{
103-
title: 'Commit Hash',
104-
value: '${{ steps.commit.outputs.sha }}',
105-
short: true
106-
},
107-
{
108-
title: 'Author',
109-
value: '${{ github.actor }}',
110-
short: true
111-
},
112-
{
113-
title: 'Commit Message',
114-
value: `${{ github.event.head_commit.message }}`,
115-
short: false
116-
},
117-
{
118-
title: 'Pipeline URL',
119-
value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
120-
short: false
121-
}]
122-
}]
123-
}
124-
env:
125-
GITHUB_TOKEN: ${{ github.token }}
126-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

.github/workflows/fossa.yml

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,3 @@ jobs:
1919
uses: fossas/fossa-action@v1
2020
with:
2121
api-key: ${{ secrets.FOSSA_TOKEN }}
22-
23-
notify:
24-
name: Notify
25-
runs-on: ubuntu-20.04
26-
needs: scan
27-
if: always()
28-
steps:
29-
- name: Workflow Status
30-
id: check
31-
uses: martialonline/workflow-status@v2
32-
- name: Output Variables
33-
id: commit
34-
run: |
35-
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
36-
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
37-
- name: Send Notification
38-
uses: 8398a7/action-slack@v3
39-
if: steps.check.outputs.status == 'failure'
40-
with:
41-
status: custom
42-
custom_payload: |
43-
{
44-
username: 'Fossa Scan',
45-
icon_emoji: ':fossa:',
46-
mention: 'channel',
47-
attachments: [{
48-
title: '${{ steps.commit.outputs.repo }} ${{ github.workflow }} license scan has failed',
49-
color: 'danger',
50-
fields: [{
51-
title: 'Commit Hash',
52-
value: '${{ steps.commit.outputs.sha }}',
53-
short: true
54-
},
55-
{
56-
title: 'Author',
57-
value: '${{ github.actor }}',
58-
short: true
59-
},
60-
{
61-
title: 'Job URL',
62-
value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
63-
short: false
64-
}]
65-
}]
66-
}
67-
env:
68-
GITHUB_TOKEN: ${{ github.token }}
69-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

.github/workflows/notifications.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Notification
2+
3+
on:
4+
workflow_run:
5+
branches: main
6+
workflows:
7+
- "Continuous Integration"
8+
- "CodeQL"
9+
- "Fossa"
10+
- "Lint"
11+
types:
12+
- completed
13+
14+
jobs:
15+
on-failure:
16+
runs-on: ubuntu-20.04
17+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
18+
steps:
19+
- name: Data
20+
uses: actions/github-script@v6
21+
continue-on-error: true
22+
id: data
23+
with:
24+
script: |
25+
const message = context.payload.workflow_run.head_commit.message
26+
message_sanitized = message.split('\n')[0]
27+
28+
const check_data = (await github.rest.checks.listForRef({
29+
owner: context.payload.repository.owner.login,
30+
repo: context.payload.repository.name,
31+
ref: context.payload.workflow_run.head_commit.id,
32+
})).data.check_runs.filter(check_run => check_run.conclusion === 'failure')[0]
33+
34+
return {
35+
job_name: check_data.name,
36+
job_url: check_data.html_url,
37+
commit_message: message_sanitized,
38+
}
39+
40+
- name: Send Notification
41+
uses: 8398a7/action-slack@v3
42+
with:
43+
status: custom
44+
custom_payload: |
45+
{
46+
username: 'Github',
47+
icon_emoji: ':github:',
48+
mention: 'channel',
49+
attachments: [{
50+
title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ github.event.workflow_run.event }})',
51+
color: 'danger',
52+
fields: [{
53+
title: 'Commit',
54+
value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ fromJSON(steps.data.outputs.result).commit_message }}>`,
55+
short: true
56+
},
57+
{
58+
title: 'Failed Job',
59+
value: `<${{ fromJSON(steps.data.outputs.result).job_url }}|${{ fromJSON(steps.data.outputs.result).job_name }}>`,
60+
short: true
61+
},
62+
{
63+
title: 'Author',
64+
value: `${{ github.event.workflow_run.head_commit.author.name }}`,
65+
short: true
66+
},
67+
{
68+
title: 'Pipeline URL',
69+
value: `<https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|${{ github.event.workflow_run.id }}>`,
70+
short: true
71+
}]
72+
}]
73+
}
74+
env:
75+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

0 commit comments

Comments
 (0)