Files
breeze/scripts/release_notes.py
T
waozi 28788c067a Show Lumi's update notes and Play release notes in the user's language
Lumi announced each update in English whatever the language. Translations
of a release now live in locales/changelog/LANGUAGE.md beside the English
CHANGELOG.md; the build packs them as release-notes-LANGUAGE.json, Lumi
picks the active language's notes for the same release, and
update_version.sh writes each Play listing's notes. A test requires every
language to translate the newest release, and the fonts cover them.

Shorten the 2.1.61 notes.
2026-10-29 12:21:05 -03:00

81 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Package the latest changelog text for Lumi's offline update message.
Translations of each release live in locales/changelog/LANGUAGE.md, written
like CHANGELOG.md. They become release-notes-LANGUAGE.json beside the English
notes, and with --play CODE the Play release notes of their listings.
"""
import argparse
import json
from pathlib import Path
import re
def release_notes(changelog):
heading = re.search(r"^## \[(\d+\.\d+\.\d+)\] - \d{4}-\d{2}-\d{2}\s*$",
changelog, re.M)
if not heading:
raise ValueError("changelog needs a numeric release")
body = changelog[heading.end():].split("\n## [", 1)[0]
notes = []
for line in body.splitlines():
if line.startswith("- "):
notes.append(line[2:].strip())
elif line.startswith(" ") and notes:
notes[-1] += " " + line.strip()
if not notes:
raise ValueError("release needs changelog notes")
return {"version": heading[1], "notes": notes}
# Play listing folder of each translated language.
PLAY_LISTINGS = {"cs": "cs-CZ", "de": "de-DE", "es": "es-ES", "fr": "fr-FR", "id": "id",
"it": "it-IT", "ja": "ja-JP", "ko": "ko-KR", "pt": "pt-BR", "ru": "ru-RU",
"zh": "zh-CN"}
def translations(folder, english):
"""The notes of each language that translates the latest release."""
result = {}
for path in sorted(folder.glob("*.md")):
notes = release_notes(path.read_text(encoding="utf-8"))
if notes["version"] != english["version"]:
continue
if len(notes["notes"]) != len(english["notes"]):
raise ValueError(f"{path.name} translates {len(notes['notes'])} of "
f"{len(english['notes'])} notes for {english['version']}")
result[path.stem] = notes
return result
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("changelog", type=Path)
parser.add_argument("output", type=Path, nargs="?")
parser.add_argument("--play", metavar="CODE", help="write Play notes for this versionCode")
args = parser.parse_args()
result = release_notes(args.changelog.read_text(encoding="utf-8"))
root = args.changelog.resolve().parent
translated = translations(root / "locales/changelog", result)
if args.play:
for language, notes in translated.items():
listing = root / "fastlane/metadata/android" / PLAY_LISTINGS[language] / "changelogs"
listing.mkdir(parents=True, exist_ok=True)
text = "".join(f"- {note}\n" for note in notes["notes"])
(listing / f"{args.play}.txt").write_text(text, encoding="utf-8")
return
if args.output is None:
parser.error("an output file is required without --play")
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n",
encoding="utf-8")
for stale in args.output.parent.glob("release-notes-*.json"):
stale.unlink()
for language, notes in translated.items():
target = args.output.parent / f"release-notes-{language}.json"
target.write_text(json.dumps(notes, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
if __name__ == "__main__":
main()