-
Notifications
You must be signed in to change notification settings - Fork 688
/
release-create-github
executable file
·115 lines (94 loc) · 3.79 KB
/
release-create-github
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
#!/usr/bin/env python3
"""Creates github release for tag
"""
import fileinput
import os.path
import os
import sys
from contextlib import contextmanager
from typing import Generator
from lib import re_ga, get_gh_repo, re_ea
from lib.uiutil import Checker, CheckResult, run, run_txtcapture
RELEASE_TITLE_FORMAT = "Emissary Ingress {release_version}"
RELEASE_BODY_FORMAT= """
## :tada: Emissary Ingress {release_version} :tada:
#### Emissary Ingress is an open source, Kubernetes-native microservices API gateway built on the Envoy Proxy.
Upgrade Emissary - https://www.getambassador.io/reference/upgrading.html
View changelog - https://github.com/emissary-ingress/emissary/blob/{git_tag}/CHANGELOG.md
Get started with Emissary on Kubernetes - https://www.getambassador.io/user-guide/getting-started
{release_notes}
"""
def main(release_version: str) -> int:
# This context manager and check function are pretty much just to produce
# a nice list of steps...
in_ci = os.getenv('CI') != ''
checker = Checker()
@contextmanager
def check(name: str) -> Generator[CheckResult, None, None]:
with checker.check(name) as subcheck:
# time.sleep(1) # it's stupid, but honestly the delay makes the output more readable
yield subcheck
with check(f"Check that tag v{release_version} exists"):
if not in_ci:
run(['git', 'fetch', '--tags'])
run(['git', 'rev-parse', '--verify', f"v{release_version}"])
if not checker.ok:
return 1
buf = ""
with check(f"Creating release notes for {release_version}"):
# TODO: Rewrite this to use `docs/releaseNotes.yml` instead of
# `CHANGELOG.md`.
in_changelog = False
for line in fileinput.FileInput("CHANGELOG.md"):
if in_changelog:
if line.startswith("## ") or line == "### Ambassador Edge Stack only\n":
break
if line.startswith(f"[{release_version}]: https://github.com/"):
continue
if line == "### Emissary-ingress and Ambassador Edge Stack\n":
continue
buf += line
if line.startswith(f"## [{release_version}] "):
in_changelog = True
buf = buf.strip()
if buf == "":
raise Exception(f"Changelog entry for {release_version} not found. Are you sure you're trying to release that?")
print(f"Generated release notes:")
print(buf)
if not in_ci:
ok = input("Does this look correct? (y/n)")
if ok != 'y':
print('Ok, not generating release')
return 1
with check(f"Creating release for {release_version}"):
run([
"gh", "release", "create",
f"v{release_version}",
"--repo", get_gh_repo(),
"--title", RELEASE_TITLE_FORMAT.format(release_version=release_version),
"--notes", RELEASE_BODY_FORMAT.format(
release_version=release_version,
release_notes=buf,
git_tag="v"+release_version,
)])
if not checker.ok:
return 1
url = run_txtcapture([
"gh", "release", "view",
"--json=url",
"--jq=.url",
"--repo="+get_gh_repo(),
"v"+release_version])
print(f'echo "url={url}" >> $GITHUB_OUTPUT')
if os.getenv("AMBASSADOR_RELENG_NO_GUI") == '':
print('Release info from github:')
run(["gh", "release", "view", "--repo="+get_gh_repo(), f"v{release_version}"])
return 0
if __name__ == '__main__':
args = sys.argv[1:]
if len(args) < 1 or (not re_ga.match(args[0]) and not re_ea.match(args[0])):
sys.stderr.write(f"Usage: {os.path.basename(sys.argv[0])} X.Y.Z(-ea)?\n")
sys.exit(2)
sys.exit(main(
release_version=args[0],
))