bin/gen_release_notes.py: strip '#' from gitlab bugs
[mesa.git] / bin / gen_release_notes.py
1 #!/usr/bin/env python3
2 # Copyright © 2019 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 textwrap
29 import typing
30 import urllib.parse
31
32 import aiohttp
33 from mako.template import Template
34 from mako import exceptions
35
36
37 CURRENT_GL_VERSION = '4.6'
38 CURRENT_VK_VERSION = '1.1'
39
40 TEMPLATE = Template(textwrap.dedent("""\
41 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
42 <html lang="en">
43 <head>
44 <meta http-equiv="content-type" content="text/html; charset=utf-8">
45 <title>Mesa Release Notes</title>
46 <link rel="stylesheet" type="text/css" href="../mesa.css">
47 </head>
48 <body>
49
50 <div class="header">
51 <h1>The Mesa 3D Graphics Library</h1>
52 </div>
53
54 <iframe src="../contents.html"></iframe>
55 <div class="content">
56
57 <h1>Mesa ${next_version} Release Notes / ${today}</h1>
58
59 <p>
60 %if not bugfix:
61 Mesa ${next_version} is a new development release. People who are concerned
62 with stability and reliability should stick with a previous release or
63 wait for Mesa ${version[:-1]}1.
64 %else:
65 Mesa ${next_version} is a bug fix release which fixes bugs found since the ${version} release.
66 %endif
67 </p>
68 <p>
69 Mesa ${next_version} implements the OpenGL ${gl_version} API, but the version reported by
70 glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) /
71 glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver being used.
72 Some drivers don't support all the features required in OpenGL ${gl_version}. OpenGL
73 ${gl_version} is <strong>only</strong> available if requested at context creation.
74 Compatibility contexts may report a lower version depending on each driver.
75 </p>
76 <p>
77 Mesa ${next_version} implements the Vulkan ${vk_version} API, but the version reported by
78 the apiVersion property of the VkPhysicalDeviceProperties struct
79 depends on the particular driver being used.
80 </p>
81
82 <h2>SHA256 checksum</h2>
83 <pre>
84 TBD.
85 </pre>
86
87
88 <h2>New features</h2>
89
90 <ul>
91 %for f in features:
92 <li>${f}</li>
93 %endfor
94 </ul>
95
96 <h2>Bug fixes</h2>
97
98 <ul>
99 %for b in bugs:
100 <li>${b}</li>
101 %endfor
102 </ul>
103
104 <h2>Changes</h2>
105
106 <ul>
107 %for c, author in changes:
108 %if author:
109 <p>${c}</p>
110 %else:
111 <li>${c}</li>
112 %endif
113 %endfor
114 </ul>
115
116 </div>
117 </body>
118 </html>
119 """))
120
121
122 async def gather_commits(version: str) -> str:
123 p = await asyncio.create_subprocess_exec(
124 'git', 'log', f'mesa-{version}..', '--grep', r'Closes: \(https\|#\).*',
125 stdout=asyncio.subprocess.PIPE)
126 out, _ = await p.communicate()
127 assert p.returncode == 0, f"git log didn't work: {version}"
128 return out.decode().strip()
129
130
131 async def gather_bugs(version: str) -> typing.List[str]:
132 commits = await gather_commits(version)
133
134 issues: typing.List[str] = []
135 for commit in commits.split('\n'):
136 sha, message = commit.split(maxsplit=1)
137 p = await asyncio.create_subprocess_exec(
138 'git', 'log', '--max-count', '1', r'--format=%b', sha,
139 stdout=asyncio.subprocess.PIPE)
140 _out, _ = await p.communicate()
141 out = _out.decode().split('\n')
142 for line in reversed(out):
143 if line.startswith('Closes:'):
144 bug = line.lstrip('Closes:').strip()
145 break
146 else:
147 raise Exception('No closes found?')
148 if bug.startswith('h'):
149 # This means we have a bug in the form "Closes: https://..."
150 issues.append(os.path.basename(urllib.parse.urlparse(bug).path))
151 else:
152 issues.append(bug.lstrip('#'))
153
154 loop = asyncio.get_event_loop()
155 async with aiohttp.ClientSession(loop=loop) as session:
156 results = await asyncio.gather(*[get_bug(session, i) for i in issues])
157 typing.cast(typing.Tuple[str, ...], results)
158 return list(results)
159
160
161 async def get_bug(session: aiohttp.ClientSession, bug_id: str) -> str:
162 """Query gitlab to get the name of the issue that was closed."""
163 # Mesa's gitlab id is 176,
164 url = 'https://gitlab.freedesktop.org/api/v4/projects/176/issues'
165 params = {'iids[]': bug_id}
166 async with session.get(url, params=params) as response:
167 content = await response.json()
168 return content[0]['title']
169
170
171 async def get_shortlog(version: str) -> str:
172 """Call git shortlog."""
173 p = await asyncio.create_subprocess_exec('git', 'shortlog', f'mesa-{version}..',
174 stdout=asyncio.subprocess.PIPE)
175 out, _ = await p.communicate()
176 assert p.returncode == 0, 'error getting shortlog'
177 assert out is not None, 'just for mypy'
178 return out.decode()
179
180
181 def walk_shortlog(log: str) -> typing.Generator[typing.Tuple[str, bool], None, None]:
182 for l in log.split('\n'):
183 if l.startswith(' '): # this means we have a patch description
184 yield l, False
185 else:
186 yield l, True
187
188
189 def calculate_next_version(version: str, is_point: bool) -> str:
190 """Calculate the version about to be released."""
191 if '-' in version:
192 version = version.split('-')[0]
193 if is_point:
194 base = version.split('.')
195 base[2] = str(int(base[2]) + 1)
196 return '.'.join(base)
197 return version
198
199
200 def calculate_previous_version(version: str, is_point: bool) -> str:
201 """Calculate the previous version to compare to.
202
203 In the case of -rc to final that verison is the previous .0 release,
204 (19.3.0 in the case of 20.0.0, for example). for point releases that is
205 the last point release. This value will be the same as the input value
206 for a point release, but different for a major release.
207 """
208 if '-' in version:
209 version = version.split('-')[0]
210 if is_point:
211 return version
212 base = version.split('.')
213 if base[1] == '0':
214 base[0] = str(int(base[0]) - 1)
215 base[1] = '3'
216 else:
217 base[1] = str(int(base[1]) - 1)
218 return '.'.join(base)
219
220
221 def get_features() -> typing.Generator[str, None, None]:
222 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / 'new_features.txt'
223 if p.exists():
224 with p.open('rt') as f:
225 for line in f:
226 yield line
227
228
229 async def main() -> None:
230 v = pathlib.Path(__file__).parent.parent / 'VERSION'
231 with v.open('rt') as f:
232 raw_version = f.read().strip()
233 is_point_release = '-rc' not in raw_version
234 assert '-devel' not in raw_version, 'Do not run this script on -devel'
235 version = raw_version.split('-')[0]
236 previous_version = calculate_previous_version(version, is_point_release)
237 next_version = calculate_next_version(version, is_point_release)
238
239 shortlog, bugs = await asyncio.gather(
240 get_shortlog(previous_version),
241 gather_bugs(previous_version),
242 )
243
244 final = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / f'{next_version}.html'
245 with final.open('wt') as f:
246 try:
247 f.write(TEMPLATE.render(
248 bugfix=is_point_release,
249 bugs=bugs,
250 changes=walk_shortlog(shortlog),
251 features=get_features(),
252 gl_version=CURRENT_GL_VERSION,
253 next_version=next_version,
254 today=datetime.date.today(),
255 version=previous_version,
256 vk_version=CURRENT_VK_VERSION,
257 ))
258 except:
259 print(exceptions.text_error_template().render())
260
261
262 if __name__ == "__main__":
263 loop = asyncio.get_event_loop()
264 loop.run_until_complete(main())