Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Dylan Baker | 0123b8f | 2020-03-05 14:04:04 -0800 | [diff] [blame] | 2 | # Copyright © 2019-2020 Intel Corporation |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 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 |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 28 | import re |
Eric Engestrom | ae2d045 | 2020-07-09 01:25:39 +0200 | [diff] [blame] | 29 | import subprocess |
Dylan Baker | 8a4541a | 2019-10-24 13:11:40 -0700 | [diff] [blame] | 30 | import sys |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 31 | import textwrap |
| 32 | import typing |
| 33 | import urllib.parse |
| 34 | |
| 35 | import aiohttp |
| 36 | from mako.template import Template |
| 37 | from mako import exceptions |
| 38 | |
| 39 | |
| 40 | CURRENT_GL_VERSION = '4.6' |
Eric Engestrom | 2557d61 | 2020-03-06 19:12:26 +0100 | [diff] [blame] | 41 | CURRENT_VK_VERSION = '1.2' |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 42 | |
| 43 | TEMPLATE = Template(textwrap.dedent("""\ |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 44 | ${header} |
| 45 | ${header_underline} |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 46 | |
Dylan Baker | 69f540c | 2019-10-09 10:27:13 -0700 | [diff] [blame] | 47 | %if not bugfix: |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 48 | Mesa ${this_version} is a new development release. People who are concerned |
| 49 | with stability and reliability should stick with a previous release or |
| 50 | wait for Mesa ${this_version[:-1]}1. |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 51 | %else: |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 52 | Mesa ${this_version} is a bug fix release which fixes bugs found since the ${previous_version} release. |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 53 | %endif |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 54 | |
Eric Engestrom | 3aa83d8 | 2020-03-09 12:58:05 +0100 | [diff] [blame] | 55 | Mesa ${this_version} implements the OpenGL ${gl_version} API, but the version reported by |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 56 | glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) / |
| 57 | glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver being used. |
| 58 | Some drivers don't support all the features required in OpenGL ${gl_version}. OpenGL |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 59 | ${gl_version} is **only** available if requested at context creation. |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 60 | Compatibility contexts may report a lower version depending on each driver. |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 61 | |
Eric Engestrom | 3aa83d8 | 2020-03-09 12:58:05 +0100 | [diff] [blame] | 62 | Mesa ${this_version} implements the Vulkan ${vk_version} API, but the version reported by |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 63 | the apiVersion property of the VkPhysicalDeviceProperties struct |
| 64 | depends on the particular driver being used. |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 65 | |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 66 | SHA256 checksum |
| 67 | --------------- |
| 68 | |
| 69 | :: |
| 70 | |
| 71 | TBD. |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 72 | |
| 73 | |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 74 | New features |
| 75 | ------------ |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 76 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 77 | %for f in features: |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 78 | - ${rst_escape(f)} |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 79 | %endfor |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 80 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 81 | |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 82 | Bug fixes |
| 83 | --------- |
| 84 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 85 | %for b in bugs: |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 86 | - ${rst_escape(b)} |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 87 | %endfor |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 88 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 89 | |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 90 | Changes |
| 91 | ------- |
| 92 | %for c, author_line in changes: |
| 93 | %if author_line: |
| 94 | |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 95 | ${rst_escape(c)} |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 96 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 97 | %else: |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 98 | - ${rst_escape(c)} |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 99 | %endif |
| 100 | %endfor |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 101 | """)) |
| 102 | |
| 103 | |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 104 | def rst_escape(unsafe_str: str) -> str: |
| 105 | "Escape rST special chars when they follow or preceed a whitespace" |
| 106 | special = re.escape(r'`<>*_#[]|') |
| 107 | unsafe_str = re.sub(r'(^|\s)([' + special + r'])', |
| 108 | r'\1\\\2', |
| 109 | unsafe_str) |
| 110 | unsafe_str = re.sub(r'([' + special + r'])(\s|$)', |
| 111 | r'\\\1\2', |
| 112 | unsafe_str) |
| 113 | return unsafe_str |
| 114 | |
| 115 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 116 | async def gather_commits(version: str) -> str: |
| 117 | p = await asyncio.create_subprocess_exec( |
Eric Engestrom | d7a70fb | 2020-03-05 23:09:45 +0100 | [diff] [blame] | 118 | 'git', 'log', '--oneline', f'mesa-{version}..', '--grep', r'Closes: \(https\|#\).*', |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 119 | stdout=asyncio.subprocess.PIPE) |
| 120 | out, _ = await p.communicate() |
| 121 | assert p.returncode == 0, f"git log didn't work: {version}" |
| 122 | return out.decode().strip() |
| 123 | |
| 124 | |
| 125 | async def gather_bugs(version: str) -> typing.List[str]: |
| 126 | commits = await gather_commits(version) |
| 127 | |
| 128 | issues: typing.List[str] = [] |
| 129 | for commit in commits.split('\n'): |
| 130 | sha, message = commit.split(maxsplit=1) |
| 131 | p = await asyncio.create_subprocess_exec( |
| 132 | 'git', 'log', '--max-count', '1', r'--format=%b', sha, |
| 133 | stdout=asyncio.subprocess.PIPE) |
| 134 | _out, _ = await p.communicate() |
| 135 | out = _out.decode().split('\n') |
| 136 | for line in reversed(out): |
| 137 | if line.startswith('Closes:'): |
| 138 | bug = line.lstrip('Closes:').strip() |
| 139 | break |
| 140 | else: |
| 141 | raise Exception('No closes found?') |
| 142 | if bug.startswith('h'): |
| 143 | # This means we have a bug in the form "Closes: https://..." |
| 144 | issues.append(os.path.basename(urllib.parse.urlparse(bug).path)) |
| 145 | else: |
Dylan Baker | df3d4ad | 2019-10-09 10:29:41 -0700 | [diff] [blame] | 146 | issues.append(bug.lstrip('#')) |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 147 | |
| 148 | loop = asyncio.get_event_loop() |
| 149 | async with aiohttp.ClientSession(loop=loop) as session: |
| 150 | results = await asyncio.gather(*[get_bug(session, i) for i in issues]) |
| 151 | typing.cast(typing.Tuple[str, ...], results) |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 152 | bugs = list(results) |
| 153 | if not bugs: |
| 154 | bugs = ['None'] |
| 155 | return bugs |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 156 | |
| 157 | |
| 158 | async def get_bug(session: aiohttp.ClientSession, bug_id: str) -> str: |
| 159 | """Query gitlab to get the name of the issue that was closed.""" |
| 160 | # Mesa's gitlab id is 176, |
| 161 | url = 'https://gitlab.freedesktop.org/api/v4/projects/176/issues' |
| 162 | params = {'iids[]': bug_id} |
| 163 | async with session.get(url, params=params) as response: |
| 164 | content = await response.json() |
| 165 | return content[0]['title'] |
| 166 | |
| 167 | |
| 168 | async def get_shortlog(version: str) -> str: |
| 169 | """Call git shortlog.""" |
| 170 | p = await asyncio.create_subprocess_exec('git', 'shortlog', f'mesa-{version}..', |
| 171 | stdout=asyncio.subprocess.PIPE) |
| 172 | out, _ = await p.communicate() |
| 173 | assert p.returncode == 0, 'error getting shortlog' |
| 174 | assert out is not None, 'just for mypy' |
| 175 | return out.decode() |
| 176 | |
| 177 | |
| 178 | def walk_shortlog(log: str) -> typing.Generator[typing.Tuple[str, bool], None, None]: |
| 179 | for l in log.split('\n'): |
| 180 | if l.startswith(' '): # this means we have a patch description |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 181 | yield l.lstrip(), False |
| 182 | elif l.strip(): |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 183 | yield l, True |
| 184 | |
| 185 | |
| 186 | def calculate_next_version(version: str, is_point: bool) -> str: |
| 187 | """Calculate the version about to be released.""" |
| 188 | if '-' in version: |
| 189 | version = version.split('-')[0] |
| 190 | if is_point: |
| 191 | base = version.split('.') |
| 192 | base[2] = str(int(base[2]) + 1) |
| 193 | return '.'.join(base) |
| 194 | return version |
| 195 | |
| 196 | |
| 197 | def calculate_previous_version(version: str, is_point: bool) -> str: |
| 198 | """Calculate the previous version to compare to. |
| 199 | |
| 200 | In the case of -rc to final that verison is the previous .0 release, |
| 201 | (19.3.0 in the case of 20.0.0, for example). for point releases that is |
| 202 | the last point release. This value will be the same as the input value |
| 203 | for a point release, but different for a major release. |
| 204 | """ |
| 205 | if '-' in version: |
| 206 | version = version.split('-')[0] |
| 207 | if is_point: |
| 208 | return version |
| 209 | base = version.split('.') |
| 210 | if base[1] == '0': |
| 211 | base[0] = str(int(base[0]) - 1) |
| 212 | base[1] = '3' |
| 213 | else: |
| 214 | base[1] = str(int(base[1]) - 1) |
| 215 | return '.'.join(base) |
| 216 | |
| 217 | |
Dylan Baker | 8a4541a | 2019-10-24 13:11:40 -0700 | [diff] [blame] | 218 | def get_features(is_point_release: bool) -> typing.Generator[str, None, None]: |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 219 | p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / 'new_features.txt' |
| 220 | if p.exists(): |
Dylan Baker | 8a4541a | 2019-10-24 13:11:40 -0700 | [diff] [blame] | 221 | if is_point_release: |
| 222 | print("WARNING: new features being introduced in a point release", file=sys.stderr) |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 223 | with p.open('rt') as f: |
| 224 | for line in f: |
| 225 | yield line |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 226 | else: |
| 227 | yield "None" |
Eric Engestrom | c905e48 | 2020-06-10 19:50:31 +0200 | [diff] [blame] | 228 | p.unlink() |
Dylan Baker | c6d41e7 | 2019-10-09 10:30:17 -0700 | [diff] [blame] | 229 | else: |
| 230 | yield "None" |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 231 | |
| 232 | |
| 233 | async def main() -> None: |
| 234 | v = pathlib.Path(__file__).parent.parent / 'VERSION' |
| 235 | with v.open('rt') as f: |
| 236 | raw_version = f.read().strip() |
| 237 | is_point_release = '-rc' not in raw_version |
| 238 | assert '-devel' not in raw_version, 'Do not run this script on -devel' |
| 239 | version = raw_version.split('-')[0] |
| 240 | previous_version = calculate_previous_version(version, is_point_release) |
Eric Engestrom | 3aa83d8 | 2020-03-09 12:58:05 +0100 | [diff] [blame] | 241 | this_version = calculate_next_version(version, is_point_release) |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 242 | today = datetime.date.today() |
| 243 | header = f'Mesa {this_version} Release Notes / {today}' |
| 244 | header_underline = '=' * len(header) |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 245 | |
| 246 | shortlog, bugs = await asyncio.gather( |
| 247 | get_shortlog(previous_version), |
| 248 | gather_bugs(previous_version), |
| 249 | ) |
| 250 | |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 251 | final = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / f'{this_version}.rst' |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 252 | with final.open('wt') as f: |
| 253 | try: |
| 254 | f.write(TEMPLATE.render( |
| 255 | bugfix=is_point_release, |
| 256 | bugs=bugs, |
| 257 | changes=walk_shortlog(shortlog), |
Dylan Baker | 8a4541a | 2019-10-24 13:11:40 -0700 | [diff] [blame] | 258 | features=get_features(is_point_release), |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 259 | gl_version=CURRENT_GL_VERSION, |
Eric Engestrom | 3aa83d8 | 2020-03-09 12:58:05 +0100 | [diff] [blame] | 260 | this_version=this_version, |
Eric Engestrom | 8bc055f | 2020-04-29 02:02:28 +0200 | [diff] [blame] | 261 | header=header, |
| 262 | header_underline=header_underline, |
Eric Engestrom | 3aa83d8 | 2020-03-09 12:58:05 +0100 | [diff] [blame] | 263 | previous_version=previous_version, |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 264 | vk_version=CURRENT_VK_VERSION, |
Eric Engestrom | 636f770 | 2020-09-25 21:19:10 +0200 | [diff] [blame] | 265 | rst_escape=rst_escape, |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 266 | )) |
| 267 | except: |
| 268 | print(exceptions.text_error_template().render()) |
| 269 | |
Eric Engestrom | ae2d045 | 2020-07-09 01:25:39 +0200 | [diff] [blame] | 270 | subprocess.run(['git', 'add', final]) |
| 271 | subprocess.run(['git', 'commit', '-m', |
| 272 | f'docs: add release notes for {this_version}']) |
| 273 | |
Dylan Baker | 8607944 | 2019-09-25 14:56:21 -0700 | [diff] [blame] | 274 | |
| 275 | if __name__ == "__main__": |
| 276 | loop = asyncio.get_event_loop() |
| 277 | loop.run_until_complete(main()) |