forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-release.py
440 lines (352 loc) · 15.3 KB
/
make-release.py
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#! /usr/bin/env python3
import os
import signal
import time
import sys
import subprocess
import tempfile
import datetime
import re
RELEASE_VERSION=""
DATE = datetime.date.today().strftime("%d/%m/%Y")
SIGNOFF_REVIEWER = "syrusakbary"
TAG = "master"
if len(sys.argv) > 1:
RELEASE_VERSION = sys.argv[1]
else:
print("no release version as first argument")
sys.exit(1)
if len(sys.argv) > 2:
TAG = sys.argv[2]
RELEASE_VERSION_WITH_V = RELEASE_VERSION
if not(RELEASE_VERSION.startswith("v")):
RELEASE_VERSION_WITH_V = "v" + RELEASE_VERSION
else:
RELEASE_VERSION = RELEASE_VERSION[1:]
if os.system("git --version") != 0:
print("git not installed")
sys.exit(1)
if os.system("gh --version") != 0:
print("gh not installed")
sys.exit(1)
def get_file_string(file):
file_handle = open(file, 'r', newline='')
file_string = file_handle.read()
file_handle.close()
return file_string
def write_file_string(file, file_string):
file_handle = open(file, 'w')
file_handle.write(file_string)
file_handle.close()
def replace(file, pattern, subst):
file_string = get_file_string(file)
file_string = file_string.replace(pattern, subst,1)
write_file_string(file, file_string)
def make_release(version):
gh_logged_in = os.system("gh auth status") == 0
if not(gh_logged_in):
raise Exception("please log in")
import tempfile
temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)
if os.system("git clone https://github.com/wasmerio/wasmer --branch " + TAG + " --depth 1 " + temp_dir.name) != 0:
raise Exception("could not clone github repo")
# generate changelog
proc = subprocess.Popen(['gh', "search", "prs", "--repo", "wasmerio/wasmer", "--merged", "--limit", "100", "--sort", "updated"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
print(proc.stdout)
raise Exception("could not run gh search prs")
lines = []
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if "Release" in line:
break
lines.append(line)
changed = []
added = []
fixed = []
release_notes_changed = []
for l in lines:
fields = l.split("\t")
pr_number = fields[1]
pr_text = fields[3]
l = " - [#" + pr_number + "](https://github.com/wasmerio/wasmer/pull/" + pr_number + ") " + pr_text
release_notes_changed.append(l)
if "add" in l.lower():
added.append(l)
elif "fix" in l.lower():
fixed.append(l)
else:
changed.append(l)
changelog = []
changelog.append("## **Unreleased**")
changelog.append("")
changelog.append("## " + RELEASE_VERSION + " - " + DATE)
changelog.append("")
changelog.append("## Added")
changelog.append("")
for a in added:
changelog.append(a)
changelog.append("")
changelog.append("## Changed")
changelog.append("")
for c in changed:
changelog.append(c)
changelog.append("")
changelog.append("## Fixed")
changelog.append("")
for f in fixed:
changelog.append(f)
changelog.append("")
changelog.append("")
for l in changelog:
print(" " + l)
proc = subprocess.Popen(['gh','search', "prs", "--repo", "wasmerio/wasmer", "--merged", "--sort", "updated"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
already_released_str = ""
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if RELEASE_VERSION + "\t" in line:
already_released_str = line
break
already_released = already_released_str != ""
proc = subprocess.Popen(['gh','pr', "list", "--repo", "wasmerio/wasmer"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
github_link_line = ""
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if "release-" + RELEASE_VERSION + "\t" in line:
github_link_line = line
break
print("github link line" + github_link_line)
if github_link_line != "":
proc = subprocess.Popen(['git','pull', "origin", "release-" + RELEASE_VERSION], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','checkout', "-b", "release-" + RELEASE_VERSION], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','pull', "origin", "release-" + RELEASE_VERSION, "--depth", "1"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','log', "--oneline"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
for line in proc.stdout:
print(line.rstrip())
if github_link_line == "" and not(already_released):
# git checkout -b release-3.0.0-rc.2
proc = subprocess.Popen(['git','checkout', "-b", "release-" + RELEASE_VERSION], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
for line in proc.stdout:
print(line.rstrip())
raise Exception("could not run git checkout -b release-" + RELEASE_VERSION)
replace(temp_dir.name + "/CHANGELOG.md", "## **Unreleased**", "\r\n".join(changelog))
proc = subprocess.Popen(['git','commit', "-am", "Update CHANGELOG"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
for line in proc.stdout:
print(line.rstrip())
raise Exception("could not commit CHANGELOG " + RELEASE_VERSION_WITH_V)
# Update version numbers
update_version_py = get_file_string(temp_dir.name + "/scripts/update-version.py")
previous_version = re.search("NEXT_VERSION=\'(.*)\'", update_version_py).groups(1)[0]
next_version = RELEASE_VERSION
print("updating version " + previous_version + " -> " + next_version)
update_version_py = re.sub("PREVIOUS_VERSION=\'.*\'","PREVIOUS_VERSION='" + previous_version + "'", update_version_py)
update_version_py = re.sub("NEXT_VERSION=\'.*\'","NEXT_VERSION='" + next_version + "'", update_version_py)
write_file_string(temp_dir.name + "/scripts/update-version.py", update_version_py)
proc = subprocess.Popen(['python3', temp_dir.name + "/scripts/update-version.py"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','commit', "-am", "Release " + RELEASE_VERSION], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
for line in proc.stdout:
print(line.rstrip())
raise Exception("could not commit CHANGELOG " + RELEASE_VERSION_WITH_V)
proc = subprocess.Popen(['git','log', "--oneline"], stdout = subprocess.PIPE, cwd = temp_dir.name)
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
print(line)
proc.wait()
proc = subprocess.Popen(['git','push', "-f", "-u", "origin", "release-" + RELEASE_VERSION], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['gh','pr', "create", "--head", "release-" + RELEASE_VERSION, "--title", "Release " + RELEASE_VERSION, "--body", "[bot] Release wasmer version " + RELEASE_VERSION, "--reviewer", SIGNOFF_REVIEWER], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['gh','pr', "list", "--repo", "wasmerio/wasmer"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if "release-" + RELEASE_VERSION + "\t" in line:
github_link_line = line
break
pr_number = ""
if (already_released):
pr_number = already_released_str.split("\t")[1]
print("already released in PR " + pr_number)
else:
pr_number = github_link_line.split("\t")[0]
print("releasing in PR " + pr_number)
while not(already_released):
proc = subprocess.Popen(['gh','pr', "checks", pr_number], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
all_checks_have_passed = True
print("Waiting for checks to pass... PR " + pr_number + " https://github.com/wasmerio/wasmer/pull/" + pr_number)
print("")
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
print(" " + line)
if "no checks reported" in line:
all_checks_have_passed = False
if line.startswith("*") or "pending" in line:
all_checks_have_passed = False
if line.startswith("X") or "fail" in line:
raise Exception("check failed")
if all_checks_have_passed:
break
else:
time.sleep(5)
last_commit = ""
proc = subprocess.Popen(['git','log'], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode == 0:
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
print(line.rstrip())
last_commit = line
break
else:
raise Exception("could not git log branch " + RELEASE_VERSION_WITH_V)
if last_commit == "":
raise Exception("could not get last info")
proc = subprocess.Popen(['git','checkout', "master"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
for line in proc.stdout:
print(line.rstrip())
raise Exception("could not commit checkout master " + RELEASE_VERSION_WITH_V)
if not(already_released):
proc = subprocess.Popen(['gh','pr', "merge", "--auto", pr_number, "--merge", "--delete-branch"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
# wait for bors to merge PR
while not(already_released):
print("git pull origin master...")
proc = subprocess.Popen(['git','pull', "origin", "master", "--depth", "1"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode != 0:
for line in proc.stdout:
print(line.rstrip())
raise Exception("could not pull origin ")
proc = subprocess.Popen(['gh','search', "prs", "--repo", "wasmerio/wasmer", "--merged", "--sort", "updated"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
github_link_line = ""
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if RELEASE_VERSION + "\t" in line:
github_link_line = line
break
current_commit = ""
proc = subprocess.Popen(['git','log'], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode == 0:
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
print(line.rstrip())
current_commit = line
break
else:
raise Exception("could not git log master")
if current_commit == "":
raise Exception("could not get current info")
if github_link_line != "":
print("ok: " + current_commit + " == " + last_commit)
print(github_link_line)
break
else:
time.sleep(20)
# Select the correct merge commit to tag
correct_checkout = ""
proc = subprocess.Popen(['git','log', "--oneline"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
if proc.returncode == 0:
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if "Merge pull request #" + pr_number in line:
correct_checkout = line
else:
raise Exception("could not git log branch " + RELEASE_VERSION_WITH_V)
if correct_checkout == "":
raise Exception("could not get last info")
print(correct_checkout)
checkout_hash = correct_checkout.split(" ")[0]
print("checking out hash " + checkout_hash)
proc = subprocess.Popen(['git','tag', "-d", RELEASE_VERSION_WITH_V], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','push', "-d", "origin", RELEASE_VERSION_WITH_V], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','tag', RELEASE_VERSION_WITH_V, checkout_hash], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
proc = subprocess.Popen(['git','push', "-f", "origin", RELEASE_VERSION_WITH_V], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
# Make release and wait for it to finish
if not(already_released):
proc = subprocess.Popen(['gh','workflow', "run", "build.yml", "--field", "release=" + RELEASE_VERSION_WITH_V, "--ref", RELEASE_VERSION_WITH_V], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
time.sleep(5)
while True:
# gh run list --workflow=build.yml
proc = subprocess.Popen(['gh','run', "list", "--workflow=build.yml"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
workflow_line = ""
if proc.returncode == 0:
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if RELEASE_VERSION_WITH_V in line:
workflow_line = line
break
print("workflow line: " + workflow_line)
if workflow_line.startswith("X"):
raise Exception("release workflow failed")
proc = subprocess.Popen(['gh','release', "list"], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
release_line = ""
if proc.returncode == 0:
for line in proc.stdout:
line = line.decode("utf-8").rstrip()
if RELEASE_VERSION_WITH_V in line:
release_line = line
break
if release_line != "":
break
else:
print("not released yet")
time.sleep(30)
# release done, update release
release_notes = [
"Install this version of wasmer:",
"",
"```sh",
"curl https://get.wasmer.io -sSfL | sh -s \"" + RELEASE_VERSION_WITH_V + "\"",
"```",
"",
]
if not(len(added) == 0) and not(len(changed) == 0):
release_notes.append("## What's Changed")
release_notes.append("")
for a in added:
release_notes.append(a)
for c in changed:
release_notes.append(c)
hash = RELEASE_VERSION + "---" + DATE
hash = hash.replace(".", "")
hash = hash.replace("/", "")
release_notes.append("")
release_notes.append("See full list of changes in the [CHANGELOG](https://github.com/wasmerio/wasmer/blob/master/CHANGELOG.md#" + hash + ")")
proc = subprocess.Popen(['gh','release', "edit", RELEASE_VERSION_WITH_V, "--notes", "\r\n".join(release_notes)], stdout = subprocess.PIPE, cwd = temp_dir.name)
proc.wait()
raise Exception("script done and merged")
try:
make_release(RELEASE_VERSION)
except Exception as err:
while True:
print(str(err))
if os.system("say " + str(err)) != 0:
sys.exit()