2 # Copyright © 2019-2020 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 is_first_release(version
: str) -> bool:
37 return version
.endswith('.0')
40 def is_release_candidate(version
: str) -> bool:
41 return '-rc' in version
44 def branch_name(version
: str) -> str:
45 if is_release_candidate(version
):
46 version
= version
.split('-')[0]
47 (major
, minor
, _
) = version
.split('.')
48 return f
'{major}.{minor}'
51 def update_index(version
: str) -> None:
52 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'index.html'
53 with p
.open('rt') as f
:
56 news
= tree
.xpath('.//h1')[0]
58 date
= datetime
.date
.today()
59 month
= calendar
.month_name
[date
.month
]
60 header
= etree
.Element('h2')
61 header
.text
= f
"{month} {date.day}, {date.year}"
63 body
= etree
.Element('p')
65 body
, 'a', attrib
={'href': f
'relnotes/{version}.html'})
66 a
.text
= f
"Mesa {version}"
67 if is_first_release(version
):
68 a
.tail
= (" is released. This is a new development release. "
69 "See the release notes for more information about this release.")
71 a
.tail
= " is released. This is a bug fix release."
73 root
= news
.getparent()
74 index
= root
.index(news
) + 1
75 root
.insert(index
, body
)
76 root
.insert(index
, header
)
78 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
79 subprocess
.run(['git', 'add', p
])
82 def update_release_notes(version
: str) -> None:
83 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'relnotes.html'
84 with p
.open('rt') as f
:
87 li
= etree
.Element('li')
88 a
= etree
.SubElement(li
, 'a', href
=f
'relnotes/{version}.html')
89 a
.text
= f
'{version} release notes'
91 ul
= tree
.xpath('.//ul')[0]
94 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
95 subprocess
.run(['git', 'add', p
])
98 def update_calendar(version
: str) -> None:
99 p
= pathlib
.Path(__file__
).parent
.parent
/ 'docs' / 'release-calendar.html'
100 with p
.open('rt') as f
:
103 branch
= branch_name(version
)
108 for tr
in tree
.xpath('.//tr'):
113 for td
in tr
.xpath('./td'):
114 if td
.text
== branch
:
118 assert old
is not None
119 assert new
is not None
120 old
.getparent().remove(old
)
122 # rowspan is 1 based in html, but 0 based in lxml
123 rowspan
= int(td
.get("rowspan")) - 1
125 td
.set("rowspan", str(rowspan
))
128 tree
.write(p
.as_posix(), method
='html', pretty_print
=True)
129 subprocess
.run(['git', 'add', p
])
133 parser
= argparse
.ArgumentParser()
134 parser
.add_argument('version', help="The released version.")
135 args
= parser
.parse_args()
137 update_calendar(args
.version
)
138 done
= 'update calendar'
140 if not is_release_candidate(args
.version
):
141 update_index(args
.version
)
142 update_release_notes(args
.version
)
143 done
+= ', add news item, and link releases notes'
145 subprocess
.run(['git', 'commit', '-m',
146 f
'docs: {done} for {args.version}'])
149 if __name__
== "__main__":