post_version.py: don't generate relnotes twice
[mesa.git] / bin / post_version.py
1 #!/usr/bin/env python3
2 # Copyright © 2019-2020 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 """Update the main page, release notes, and calendar."""
23
24 import argparse
25 import pathlib
26 import subprocess
27
28
29 def update_homepage(version: str) -> None:
30 p = pathlib.Path(__file__).parent.parent / 'docs' / 'conf.py'
31
32 # Don't post release candidates to the homepage
33 if 'rc' in version:
34 return
35
36 with open(p, 'r') as f:
37 conf = f.readlines()
38
39 new_conf = []
40 for line in conf:
41 if line.startswith("version = '") and line.endswith("'\n"):
42 old_version = line.split("'")[1]
43 # Avoid overwriting 20.1.0 when releasing 20.0.8
44 # TODO: we might need more than that to handle 20.0.10
45 if old_version < version:
46 line = f"version = '{version}'\n"
47 new_conf.append(line)
48
49 with open(p, 'w') as f:
50 for line in new_conf:
51 f.write(line)
52
53 subprocess.run(['git', 'add', p])
54
55
56 def update_release_notes(version: str) -> None:
57 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.rst'
58
59 with open(p, 'r') as f:
60 relnotes = f.readlines()
61
62 new_relnotes = []
63 first_list = True
64 for line in relnotes:
65 if first_list and line.startswith('-'):
66 first_list = False
67 new_relnotes.append(f'- `{version} release notes <relnotes/{version}.rst>`__\n')
68 new_relnotes.append(line)
69
70 with open(p, 'w') as f:
71 for line in new_relnotes:
72 f.write(line)
73
74 subprocess.run(['git', 'add', p])
75
76
77 def update_calendar(version: str) -> None:
78 p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.rst'
79
80 with open(p, 'r') as f:
81 calendar = f.readlines()
82
83 branch = ''
84 skip_line = False
85 new_calendar = []
86 for line in calendar:
87 if version in line:
88 branch = line.split('|')[1].strip()
89 skip_line = True
90 elif skip_line:
91 skip_line = False
92 elif branch:
93 # Put the branch number back on the next line
94 new_calendar.append(line[:2] + branch + line[len(branch) + 2:])
95 branch = ''
96 else:
97 new_calendar.append(line)
98
99 with open(p, 'w') as f:
100 for line in new_calendar:
101 f.write(line)
102
103 subprocess.run(['git', 'add', p])
104
105
106 def main() -> None:
107 parser = argparse.ArgumentParser()
108 parser.add_argument('version', help="The released version.")
109 args = parser.parse_args()
110
111 update_homepage(args.version)
112 update_calendar(args.version)
113 done = 'update calendar'
114
115 if not is_release_candidate(args.version):
116 update_index(args.version)
117 update_release_notes(args.version)
118 done += ', add news item, and link releases notes'
119
120 subprocess.run(['git', 'commit', '-m',
121 f'docs: {done} for {args.version}'])
122
123
124 if __name__ == "__main__":
125 main()