blob: 716f807b3174b9c288fc30adf83c10b25e07e720 [file] [log] [blame]
Dylan Baker86079442019-09-25 14:56:21 -07001#!/usr/bin/env python3
Dylan Baker0123b8f2020-03-05 14:04:04 -08002# Copyright © 2019-2020 Intel Corporation
Dylan Baker86079442019-09-25 14:56:21 -07003
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
24import asyncio
25import datetime
26import os
27import pathlib
Eric Engestromae2d0452020-07-09 01:25:39 +020028import subprocess
Dylan Baker8a4541a2019-10-24 13:11:40 -070029import sys
Dylan Baker86079442019-09-25 14:56:21 -070030import textwrap
31import typing
32import urllib.parse
33
34import aiohttp
35from mako.template import Template
36from mako import exceptions
37
38
39CURRENT_GL_VERSION = '4.6'
Eric Engestrom2557d612020-03-06 19:12:26 +010040CURRENT_VK_VERSION = '1.2'
Dylan Baker86079442019-09-25 14:56:21 -070041
42TEMPLATE = Template(textwrap.dedent("""\
Eric Engestrom8bc055f2020-04-29 02:02:28 +020043 ${header}
44 ${header_underline}
Dylan Baker86079442019-09-25 14:56:21 -070045
Dylan Baker69f540c2019-10-09 10:27:13 -070046 %if not bugfix:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020047 Mesa ${this_version} is a new development release. People who are concerned
48 with stability and reliability should stick with a previous release or
49 wait for Mesa ${this_version[:-1]}1.
Dylan Baker86079442019-09-25 14:56:21 -070050 %else:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020051 Mesa ${this_version} is a bug fix release which fixes bugs found since the ${previous_version} release.
Dylan Baker86079442019-09-25 14:56:21 -070052 %endif
Eric Engestrom8bc055f2020-04-29 02:02:28 +020053
Eric Engestrom3aa83d82020-03-09 12:58:05 +010054 Mesa ${this_version} implements the OpenGL ${gl_version} API, but the version reported by
Dylan Baker86079442019-09-25 14:56:21 -070055 glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) /
56 glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver being used.
57 Some drivers don't support all the features required in OpenGL ${gl_version}. OpenGL
Eric Engestrom8bc055f2020-04-29 02:02:28 +020058 ${gl_version} is **only** available if requested at context creation.
Dylan Baker86079442019-09-25 14:56:21 -070059 Compatibility contexts may report a lower version depending on each driver.
Eric Engestrom8bc055f2020-04-29 02:02:28 +020060
Eric Engestrom3aa83d82020-03-09 12:58:05 +010061 Mesa ${this_version} implements the Vulkan ${vk_version} API, but the version reported by
Dylan Baker86079442019-09-25 14:56:21 -070062 the apiVersion property of the VkPhysicalDeviceProperties struct
63 depends on the particular driver being used.
Dylan Baker86079442019-09-25 14:56:21 -070064
Eric Engestrom8bc055f2020-04-29 02:02:28 +020065 SHA256 checksum
66 ---------------
67
68 ::
69
70 TBD.
Dylan Baker86079442019-09-25 14:56:21 -070071
72
Eric Engestrom8bc055f2020-04-29 02:02:28 +020073 New features
74 ------------
Dylan Baker86079442019-09-25 14:56:21 -070075
Dylan Baker86079442019-09-25 14:56:21 -070076 %for f in features:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020077 - ${f}
Dylan Baker86079442019-09-25 14:56:21 -070078 %endfor
Dylan Baker86079442019-09-25 14:56:21 -070079
Dylan Baker86079442019-09-25 14:56:21 -070080
Eric Engestrom8bc055f2020-04-29 02:02:28 +020081 Bug fixes
82 ---------
83
Dylan Baker86079442019-09-25 14:56:21 -070084 %for b in bugs:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020085 - ${b}
Dylan Baker86079442019-09-25 14:56:21 -070086 %endfor
Dylan Baker86079442019-09-25 14:56:21 -070087
Dylan Baker86079442019-09-25 14:56:21 -070088
Eric Engestrom8bc055f2020-04-29 02:02:28 +020089 Changes
90 -------
91 %for c, author_line in changes:
92 %if author_line:
93
94 ${c}
95
Dylan Baker86079442019-09-25 14:56:21 -070096 %else:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020097 - ${c}
Dylan Baker86079442019-09-25 14:56:21 -070098 %endif
99 %endfor
Dylan Baker86079442019-09-25 14:56:21 -0700100 """))
101
102
103async def gather_commits(version: str) -> str:
104 p = await asyncio.create_subprocess_exec(
Eric Engestromd7a70fb2020-03-05 23:09:45 +0100105 'git', 'log', '--oneline', f'mesa-{version}..', '--grep', r'Closes: \(https\|#\).*',
Dylan Baker86079442019-09-25 14:56:21 -0700106 stdout=asyncio.subprocess.PIPE)
107 out, _ = await p.communicate()
108 assert p.returncode == 0, f"git log didn't work: {version}"
109 return out.decode().strip()
110
111
112async def gather_bugs(version: str) -> typing.List[str]:
113 commits = await gather_commits(version)
114
115 issues: typing.List[str] = []
116 for commit in commits.split('\n'):
117 sha, message = commit.split(maxsplit=1)
118 p = await asyncio.create_subprocess_exec(
119 'git', 'log', '--max-count', '1', r'--format=%b', sha,
120 stdout=asyncio.subprocess.PIPE)
121 _out, _ = await p.communicate()
122 out = _out.decode().split('\n')
123 for line in reversed(out):
124 if line.startswith('Closes:'):
125 bug = line.lstrip('Closes:').strip()
126 break
127 else:
128 raise Exception('No closes found?')
129 if bug.startswith('h'):
130 # This means we have a bug in the form "Closes: https://..."
131 issues.append(os.path.basename(urllib.parse.urlparse(bug).path))
132 else:
Dylan Bakerdf3d4ad2019-10-09 10:29:41 -0700133 issues.append(bug.lstrip('#'))
Dylan Baker86079442019-09-25 14:56:21 -0700134
135 loop = asyncio.get_event_loop()
136 async with aiohttp.ClientSession(loop=loop) as session:
137 results = await asyncio.gather(*[get_bug(session, i) for i in issues])
138 typing.cast(typing.Tuple[str, ...], results)
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200139 bugs = list(results)
140 if not bugs:
141 bugs = ['None']
142 return bugs
Dylan Baker86079442019-09-25 14:56:21 -0700143
144
145async def get_bug(session: aiohttp.ClientSession, bug_id: str) -> str:
146 """Query gitlab to get the name of the issue that was closed."""
147 # Mesa's gitlab id is 176,
148 url = 'https://gitlab.freedesktop.org/api/v4/projects/176/issues'
149 params = {'iids[]': bug_id}
150 async with session.get(url, params=params) as response:
151 content = await response.json()
152 return content[0]['title']
153
154
155async def get_shortlog(version: str) -> str:
156 """Call git shortlog."""
157 p = await asyncio.create_subprocess_exec('git', 'shortlog', f'mesa-{version}..',
158 stdout=asyncio.subprocess.PIPE)
159 out, _ = await p.communicate()
160 assert p.returncode == 0, 'error getting shortlog'
161 assert out is not None, 'just for mypy'
162 return out.decode()
163
164
165def walk_shortlog(log: str) -> typing.Generator[typing.Tuple[str, bool], None, None]:
166 for l in log.split('\n'):
167 if l.startswith(' '): # this means we have a patch description
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200168 yield l.lstrip(), False
169 elif l.strip():
Dylan Baker86079442019-09-25 14:56:21 -0700170 yield l, True
171
172
173def calculate_next_version(version: str, is_point: bool) -> str:
174 """Calculate the version about to be released."""
175 if '-' in version:
176 version = version.split('-')[0]
177 if is_point:
178 base = version.split('.')
179 base[2] = str(int(base[2]) + 1)
180 return '.'.join(base)
181 return version
182
183
184def calculate_previous_version(version: str, is_point: bool) -> str:
185 """Calculate the previous version to compare to.
186
187 In the case of -rc to final that verison is the previous .0 release,
188 (19.3.0 in the case of 20.0.0, for example). for point releases that is
189 the last point release. This value will be the same as the input value
190 for a point release, but different for a major release.
191 """
192 if '-' in version:
193 version = version.split('-')[0]
194 if is_point:
195 return version
196 base = version.split('.')
197 if base[1] == '0':
198 base[0] = str(int(base[0]) - 1)
199 base[1] = '3'
200 else:
201 base[1] = str(int(base[1]) - 1)
202 return '.'.join(base)
203
204
Dylan Baker8a4541a2019-10-24 13:11:40 -0700205def get_features(is_point_release: bool) -> typing.Generator[str, None, None]:
Dylan Baker86079442019-09-25 14:56:21 -0700206 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / 'new_features.txt'
207 if p.exists():
Dylan Baker8a4541a2019-10-24 13:11:40 -0700208 if is_point_release:
209 print("WARNING: new features being introduced in a point release", file=sys.stderr)
Dylan Baker86079442019-09-25 14:56:21 -0700210 with p.open('rt') as f:
211 for line in f:
212 yield line
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200213 else:
214 yield "None"
Eric Engestromc905e482020-06-10 19:50:31 +0200215 p.unlink()
Dylan Bakerc6d41e72019-10-09 10:30:17 -0700216 else:
217 yield "None"
Dylan Baker86079442019-09-25 14:56:21 -0700218
219
220async def main() -> None:
221 v = pathlib.Path(__file__).parent.parent / 'VERSION'
222 with v.open('rt') as f:
223 raw_version = f.read().strip()
224 is_point_release = '-rc' not in raw_version
225 assert '-devel' not in raw_version, 'Do not run this script on -devel'
226 version = raw_version.split('-')[0]
227 previous_version = calculate_previous_version(version, is_point_release)
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100228 this_version = calculate_next_version(version, is_point_release)
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200229 today = datetime.date.today()
230 header = f'Mesa {this_version} Release Notes / {today}'
231 header_underline = '=' * len(header)
Dylan Baker86079442019-09-25 14:56:21 -0700232
233 shortlog, bugs = await asyncio.gather(
234 get_shortlog(previous_version),
235 gather_bugs(previous_version),
236 )
237
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200238 final = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / f'{this_version}.rst'
Dylan Baker86079442019-09-25 14:56:21 -0700239 with final.open('wt') as f:
240 try:
241 f.write(TEMPLATE.render(
242 bugfix=is_point_release,
243 bugs=bugs,
244 changes=walk_shortlog(shortlog),
Dylan Baker8a4541a2019-10-24 13:11:40 -0700245 features=get_features(is_point_release),
Dylan Baker86079442019-09-25 14:56:21 -0700246 gl_version=CURRENT_GL_VERSION,
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100247 this_version=this_version,
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200248 header=header,
249 header_underline=header_underline,
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100250 previous_version=previous_version,
Dylan Baker86079442019-09-25 14:56:21 -0700251 vk_version=CURRENT_VK_VERSION,
252 ))
253 except:
254 print(exceptions.text_error_template().render())
255
Eric Engestromae2d0452020-07-09 01:25:39 +0200256 subprocess.run(['git', 'add', final])
257 subprocess.run(['git', 'commit', '-m',
258 f'docs: add release notes for {this_version}'])
259
Dylan Baker86079442019-09-25 14:56:21 -0700260
261if __name__ == "__main__":
262 loop = asyncio.get_event_loop()
263 loop.run_until_complete(main())