Skip to content

Commit

Permalink
scripts: Use HTML as source for GitHub release notes
Browse files Browse the repository at this point in the history
Using rendered HTML makes all links to the documentation work.

Issue #9910
  • Loading branch information
nijel committed Sep 11, 2023
1 parent ca9e0e0 commit b12f50c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
9 changes: 7 additions & 2 deletions scripts/create-release
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if [ "$1" = "--tag" ] ; then
shift
fi

# Build the documentation (for release notes)
make -C docs html

# Start with clean build environment
./setup.py clean
find weblate/locale/ docs/locales/ -name '*.mo' -delete
Expand Down Expand Up @@ -82,8 +85,10 @@ if [ "$DO_TAG" -eq 1 ] ; then
git checkout main

# Convert release notes to markdown
./scripts/extract-release-notes "$version" > "dist/Weblate-$version.rst"
pandoc "dist/Weblate-$version.rst" --write=gfm --wrap=none -o "dist/Weblate-$version.md"
sed "s/latest/$namever/" < scripts/release-notes-filter.lua > scripts/release-notes-filter.version.lua
./scripts/extract-release-notes "$version" > "dist/Weblate-$version.html"
pandoc "dist/Weblate-$version.html" --write=gfm --wrap=none --lua-filter=scripts/release-notes-filter.version.lua -o "dist/Weblate-$version.md"
rm scripts/release-notes-filter.version.lua

# Upload to GitHub
sleep 10
Expand Down
23 changes: 10 additions & 13 deletions scripts/extract-release-notes
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import re
import sys

if len(sys.argv) != 2:
raise ValueError("Missing argument")
raise ValueError("Missing version argument")

start = f"Weblate {sys.argv[1]}\n"
display = False
tag = '<section id="weblate-{}">.+?<h1>(.+?)</h1>(.+?)</section>'.format(
sys.argv[1].replace(".", "-")
)

with open("docs/changes.rst") as handle:
for line in handle:
if display:
if line.startswith("Weblate "):
break
elif not line.startswith("--"):
print(line, end="")
elif line == start:
display = True
print(line, end="")
with open("docs/_build/html/changes.html") as handle:
data = handle.read()

for match in re.findall(tag, data, re.MULTILINE | re.DOTALL):
print(match[1])
16 changes: 16 additions & 0 deletions scripts/release-notes-filter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright © Michal Čihař <[email protected]>
--
-- SPDX-License-Identifier: GPL-3.0-or-later

function fix_link (url)
return url:sub(1,4) == "http" and url or "https://docs.weblate.org/en/latest/" .. url
end
function Link (link)
link.target = fix_link(link.target);
return link
end
function Image (img)
img.src = fix_link(img.src);
return src
end
return {{Link = Link, Image = Image}}

0 comments on commit b12f50c

Please sign in to comment.