c72e440495bfc55c46f78c8847942e771182dd16
[mesa.git] / bin / gen_release_notes.py
1 #!/usr/bin/env python3
2 # Copyright © 2019-2020 Intel Corporation
3
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
10
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
13
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21
22 """Generates release notes for a given version of mesa."""
23
24 import asyncio
25 import datetime
26 import os
27 import pathlib
28 import sys
29 import textwrap
30 import typing
31 import urllib.parse
32
33 import aiohttp
34 from mako.template import Template
35 from mako import exceptions
36
37
38 CURRENT_GL_VERSION = '4.6'
39 CURRENT_VK_VERSION = '1.2'
40
41 TEMPLATE = Template(textwrap.dedent("""\
42 ${header}
43 ${header_underline}
44
45 %if not bugfix:
46 Mesa ${this_version} is a new development release. People who are concerned
47 with stability and reliability should stick with a previous release or
48 wait for Mesa ${this_version[:-1]}1.
49 %else:
50 Mesa ${this_version} is a bug fix release which fixes bugs found since the ${previous_version} release.
51 %endif
52
53 Mesa ${this_version} implements the OpenGL ${gl_version} API, but the version reported by
54 glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) /
55 glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver being used.
56 Some drivers don't support all the features required in OpenGL ${gl_version}. OpenGL
57 ${gl_version} is **only** available if requested at context creation.
58 Compatibility contexts may report a lower version depending on each driver.
59
60 Mesa ${this_version} implements the Vulkan ${vk_version} API, but the version reported by
61 the apiVersion property of the VkPhysicalDeviceProperties struct
62 depends on the particular driver being used.
63
64 SHA256 checksum
65 ---------------
66
67 ::
68
69 TBD.
70
71
72 New features
73 ------------
74
75 %for f in features:
76 - ${f}
77 %endfor
78
79
80 Bug fixes
81 ---------
82
83 %for b in bugs:
84 - ${b}
85 %endfor
86
87
88 Changes
89 -------
90 %for c, author_line in changes:
91 %if author_line:
92
93 ${c}
94
95 %else:
96 - ${c}
97 %endif
98 %endfor
99 """))
100
101
102 async def gather_commits(version: str) -> str:
103 p = await asyncio.create_subprocess_exec(
104 'git', 'log', '--oneline', f'mesa-{version}..', '--grep', r'Closes: \(https\|#\).*',
105 stdout=asyncio.subprocess.PIPE)
106 out, _ = await p.communicate()
107 assert p.returncode == 0, f"git log didn't work: {version}"
108 return out.decode().strip()
109
110
111 async def gather_bugs(version: str) -> typing.List[str]:
112 commits = await gather_commits(version)
113
114 issues: typing.List[str] = []
115 for commit in commits.split('\n'):
116 sha, message = commit.split(maxsplit=1)
117 p = await asyncio.create_subprocess_exec(
118 'git', 'log', '--max-count', '1', r'--format=%b', sha,
119 stdout=asyncio.subprocess.PIPE)
120 _out, _ = await p.communicate()
121 out = _out.decode().split('\n')
122 for line in reversed(out):
123 if line.startswith('Closes:'):
124 bug = line.lstrip('Closes:').strip()
125 break
126 else:
127 raise Exception('No closes found?')
128 if bug.startswith('h'):
129 # This means we have a bug in the form "Closes: https://..."
130 issues.append(os.path.basename(urllib.parse.urlparse(bug).path))
131 else:
132 issues.append(bug.lstrip('#'))
133
134 loop = asyncio.get_event_loop()
135 async with aiohttp.ClientSession(loop=loop) as session:
136 results = await asyncio.gather(*[get_bug(session, i) for i in issues])
137 typing.cast(typing.Tuple[str, ...], results)
138 bugs = list(results)
139 if not bugs:
140 bugs = ['None']
141 return bugs
142
143
144 async def get_bug(session: aiohttp.ClientSession, bug_id: str) -> str:
145 """Query gitlab to get the name of the issue that was closed."""
146 # Mesa's gitlab id is 176,
147 url = 'https://gitlab.freedesktop.org/api/v4/projects/176/issues'
148 params = {'iids[]': bug_id}
149 async with session.get(url, params=params) as response:
150 content = await response.json()
151 return content[0]['title']
152
153
154 async def get_shortlog(version: str) -> str:
155 """Call git shortlog."""
156 p = await asyncio.create_subprocess_exec('git', 'shortlog', f'mesa-{version}..',
157 stdout=asyncio.subprocess.PIPE)
158 out, _ = await p.communicate()
159 assert p.returncode == 0, 'error getting shortlog'
160 assert out is not None, 'just for mypy'
161 return out.decode()
162
163
164 def walk_shortlog(log: str) -> typing.Generator[typing.Tuple[str, bool], None, None]:
165 for l in log.split('\n'):
166 if l.startswith(' '): # this means we have a patch description
167 yield l.lstrip(), False
168 elif l.strip():
169 yield l, True
170
171
172 def calculate_next_version(version: str, is_point: bool) -> str:
173 """Calculate the version about to be released."""
174 if '-' in version:
175 version = version.split('-')[0]
176 if is_point:
177 base = version.split('.')
178 base[2] = str(int(base[2]) + 1)
179 return '.'.join(base)
180 return version
181
182
183 def calculate_previous_version(version: str, is_point: bool) -> str:
184 """Calculate the previous version to compare to.
185
186 In the case of -rc to final that verison is the previous .0 release,
187 (19.3.0 in the case of 20.0.0, for example). for point releases that is
188 the last point release. This value will be the same as the input value
189 for a point release, but different for a major release.
190 """
191 if '-' in version:
192 version = version.split('-')[0]
193 if is_point:
194 return version
195 base = version.split('.')
196 if base[1] == '0':
197 base[0] = str(int(base[0]) - 1)
198 base[1] = '3'
199 else:
200 base[1] = str(int(base[1]) - 1)
201 return '.'.join(base)
202
203
204 def get_features(is_point_release: bool) -> typing.Generator[str, None, None]:
205 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / 'new_features.txt'
206 if p.exists():
207 if is_point_release:
208 print("WARNING: new features being introduced in a point release", file=sys.stderr)
209 with p.open('rt') as f:
210 for line in f:
211 yield line
212 else:
213 yield "None"
214 p.unlink()
215 else:
216 yield "None"
217
218
219 async def main() -> None:
220 v = pathlib.Path(__file__).parent.parent / 'VERSION'
221 with v.open('rt') as f:
222 raw_version = f.read().strip()
223 is_point_release = '-rc' not in raw_version
224 assert '-devel' not in raw_version, 'Do not run this script on -devel'
225 version = raw_version.split('-')[0]
226 previous_version = calculate_previous_version(version, is_point_release)
227 this_version = calculate_next_version(version, is_point_release)
228 today = datetime.date.today()
229 header = f'Mesa {this_version} Release Notes / {today}'
230 header_underline = '=' * len(header)
231
232 shortlog, bugs = await asyncio.gather(
233 get_shortlog(previous_version),
234 gather_bugs(previous_version),
235 )
236
237 final = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / f'{this_version}.rst'
238 with final.open('wt') as f:
239 try:
240 f.write(TEMPLATE.render(
241 bugfix=is_point_release,
242 bugs=bugs,
243 changes=walk_shortlog(shortlog),
244 features=get_features(is_point_release),
245 gl_version=CURRENT_GL_VERSION,
246 this_version=this_version,
247 header=header,
248 header_underline=header_underline,
249 previous_version=previous_version,
250 vk_version=CURRENT_VK_VERSION,
251 ))
252 except:
253 print(exceptions.text_error_template().render())
254
255
256 if __name__ == "__main__":
257 loop = asyncio.get_event_loop()
258 loop.run_until_complete(main())