-
Notifications
You must be signed in to change notification settings - Fork 14
388 lines (352 loc) · 15.9 KB
/
release_pr.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
name: Release Pull Request
on:
issue_comment:
types: created
jobs:
changelog:
if: |
startsWith(github.event.comment.body, '/changelog')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Fetch all tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set GitHub user
env:
GIT_USER: ${{secrets.GIT_USER}}
GIT_EMAIL: ${{secrets.GIT_EMAIL}}
run: |
git config --local user.name "${GIT_USER}"
git config --local user.email "${GIT_EMAIL}"
- name: Checkout PR branch
id: checkout
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const prHead = pr.data.head.sha;
core.setOutput("pr_head", prHead);
core.setOutput("pr_title", pr.data.title.trim());
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / changelog',
state: 'pending',
});
const { spawnSync } = require("child_process")
const { status, stderr } = spawnSync(`git fetch origin pull/${pr.data.number}/head:${pr.data.head.ref} && git checkout ${pr.data.head.ref} && git push --set-upstream origin ${pr.data.head.ref}`, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'error',
description: 'Failed checking out PR branch',
}));
core.setFailed('Failed checking out PR branch');
}
- name: Validate
id: validation
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prTitle = "${{ steps.checkout.outputs.pr_title }}";
const prTitleWords = prTitle.split(' ');
const version = prTitleWords[prTitleWords.length - 1];
core.setOutput("version", version);
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(`./scripts/release/validate.sh ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'failure',
description: 'Failed validating release Pull Request',
details: stderr.toString(),
}));
core.setFailed('Validation failed!');
}
- name: Generate changelog
if: success()
uses: actions/github-script@v6
env:
GHC_GITHUB_TOKEN: ${{secrets.GH_RELEASE_TOKEN}}
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const version = "${{ steps.validation.outputs.version }}";
const prHead = "${{ steps.checkout.outputs.pr_head }}";
const changelogCmd = `sed -i '/changelog:generate/q' docs/modules/ROOT/pages/release_notes/${version}.adoc && $(curl -sL http://git.io/install-ghc | bash -s -- --path-only)/ghc generate -r maistra/istio-workspace --format adoc >> docs/modules/ROOT/pages/release_notes/${version}.adoc`;
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(changelogCmd, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'failure',
description: 'Failed generating changelog',
details: stderr.toString(),
}));
core.setFailed('Failed generating changelog');
} else {
const pushCmd = `git add . && git commit -m"release: adds changelog for ${version}" -m"/skip-e2e" -m"/skip-build" && git push && git rev-parse --short HEAD`;
const { status, stderr, stdout } = spawnSync(pushCmd, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / changelog',
state: 'error',
description: 'Failed committing release changelog',
}));
core.setFailed('Failed committing changelog');
} else {
const { status, stderr, stdout } = spawnSync('echo -n $(git rev-parse HEAD)', {shell: true});
core.exportVariable("STATUS", JSON.stringify({ sha: stdout.toString(),
context: 'release / changelog',
state: 'success',
description: 'Changelog generated',
}));
}
}
- name: Publish job status and comment with details
if: always()
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const status = ${{env.STATUS}};
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: status.sha,
context: status.context,
state: status.state,
description: status.description,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
if (status.details) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ ${status.description}\n\n${status.details}`,
});
}
release:
if: |
startsWith(github.event.comment.body, '/release')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fetch all tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set GitHub user
env:
GIT_USER: ${{secrets.GIT_USER}}
GIT_EMAIL: ${{secrets.GIT_EMAIL}}
run: |
git config --local user.name "${GIT_USER}"
git config --local user.email "${GIT_EMAIL}"
- name: Checkout PR branch
id: checkout
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const prHead = pr.data.head.sha;
core.setOutput("pr_head", prHead);
core.setOutput("pr_title", pr.data.title.trim());
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / commits',
state: 'pending',
});
const { spawnSync } = require("child_process")
const { status, stderr } = spawnSync(`git fetch origin pull/${pr.data.number}/head:${pr.data.head.ref} && git checkout ${pr.data.head.ref} && git push --set-upstream origin ${pr.data.head.ref}`, {shell: true});
if (status != 0) {
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'error',
description: 'Failed checking out PR branch',
}));
core.setFailed('Failed checking out PR branch');
}
- name: Validate
id: validation
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prTitle = "${{ steps.checkout.outputs.pr_title }}";
const prTitleWords = prTitle.split(' ');
const version = prTitleWords[prTitleWords.length - 1];
core.setOutput("version", version);
const { spawnSync } = require("child_process");
const { status, stderr } = spawnSync(`./scripts/release/validate.sh ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'failure',
description: 'Failed validating release Pull Request',
details: stderr.toString(),
}));
core.setFailed('Validation failed!');
}
- name: Release commits
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const version = "${{ steps.validation.outputs.version }}";
const { spawnSync } = require("child_process");
const { status, stderr} = spawnSync(`./scripts/release/release.sh -v ${version}`, {shell: true});
if (status != 0) {
const prHead = "${{ steps.checkout.outputs.pr_head }}";
core.exportVariable("STATUS", JSON.stringify({ sha: prHead,
context: 'release / commits',
state: 'failure',
description: 'Unable to create release-related commits',
details: stderr.toString(),
}));
core.setFailed(`Release failed!`);
} else {
const { status, stderr, stdout } = spawnSync('echo -n $(git rev-parse HEAD)', {shell: true});
core.exportVariable("STATUS", JSON.stringify({ sha: stdout.toString(),
context: 'release / commits',
state: 'success',
description: 'Additional release-related commits created',
}));
}
- name: Publish job status and comment with details
if: always()
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const status = ${{env.STATUS}};
const result = await github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: status.sha,
context: status.context,
state: status.state,
description: status.description,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
if (status.details) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ ${status.description}\n\n${status.details}`,
});
}
shipit:
if: |
startsWith(github.event.comment.body, '/shipit')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- name: Populate PR Head
id: pr_head
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput("sha", pr.data.head.sha);
- name: Rebase on master
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
const prHead = "${{ steps.pr_head.outputs.sha }}";
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'pending',
});
github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: 'rebase'
}).then(() => {
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'success',
description: 'New version has been shipped!',
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🎇 🎉 🎆 New version has been shipped! 🚀🚀🚀'
});
}).catch((data) => {
github.request("POST /repos/:owner/:repo/statuses/:sha", {
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHead,
context: 'release / shipit',
state: 'error',
description: `${data.message}`,
target_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}",
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `#### ⚠ Failed rebasing release PR\n\n${data.message}`
});
core.setFailed('Release rebase failed!');
});
help:
if: |
startsWith(github.event.comment.body, '/help')
&& (contains(github.event.comment.author_association, 'MEMBER')
|| contains(github.event.comment.author_association, 'OWNER')
|| contains(github.event.comment.author_association, 'COLLABORATOR'))
runs-on: ubuntu-latest
steps:
- name: Comment with docs
id: comment-help
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_RELEASE_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "### ℹ️ Available commands\n\n * `/changelog` will append changelog based on the closed PRs since last release to provided release notes.\n\n * `/release` will add release-related commits to this PR on your behalf. \n\n * `/shipit` will rebase everything on master branch and trigger actual release process"
});