-
Notifications
You must be signed in to change notification settings - Fork 29
192 lines (177 loc) · 8.03 KB
/
Copy pathdependency-automerge.yml
File metadata and controls
192 lines (177 loc) · 8.03 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
184
185
186
187
188
189
190
191
name: Dependency Auto-Merge
# This workflow runs AFTER CI completes for Dependabot and Cycode PRs.
# It handles squash merge AND notifications in sequence.
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
contents: write
pull-requests: write
jobs:
process-dependency-update:
name: Process Dependency Update PR
runs-on: ubuntu-latest
if: |
(github.event.workflow_run.actor.login == 'dependabot[bot]' ||
github.event.workflow_run.actor.login == 'cycode-security[bot]') &&
github.event.workflow_run.event == 'pull_request'
steps:
- name: Get PR information
id: pr
uses: actions/github-script@v9
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('number', pr.number);
core.setOutput('title', pr.title);
core.setOutput('url', pr.html_url);
core.setOutput('found', 'true');
core.setOutput('author', pr.user.login);
// Check if major update from PR title
const majorPattern = /from \d+\.\d+\.\d+ to (\d+)\./;
const match = pr.title.match(majorPattern);
if (match) {
const fromMajor = pr.title.match(/from (\d+)\./);
const toMajor = match[1];
core.setOutput('is_major', fromMajor && fromMajor[1] !== toMajor ? 'true' : 'false');
} else {
core.setOutput('is_major', 'false');
}
console.log(`Found PR #${pr.number}: ${pr.title}`);
} else {
core.setOutput('found', 'false');
console.log('No matching PR found');
}
- name: Notify Slack - CI Failed
if: |
github.event.workflow_run.conclusion == 'failure' &&
steps.pr.outputs.found == 'true'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#ff0000",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": "🚨 Dependency Update - CI Failed"}},
{"type": "section", "fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}>"}
]},
{"type": "section", "text": {"type": "mrkdwn", "text": "*Author:* ${{ steps.pr.outputs.author }}\n${{ steps.pr.outputs.title }}\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}|View CI Run>"}}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
- name: Notify Slack - Major Update
if: |
github.event.workflow_run.conclusion == 'success' &&
steps.pr.outputs.found == 'true' &&
steps.pr.outputs.is_major == 'true'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#ffa500",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": "⚠️ Major Update - Manual Review Required"}},
{"type": "section", "fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}>"}
]},
{"type": "section", "text": {"type": "mrkdwn", "text": "*Author:* ${{ steps.pr.outputs.author }}\n${{ steps.pr.outputs.title }}\n\nReview changelog for breaking changes."}}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
- name: Squash merge PR
id: merge
if: |
github.event.workflow_run.conclusion == 'success' &&
steps.pr.outputs.found == 'true' &&
steps.pr.outputs.is_major != 'true'
run: |
if gh pr merge ${{ steps.pr.outputs.number }} --squash --repo ${{ github.repository }}; then
echo "result=success" >> $GITHUB_OUTPUT
else
echo "result=failed" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify Slack - Squash Merged
if: |
github.event.workflow_run.conclusion == 'success' &&
steps.pr.outputs.found == 'true' &&
steps.pr.outputs.is_major != 'true' &&
steps.merge.outputs.result == 'success'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#36a64f",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": "✅ Dependency Update - Squash Merged"}},
{"type": "section", "fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}>"}
]},
{"type": "section", "text": {"type": "mrkdwn", "text": "*Author:* ${{ steps.pr.outputs.author }}\n${{ steps.pr.outputs.title }}"}}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
- name: Notify Slack - Merge Failed
if: |
github.event.workflow_run.conclusion == 'success' &&
steps.pr.outputs.found == 'true' &&
steps.pr.outputs.is_major != 'true' &&
steps.merge.outputs.result == 'failed'
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#ff0000",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": "🚨 Merge Failed"}},
{"type": "section", "fields": [
{"type": "mrkdwn", "text": "*Repository:*\n${{ github.repository }}"},
{"type": "mrkdwn", "text": "*PR:*\n<${{ steps.pr.outputs.url }}|#${{ steps.pr.outputs.number }}>"}
]},
{"type": "section", "text": {"type": "mrkdwn", "text": "*Author:* ${{ steps.pr.outputs.author }}\n${{ steps.pr.outputs.title }}\n\nCould not merge PR. Manual intervention required."}}
]
}]
}' "$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') ||
contains(github.event.workflow_run.head_commit.message, 'cycode'))
steps:
- name: Send Slack notification
run: |
curl -X POST -H 'Content-type: application/json' --data '{
"attachments": [{
"color": "#2eb886",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": "🎉 Dependencies Updated Successfully"}},
{"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 }}|View>"}
]}
]
}]
}' "$SLACK_WEBHOOK"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}