-
Notifications
You must be signed in to change notification settings - Fork 29
184 lines (167 loc) · 6.47 KB
/
dependabot-notifications.yml
File metadata and controls
184 lines (167 loc) · 6.47 KB
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
177
178
179
180
181
182
183
name: Dependabot Notifications
# This workflow sends Slack notifications when CI completes for Dependabot PRs.
# It uses workflow_run to trigger AFTER the CI workflow finishes.
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
contents: read
pull-requests: read
actions: read
jobs:
notify-success:
name: Notify Success
runs-on: ubuntu-latest
if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.actor.login == 'dependabot[bot]'
steps:
- name: Get PR information
id: pr-info
uses: actions/github-script@v8
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`
});
if (pullRequests.length > 0) {
const pr = pullRequests[0];
core.setOutput('pr_number', pr.number);
core.setOutput('pr_title', pr.title);
core.setOutput('pr_url', pr.html_url);
core.setOutput('found', 'true');
} else {
core.setOutput('found', 'false');
}
- name: Send Slack notification (Success)
if: steps.pr-info.outputs.found == 'true'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#36a64f",
"blocks": [
{
"type": "header",
"text": {"type": "plain_text", "text": "✅ Dependabot Update - CI Passed", "emoji": true}
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"}
]
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}"}
},
{
"type": "context",
"elements": [{"type": "mrkdwn", "text": "Auto-merge enabled • logzio-python-handler CI"}]
}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
notify-failure:
name: Notify Failure
runs-on: ubuntu-latest
if: |
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.actor.login == 'dependabot[bot]'
steps:
- name: Get PR information
id: pr-info
uses: actions/github-script@v8
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`
});
if (pullRequests.length > 0) {
const pr = pullRequests[0];
core.setOutput('pr_number', pr.number);
core.setOutput('pr_title', pr.title);
core.setOutput('pr_url', pr.html_url);
core.setOutput('found', 'true');
} else {
core.setOutput('found', 'false');
}
- name: Get workflow run URL
id: run-url
run: |
echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT
- name: Send Slack notification (Failure)
if: steps.pr-info.outputs.found == 'true'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#ff0000",
"blocks": [
{
"type": "header",
"text": {"type": "plain_text", "text": "🚨 Dependabot Update - CI Failed", "emoji": true}
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}>"}
]
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "${{ steps.pr-info.outputs.pr_title }}\n\n<${{ steps.run-url.outputs.url }}|View CI Run> to investigate"}
},
{
"type": "context",
"elements": [{"type": "mrkdwn", "text": "Manual intervention required • logzio-python-handler CI"}]
}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
notify-merged:
name: Notify Merged
runs-on: ubuntu-latest
if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
contains(github.event.workflow_run.head_commit.message, 'dependabot')
steps:
- name: Send Slack notification (Merged)
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#2eb886",
"blocks": [
{
"type": "header",
"text": {"type": "plain_text", "text": "🎉 Dependencies Updated Successfully", "emoji": true}
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}|${{ github.event.workflow_run.head_sha }}>"}
]
},
{
"type": "context",
"elements": [{"type": "mrkdwn", "text": "Merged to main • logzio-python-handler CI"}]
}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}