Skip to content

Commit e898598

Browse files
committed
Create dependabot-notifications.yml
1 parent f06debb commit e898598

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Dependabot Notifications
2+
3+
# This workflow sends Slack notifications when CI completes for Dependabot PRs.
4+
# It uses workflow_run to trigger AFTER the CI workflow finishes.
5+
6+
7+
on:
8+
workflow_run:
9+
workflows: ["CI"]
10+
types:
11+
- completed
12+
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
actions: read
17+
18+
jobs:
19+
notify-success:
20+
name: Notify Success
21+
runs-on: ubuntu-latest
22+
if: |
23+
github.event.workflow_run.conclusion == 'success' &&
24+
github.event.workflow_run.actor.login == 'dependabot[bot]'
25+
26+
steps:
27+
- name: Get PR information
28+
id: pr-info
29+
uses: actions/github-script@v7
30+
with:
31+
script: |
32+
const { data: pullRequests } = await github.rest.pulls.list({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
state: 'open',
36+
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`
37+
});
38+
39+
if (pullRequests.length > 0) {
40+
const pr = pullRequests[0];
41+
core.setOutput('pr_number', pr.number);
42+
core.setOutput('pr_title', pr.title);
43+
core.setOutput('pr_url', pr.html_url);
44+
core.setOutput('found', 'true');
45+
} else {
46+
core.setOutput('found', 'false');
47+
}
48+
49+
- name: Send Slack notification (Success)
50+
if: steps.pr-info.outputs.found == 'true'
51+
uses: rtCamp/action-slack-notify@v2
52+
env:
53+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
54+
SLACK_COLOR: "#36a64f"
55+
SLACK_USERNAME: "Dependabot"
56+
SLACK_ICON: "https://avatars.githubusercontent.com/in/29110?s=64&v=4"
57+
SLACK_TITLE: "✅ Dependabot Update - CI Passed"
58+
SLACK_MESSAGE: |
59+
*Repository:* ${{ github.repository }}
60+
*PR:* <${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}> ${{ steps.pr-info.outputs.pr_title }}
61+
*Status:* All CI checks passed! Auto-merge has been enabled.
62+
63+
The PR will be automatically merged once all branch protection requirements are satisfied.
64+
SLACK_FOOTER: "logzio-python-handler CI"
65+
66+
67+
notify-failure:
68+
name: Notify Failure
69+
runs-on: ubuntu-latest
70+
if: |
71+
github.event.workflow_run.conclusion == 'failure' &&
72+
github.event.workflow_run.actor.login == 'dependabot[bot]'
73+
74+
steps:
75+
- name: Get PR information
76+
id: pr-info
77+
uses: actions/github-script@v7
78+
with:
79+
script: |
80+
const { data: pullRequests } = await github.rest.pulls.list({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
state: 'open',
84+
head: `${context.repo.owner}:${context.payload.workflow_run.head_branch}`
85+
});
86+
87+
if (pullRequests.length > 0) {
88+
const pr = pullRequests[0];
89+
core.setOutput('pr_number', pr.number);
90+
core.setOutput('pr_title', pr.title);
91+
core.setOutput('pr_url', pr.html_url);
92+
core.setOutput('found', 'true');
93+
} else {
94+
core.setOutput('found', 'false');
95+
}
96+
97+
- name: Get workflow run URL
98+
id: run-url
99+
run: |
100+
echo "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT
101+
102+
- name: Send Slack notification (Failure)
103+
if: steps.pr-info.outputs.found == 'true'
104+
uses: rtCamp/action-slack-notify@v2
105+
env:
106+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
107+
SLACK_COLOR: "#ff0000"
108+
SLACK_USERNAME: "Dependabot"
109+
SLACK_ICON: "https://avatars.githubusercontent.com/in/29110?s=64&v=4"
110+
SLACK_TITLE: "🚨 Dependabot Update - CI Failed"
111+
SLACK_MESSAGE: |
112+
*Repository:* ${{ github.repository }}
113+
*PR:* <${{ steps.pr-info.outputs.pr_url }}|#${{ steps.pr-info.outputs.pr_number }}> ${{ steps.pr-info.outputs.pr_title }}
114+
*Status:* CI checks failed - manual intervention required!
115+
116+
<${{ steps.run-url.outputs.url }}|View CI Run> to investigate the failure.
117+
SLACK_FOOTER: "logzio-python-handler CI"
118+
119+
notify-merged:
120+
name: Notify Merged
121+
runs-on: ubuntu-latest
122+
if: |
123+
github.event.workflow_run.conclusion == 'success' &&
124+
github.event.workflow_run.event == 'push' &&
125+
contains(github.event.workflow_run.head_commit.message, 'dependabot')
126+
127+
steps:
128+
- name: Send Slack notification (Merged)
129+
uses: rtCamp/action-slack-notify@v2
130+
env:
131+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
132+
SLACK_COLOR: "#2eb886"
133+
SLACK_USERNAME: "Dependabot"
134+
SLACK_ICON: "https://avatars.githubusercontent.com/in/29110?s=64&v=4"
135+
SLACK_TITLE: "🎉 Dependencies Updated Successfully"
136+
SLACK_MESSAGE: |
137+
*Repository:* ${{ github.repository }}
138+
*Commit:* <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}|${{ github.event.workflow_run.head_sha }}>
139+
140+
Dependabot updates have been merged and CI passed on main branch.
141+
SLACK_FOOTER: "logzio-python-handler CI"
142+

0 commit comments

Comments
 (0)