2 # Copyright © 2019 Intel Corporation
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:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
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
22 """Update the main page, release notes, and calendar."""
36 def calculate_previous_version(version
: str, is_point
: bool) -> str:
37 """Calculate the previous version to compare to.
39 In the case of -rc to final that verison is the previous .0 release,
40 (19.3.0 in the case of 20.0.0, for example). for point releases that is
41 the last point release. This value will be the same as the input value
42 for a poiont release, but different for a major release.
45 version
= version
.split('-')[0]
48 base
= version
.split('.')
50 base
[0] = str(int(base
[0]) - 1)
53 base
[1] = str(int(base
[1]) - 1)
57 def is_point_release(version
: str) -> bool:
58 return not version
.endswith('.0')
61 def update_index(is_point
: bool, version
: str, previous_version
: str) -> None:
62 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'index.html'
63 with p
.open('rt') as f
:
66 news
= tree
.xpath('.//h1')[0]
68 date
= datetime
.date
.today()
69 month
= calendar
.month_name
[date
.month
]
70 header
= etree
.Element('h2')
71 header
.text
= f
"{month} {date.day}, {date.year}"
73 body
= etree
.Element('p')
75 body
, 'a', attrib
={'href': f
'relnotes/{previous_version}.html'})
76 a
.text
= f
"Mesa {previous_version}"
78 a
.tail
= " is released. This is a bug fix release."
80 a
.tail
= (" is released. This is a new development release. "
81 "See the release notes for mor information about this release.")
83 root
= news
.getparent()
84 index
= root
.index(news
) + 1
85 root
.insert(index
, body
)
86 root
.insert(index
, header
)
88 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
89 subprocess
.run(['git', 'add', p
])
92 def update_release_notes(previous_version
: str) -> None:
93 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'relnotes.html'
94 with p
.open('rt') as f
:
97 li
= etree
.Element('li')
98 a
= etree
.SubElement(li
, 'a', href
=f
'relnotes/{previous_version}.html')
99 a
.text
= f
'{previous_version} release notes'
101 ul
= tree
.xpath('.//ul')[0]
104 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
105 subprocess
.run(['git', 'add', p
])
108 def update_calendar(previous_version
: str) -> None:
109 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'release-calendar.html'
110 with p
.open('rt') as f
:
113 base_version
= previous_version
[:-2]
118 for tr
in tree
.xpath('.//tr'):
123 for td
in tr
.xpath('./td'):
124 if td
.text
== base_version
:
128 assert old
is not None
129 assert new
is not None
130 old
.getparent().remove(old
)
132 # rowspan is 1 based in html, but 0 based in lxml
133 rowspan
= int(td
.get("rowspan")) - 1
135 td
.set("rowspan", str(rowspan
))
138 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
139 subprocess
.run(['git', 'add', p
])
143 parser
= argparse
.ArgumentParser()
144 parser
.add_argument('version', help="The released version.")
145 args
= parser
.parse_args()
147 is_point
= is_point_release(args
.version
)
148 previous_version
= calculate_previous_version(args
.version
, is_point
)
150 update_index(is_point
, args
.version
, previous_version
)
151 update_release_notes(previous_version
)
152 update_calendar(previous_version
)
153 subprocess
.run(['git', 'commit', '-m',
154 'docs: update calendar, add news item, and link releases '
155 f
'notes for {previous_version}'])
158 if __name__
== "__main__":