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