blob: 359cbd9012cc177fb5428eddbac9f4d20abaf01f [file] [log] [blame]
Dylan Baker3226b122019-09-26 14:23:47 -07001#!/usr/bin/env python3
Dylan Baker0123b8f2020-03-05 14:04:04 -08002# Copyright © 2019-2020 Intel Corporation
Dylan Baker3226b122019-09-26 14:23:47 -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"""Update the main page, release notes, and calendar."""
23
Dylan Bakerabf9e7a2019-10-09 10:31:16 -070024import argparse
Dylan Baker3226b122019-09-26 14:23:47 -070025import pathlib
Dylan Baker5cdaa062019-10-28 08:47:14 -070026import subprocess
27
Dylan Baker3226b122019-09-26 14:23:47 -070028
Dylan Baker0123b8f2020-03-05 14:04:04 -080029def update_release_notes(version: str) -> None:
Eric Engestrom6c4ad622020-06-23 02:24:00 +020030 p = pathlib.Path('docs') / 'relnotes.rst'
Dylan Baker3226b122019-09-26 14:23:47 -070031
Eric Engestromebb33b22020-05-03 20:55:55 +020032 with open(p, 'r') as f:
33 relnotes = f.readlines()
Dylan Baker3226b122019-09-26 14:23:47 -070034
Eric Engestromebb33b22020-05-03 20:55:55 +020035 new_relnotes = []
36 first_list = True
Eric Engestrom5f649be2020-07-15 23:53:59 +020037 second_list = True
Eric Engestromebb33b22020-05-03 20:55:55 +020038 for line in relnotes:
39 if first_list and line.startswith('-'):
40 first_list = False
Eric Engestrom5f649be2020-07-15 23:53:59 +020041 new_relnotes.append(f'- :doc:`{version} release notes <relnotes/{version}>`\n')
42 if not first_list and second_list and line.startswith(' relnotes/'):
43 second_list = False
44 new_relnotes.append(f' relnotes/{version}\n')
Eric Engestromebb33b22020-05-03 20:55:55 +020045 new_relnotes.append(line)
Dylan Baker3226b122019-09-26 14:23:47 -070046
Eric Engestromebb33b22020-05-03 20:55:55 +020047 with open(p, 'w') as f:
48 for line in new_relnotes:
49 f.write(line)
50
Dylan Baker5cdaa062019-10-28 08:47:14 -070051 subprocess.run(['git', 'add', p])
Dylan Baker3226b122019-09-26 14:23:47 -070052
53
Dylan Baker0123b8f2020-03-05 14:04:04 -080054def update_calendar(version: str) -> None:
Eric Engestrom6c4ad622020-06-23 02:24:00 +020055 p = pathlib.Path('docs') / 'release-calendar.rst'
Dylan Bakerd7ada7d2019-10-24 15:51:30 -070056
Eric Engestromebb33b22020-05-03 20:55:55 +020057 with open(p, 'r') as f:
58 calendar = f.readlines()
Dylan Bakerd7ada7d2019-10-24 15:51:30 -070059
Eric Engestromebb33b22020-05-03 20:55:55 +020060 branch = ''
61 skip_line = False
62 new_calendar = []
63 for line in calendar:
64 if version in line:
65 branch = line.split('|')[1].strip()
66 skip_line = True
67 elif skip_line:
68 skip_line = False
69 elif branch:
70 # Put the branch number back on the next line
71 new_calendar.append(line[:2] + branch + line[len(branch) + 2:])
72 branch = ''
73 else:
74 new_calendar.append(line)
Dylan Bakerd7ada7d2019-10-24 15:51:30 -070075
Eric Engestromebb33b22020-05-03 20:55:55 +020076 with open(p, 'w') as f:
77 for line in new_calendar:
78 f.write(line)
Dylan Bakerd7ada7d2019-10-24 15:51:30 -070079
Dylan Baker5cdaa062019-10-28 08:47:14 -070080 subprocess.run(['git', 'add', p])
Dylan Bakerd7ada7d2019-10-24 15:51:30 -070081
82
Dylan Baker3226b122019-09-26 14:23:47 -070083def main() -> None:
Dylan Bakerabf9e7a2019-10-09 10:31:16 -070084 parser = argparse.ArgumentParser()
85 parser.add_argument('version', help="The released version.")
86 args = parser.parse_args()
Dylan Baker3226b122019-09-26 14:23:47 -070087
Dylan Baker0123b8f2020-03-05 14:04:04 -080088 update_calendar(args.version)
Eric Engestrom445e5592020-05-07 00:20:46 +020089 done = 'update calendar'
90
Eric Engestroma28a0892020-06-23 02:22:58 +020091 if 'rc' not in args.version:
Eric Engestrom445e5592020-05-07 00:20:46 +020092 update_release_notes(args.version)
Eric Engestroma28a0892020-06-23 02:22:58 +020093 done += ' and link releases notes'
Eric Engestrom445e5592020-05-07 00:20:46 +020094
Dylan Baker5cdaa062019-10-28 08:47:14 -070095 subprocess.run(['git', 'commit', '-m',
Eric Engestrom445e5592020-05-07 00:20:46 +020096 f'docs: {done} for {args.version}'])
Dylan Baker3226b122019-09-26 14:23:47 -070097
98
99if __name__ == "__main__":
100 main()