xenocara/lib/mesa/bin/post_version.py

151 lines
4.4 KiB
Python
Raw Normal View History

2020-01-21 19:07:15 -07:00
#!/usr/bin/env python3
2020-08-25 23:26:37 -06:00
# Copyright © 2019-2020 Intel Corporation
2020-01-21 19:07:15 -07:00
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Update the main page, release notes, and calendar."""
import argparse
import calendar
import datetime
import pathlib
2020-08-25 23:26:37 -06:00
import subprocess
2020-01-21 19:07:15 -07:00
from lxml import (
etree,
html,
)
2020-08-25 23:26:37 -06:00
def is_first_release(version: str) -> bool:
return version.endswith('.0')
2020-01-21 19:07:15 -07:00
2020-08-25 23:26:37 -06:00
def is_release_candidate(version: str) -> bool:
return '-rc' in version
2020-01-21 19:07:15 -07:00
2020-08-25 23:26:37 -06:00
def branch_name(version: str) -> str:
if is_release_candidate(version):
version = version.split('-')[0]
(major, minor, _) = version.split('.')
return f'{major}.{minor}'
2020-01-21 19:07:15 -07:00
2020-08-25 23:26:37 -06:00
def update_index(version: str) -> None:
2020-01-21 19:07:15 -07:00
p = pathlib.Path(__file__).parent.parent / 'docs' / 'index.html'
with p.open('rt') as f:
tree = html.parse(f)
news = tree.xpath('.//h1')[0]
date = datetime.date.today()
month = calendar.month_name[date.month]
header = etree.Element('h2')
header.text = f"{month} {date.day}, {date.year}"
body = etree.Element('p')
a = etree.SubElement(
2020-08-25 23:26:37 -06:00
body, 'a', attrib={'href': f'relnotes/{version}.html'})
a.text = f"Mesa {version}"
if is_first_release(version):
2020-01-21 19:07:15 -07:00
a.tail = (" is released. This is a new development release. "
2020-08-25 23:26:37 -06:00
"See the release notes for more information about this release.")
else:
a.tail = " is released. This is a bug fix release."
2020-01-21 19:07:15 -07:00
root = news.getparent()
index = root.index(news) + 1
root.insert(index, body)
root.insert(index, header)
2020-08-25 23:26:37 -06:00
tree.write(p.as_posix(), method='html', pretty_print=True)
subprocess.run(['git', 'add', p])
2020-01-21 19:07:15 -07:00
2020-08-25 23:26:37 -06:00
def update_release_notes(version: str) -> None:
2020-01-21 19:07:15 -07:00
p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html'
with p.open('rt') as f:
tree = html.parse(f)
li = etree.Element('li')
2020-08-25 23:26:37 -06:00
a = etree.SubElement(li, 'a', href=f'relnotes/{version}.html')
a.text = f'{version} release notes'
2020-01-21 19:07:15 -07:00
ul = tree.xpath('.//ul')[0]
ul.insert(0, li)
2020-08-25 23:26:37 -06:00
tree.write(p.as_posix(), method='html', pretty_print=True)
subprocess.run(['git', 'add', p])
def update_calendar(version: str) -> None:
p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.html'
with p.open('rt') as f:
tree = html.parse(f)
branch = branch_name(version)
old = None
new = None
for tr in tree.xpath('.//tr'):
if old is not None:
new = tr
break
for td in tr.xpath('./td'):
if td.text == branch:
old = tr
break
assert old is not None
assert new is not None
old.getparent().remove(old)
# rowspan is 1 based in html, but 0 based in lxml
rowspan = int(td.get("rowspan")) - 1
if rowspan:
td.set("rowspan", str(rowspan))
new.insert(0, td)
tree.write(p.as_posix(), method='html', pretty_print=True)
subprocess.run(['git', 'add', p])
2020-01-21 19:07:15 -07:00
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('version', help="The released version.")
args = parser.parse_args()
2020-08-25 23:26:37 -06:00
update_calendar(args.version)
done = 'update calendar'
if not is_release_candidate(args.version):
update_index(args.version)
update_release_notes(args.version)
done += ', add news item, and link releases notes'
2020-01-21 19:07:15 -07:00
2020-08-25 23:26:37 -06:00
subprocess.run(['git', 'commit', '-m',
f'docs: {done} for {args.version}'])
2020-01-21 19:07:15 -07:00
if __name__ == "__main__":
main()