post_version.py: update script to the new rST way of things

Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4630>
This commit is contained in:
Eric Engestrom
2020-05-03 20:55:55 +02:00
committed by Marge Bot
parent 8bc055fc52
commit ebb33b2c0a

View File

@@ -22,110 +22,84 @@
"""Update the main page, release notes, and calendar.""" """Update the main page, release notes, and calendar."""
import argparse import argparse
import calendar
import datetime
import pathlib import pathlib
import subprocess import subprocess
from lxml import (
etree,
html,
)
def update_homepage(version: str) -> None:
p = pathlib.Path(__file__).parent.parent / 'docs' / 'conf.py'
def is_first_release(version: str) -> bool: # Don't post release candidates to the homepage
return version.endswith('.0') if 'rc' in version:
return
with open(p, 'r') as f:
conf = f.readlines()
def is_release_candidate(version: str) -> bool: new_conf = []
return '-rc' in version for line in conf:
if line.startswith("version = '") and line.endswith("'\n"):
old_version = line.split("'")[1]
# Avoid overwriting 20.1.0 when releasing 20.0.8
# TODO: we might need more than that to handle 20.0.10
if old_version < version:
line = f"version = '{version}'\n"
new_conf.append(line)
with open(p, 'w') as f:
for line in new_conf:
f.write(line)
def branch_name(version: str) -> str:
if is_release_candidate(version):
version = version.split('-')[0]
(major, minor, _) = version.split('.')
return f'{major}.{minor}'
def update_index(version: str) -> None:
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(
body, 'a', attrib={'href': f'relnotes/{version}.html'})
a.text = f"Mesa {version}"
if is_first_release(version):
a.tail = (" is released. This is a new development release. "
"See the release notes for more information about this release.")
else:
a.tail = " is released. This is a bug fix release."
root = news.getparent()
index = root.index(news) + 1
root.insert(index, body)
root.insert(index, header)
tree.write(p.as_posix(), method='html', pretty_print=True)
subprocess.run(['git', 'add', p]) subprocess.run(['git', 'add', p])
def update_release_notes(version: str) -> None: def update_release_notes(version: str) -> None:
p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.html' p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes.rst'
with p.open('rt') as f:
tree = html.parse(f)
li = etree.Element('li') with open(p, 'r') as f:
a = etree.SubElement(li, 'a', href=f'relnotes/{version}.html') relnotes = f.readlines()
a.text = f'{version} release notes'
ul = tree.xpath('.//ul')[0] new_relnotes = []
ul.insert(0, li) first_list = True
for line in relnotes:
if first_list and line.startswith('-'):
first_list = False
new_relnotes.append(f'- `{version} release notes <relnotes/{version}.rst>`__\n')
new_relnotes.append(line)
with open(p, 'w') as f:
for line in new_relnotes:
f.write(line)
tree.write(p.as_posix(), method='html', pretty_print=True)
subprocess.run(['git', 'add', p]) subprocess.run(['git', 'add', p])
def update_calendar(version: str) -> None: def update_calendar(version: str) -> None:
p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.html' p = pathlib.Path(__file__).parent.parent / 'docs' / 'release-calendar.rst'
with p.open('rt') as f:
tree = html.parse(f)
branch = branch_name(version) with open(p, 'r') as f:
calendar = f.readlines()
old = None branch = ''
new = None skip_line = False
new_calendar = []
for line in calendar:
if version in line:
branch = line.split('|')[1].strip()
skip_line = True
elif skip_line:
skip_line = False
elif branch:
# Put the branch number back on the next line
new_calendar.append(line[:2] + branch + line[len(branch) + 2:])
branch = ''
else:
new_calendar.append(line)
for tr in tree.xpath('.//tr'): with open(p, 'w') as f:
if old is not None: for line in new_calendar:
new = tr f.write(line)
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]) subprocess.run(['git', 'add', p])
@@ -134,6 +108,8 @@ def main() -> None:
parser.add_argument('version', help="The released version.") parser.add_argument('version', help="The released version.")
args = parser.parse_args() args = parser.parse_args()
update_homepage(args.version)
update_release_notes(args.version)
update_calendar(args.version) update_calendar(args.version)
done = 'update calendar' done = 'update calendar'