-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmk_release_announce_email.py
executable file
·215 lines (164 loc) · 6.83 KB
/
mk_release_announce_email.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
#!/usr/bin/python3
"""Generate an email to thunderbird-drivers and support
and open a Thunderbird compose window with content
and recipient fields filled in.
The release notes YAML needs to be written as the
rendered notes are attached to the email.
The uplifts need to be pushed, versions updated, and
.gecko_rev.yml pinned to the mozilla revision.
The version and pinning information is pulled from the tip of the
provided repo (version.txt and .gecko_rev.yml).
Example:
./tools/mk_release_announce_email.py comm-esr78
Defaults to using "1" for the build number in the subject line.
To change the build number:
./tools/mk_release_announce_email.py comm-esr78 2
- "thunderbird" must be in $PATH.
"""
import sys
import os
import re
import json
import subprocess
import shutil
from datetime import datetime
from urllib.request import urlopen
from collections import namedtuple
from tools_lib import yaml
import markupsafe
import markdown
GECKO_REV_URL = "https://hg.mozilla.org/releases/{repo}/raw-file/tip/.gecko_rev.yml"
MERCURIAL_TAGS_URL = "https://hg.mozilla.org/releases/{repo}/json-tags"
CUR_VERSION_URL = (
"https://hg.mozilla.org/releases/{repo}/raw-file/tip/mail/config/version.txt"
)
CUR_VERSION_DISPLAY_URL = "https://hg.mozilla.org/releases/{repo}/raw-file/tip/mail/config/version_display.txt"
SOURCE_URL = "https://hg.mozilla.org/releases/{repo}/file/{hash}"
REV_MD_TMPL = "[{link_text}]({link_url})"
RELEASE_EMAIL_SUBJECT = "Thunderbird {release_version} - build {build}"
RELEASE_EMAIL_HTML = """**Thunderbird {release_version}** - build {build} - **{release_date}**
{repo}: {comm_link}
{moz_repo}: {moz_link}
Releases are planned to be complete on the day listed in the notes, during the US work day.
"""
ReleaseRevs = namedtuple("ReleaseRevs", ["comm_rev", "gecko_ref", "gecko_rev"])
def beta_release_date(release_info):
release = release_info["release"]
# Assume if there's no "groups" section, or there's exactly one group item it's beta 1
if "groups" in release and len(release["groups"]) > 1:
# This code relies on the format of the date being found in the first line of "text"
# and the content of that line not changing very much. The date starts after the word release, and
# ends at the ".**" at the end of the line.
date_line = release["text"].split("\n")[0]
match = re.search(r"released (?P<date>[A-Za-z, 0-9]+)\.\*\*", date_line)
if match:
release_date = datetime.strptime(match.group("date"), "%B %d, %Y")
return release_date.strftime("%Y-%m-%d")
raise Exception(f"Unable to find Beta release date in '{date_line}'.")
# Fallback for beta 1
return release["release_date"]
def get_release_date(yaml_file):
if "beta" in yaml_file:
yaml_dir = "beta"
else:
yaml_dir = "release"
yaml_path = os.path.join(yaml_dir, f"{yaml_file}.yml")
release_info = yaml.load(open(yaml_path).read())
if yaml_dir == "beta":
return beta_release_date(release_info)
return release_info["release"]["release_date"]
def get_revs(c_repo):
with urlopen(GECKO_REV_URL.format(repo=c_repo)) as response:
data = response.read()
gecko_rev_data = yaml.load(data)
gecko_ref = gecko_rev_data["GECKO_HEAD_REF"]
gecko_rev = gecko_rev_data["GECKO_HEAD_REV"]
with urlopen(MERCURIAL_TAGS_URL.format(repo=c_repo)) as response:
data = response.read()
tags_data = json.loads(data)
comm_rev = tags_data["node"]
return ReleaseRevs(comm_rev=comm_rev, gecko_ref=gecko_ref, gecko_rev=gecko_rev)
def markdown_render(md_source):
"""Strips the outer <p> element from rendered markdown."""
return re.sub(
"(^<P>|</P>$)",
"",
markupsafe.Markup(markdown.markdown(md_source)),
flags=re.IGNORECASE,
)
def gen_preview(version):
subprocess.run("python preview.py {} email".format(version), shell=True, check=True)
def main(comm_repo, build):
moz_repo = comm_repo.replace("comm", "mozilla")
with urlopen(CUR_VERSION_URL.format(repo=comm_repo)) as response:
data = response.read()
release_version = data.strip().decode("utf-8")
with urlopen(CUR_VERSION_DISPLAY_URL.format(repo=comm_repo)) as response:
data = response.read()
release_display_version = data.strip().decode("utf-8")
revs = get_revs(comm_repo)
comm_source_url = SOURCE_URL.format(repo=comm_repo, hash=revs.comm_rev)
comm_source_text = revs.comm_rev[:12]
comm_link = REV_MD_TMPL.format(link_text=comm_source_text, link_url=comm_source_url)
moz_source_url = SOURCE_URL.format(repo=moz_repo, hash=revs.gecko_rev)
moz_source_text = "{g_ref}/{g_rev}".format(
g_ref=revs.gecko_ref, g_rev=revs.gecko_rev[:12]
)
moz_link = REV_MD_TMPL.format(link_text=moz_source_text, link_url=moz_source_url)
notes_suffix = ""
if comm_repo == "comm-beta":
notes_suffix = "beta"
notes_version = "{}{}".format(release_version, notes_suffix)
release_date = get_release_date(notes_version)
email_subject = RELEASE_EMAIL_SUBJECT.format(
release_version=release_display_version, build=build
)
email_body_html = markdown_render(
RELEASE_EMAIL_HTML.format(
release_version=release_display_version,
release_date=release_date,
build=build,
repo=comm_repo,
moz_repo=moz_repo,
comm_link=comm_link,
moz_link=moz_link,
)
)
gen_preview(notes_version)
attach_fn = "Thunderbird_{}.html".format(release_display_version.replace(".", "_"))
shutil.move("preview.html", attach_fn)
cc = "Thunderbird Support <[email protected]>"
if comm_repo == "comm-beta":
cc += ";TB Beta <[email protected]>"
subprocess.run(
"thunderbird -compose 'format=html','attachment={}','to={}','cc={}','subject={}','body={}'".format(
os.path.abspath(attach_fn),
"Thunderbird Drivers <[email protected]>",
cc,
email_subject,
email_body_html,
),
shell=True,
)
def do_builderr(build_str):
print("Invalid build number: {}".format(build_str))
sys.exit(3)
if __name__ == "__main__":
if not sys.argv[1]:
print("Provide a repository name: comm-beta/comm-esr78/comm-esr91")
sys.exit(1)
if sys.argv[1] not in ("comm-beta", "comm-esr91", "comm-esr102", "comm-esr115"):
print("Invalid repository: {}".format(sys.argv[1]))
sys.exit(2)
if len(sys.argv) < 3:
print("Defaulting to build one")
sys.argv.append("1")
else:
try:
bi = int(sys.argv[2])
except ValueError:
do_builderr(sys.argv[2])
if bi > 5:
# arbitrary limit for giggles
do_builderr(sys.argv[2])
main(*sys.argv[1:])