From 1e1b0c729c8b7abfb09e3e45d541481481a6418c Mon Sep 17 00:00:00 2001 From: professorDeveloper <108933534+professorDeveloper@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:27:51 +0500 Subject: [PATCH] Release: a banner for every version, a full page, and a Telegram post with it - tool/release_banner.py draws docs/images/v/banner.svg from the v3.2.0 artwork: version badge, NEW or PATCH RELEASE with the month, two tagline lines and up to four chips. Wording comes from a comment in the notes, or from the areas merged since the last tag. The version job commits it with the bump; one already there is kept. - The release page gets the banner on top. A version with no notes file now gets a page in the v3.2.0 layout (badges, what's new by area, downloads, community, compare link) instead of the bare table. - Telegram: the banner as a photo with an HTML caption (the notes' Uzbek summary, or the merged changes) and buttons (Android from the CDN, all platforms when the release is public, channel, Discord). The files follow, with install notes under the last one. Falls back to text if the picture or HTML is refused. - v3.2.1 notes: banner wording, and its banner. --- .github/workflows/release.yml | 239 +++++++++++++++-------------- docs/images/v3.2.1/banner.svg | 106 +++++++++++++ docs/releases/v3.2.1.md | 5 + tool/compose_release_notes.py | 235 +++++++++++++++++++++++++++- tool/compose_release_notes_test.py | 133 +++++++++++++++- tool/release_banner.py | 184 ++++++++++++++++++++++ 6 files changed, 782 insertions(+), 120 deletions(-) create mode 100644 docs/images/v3.2.1/banner.svg create mode 100644 tool/release_banner.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7d89946c..b1d132cf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -313,9 +313,21 @@ jobs: PY grep -E '^version:' pubspec.yaml + # The release banner, committed with the bump so the release page can + # show it from this exact commit. One already in the repository (drawn + # by hand, or by an earlier attempt at this version) is kept. + BANNER="docs/images/v${NAME}/banner.svg" + PREV="$(git tag --merged HEAD --sort=-v:refname --list 'v*' | head -1)" + git log ${PREV:+"${PREV}..HEAD"} --first-parent --format=%s > "${RUNNER_TEMP}/changes.txt" + python3 tool/release_banner.py --version "${NAME}" --out "${BANNER}" \ + --log "${RUNNER_TEMP}/changes.txt" --keep \ + || echo "::warning title=No banner::the release page will have none" + git config user.name "${GITHUB_ACTOR}" git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git commit -am "chore: ${NAME}+${BUILD}" + git add pubspec.yaml + [ -f "${BANNER}" ] && git add "${BANNER}" + git commit -m "chore: ${NAME}+${BUILD}" git tag "${TAG}" # Pushed with GITHUB_TOKEN, which deliberately does NOT re-trigger @@ -1122,6 +1134,8 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ needs.version.outputs.sha }} + # Tags and history: the notes list what was merged since the last tag. + fetch-depth: 0 - name: Download all build artifacts uses: actions/download-artifact@v4 @@ -1184,83 +1198,23 @@ jobs: echo; echo "Release payload:"; ls -lh rel + # docs/releases/v.md when somebody wrote it; otherwise a page + # in the same layout (banner, badges, what's new by area, downloads, + # community) built from the titles merged since the previous tag. - name: Compose the release notes env: V: ${{ needs.version.outputs.name }} - BUILD: ${{ needs.version.outputs.build }} NOTES: ${{ inputs.notes }} SHA: ${{ needs.version.outputs.sha }} TAG: ${{ needs.version.outputs.tag }} run: | set -euo pipefail - # Hand-written notes and screenshots, when this version has them. - status=0 + PREV="$(git tag --merged "${SHA}" --sort=-v:refname --list 'v*' | grep -vx "${TAG}" | head -1 || true)" + git log ${PREV:+"${PREV}..${SHA}"} --first-parent --format=%s > changes.txt python3 tool/compose_release_notes.py --version "${V}" --sha "${SHA}" \ --repo "${GITHUB_REPOSITORY}" --tag "${TAG}" --assets rel \ - --out RELEASE_NOTES.md || status=$? - if [ "${status}" -eq 0 ]; then - echo "── notes ──"; cat RELEASE_NOTES.md - exit 0 - elif [ "${status}" -ne 3 ]; then - exit "${status}" - fi - { - if [ -n "${NOTES}" ]; then - printf '%s\n\n' "${NOTES}" - fi - - cat <<'MD' - ## ⬇️ Qaysi faylni yuklab olay? - - | Fayl | Kimga | - |---|---| - | 🟢 **`arm64-v8a.apk`** | Zamonaviy 64-bit Android telefonlar — **ko'pchilikka shu** | - | 🟡 `armeabi-v7a.apk` | Eski 32-bit qurilmalar | - | 🔵 `universal.apk` | Qaysi birini olishni bilmasangiz — hammasida ishlaydi, faqat kattaroq | - | 📺 `tv-arm64-v8a.apk` | Android TV / Google TV / Shield — TV ga sideload qiling | - | 🪟 `Windows-Setup.exe` | Windows o'rnatuvchisi | - | 🪟 `Windows-portable.zip` | O'rnatmasdan ishlatish | - | 🐧 `Linux-x64.tar.gz` | Linux x64 | - | 🍎 `macOS.dmg` | macOS (imzosiz — pastga qarang) | - - `SHA256SUMS.txt` — yuklab olingan faylni tekshirish uchun. - - --- - -
- 🍎 macOS: "damaged / ochilmadi" chiqsa - - DMG Apple sertifikati bilan imzolanmagan. Terminal'da bir marta: - - ``` - xattr -dr com.apple.quarantine /Applications/Sozo.app - ``` - - Yoki Applications'da Sozo.app → o'ng tugma → Open → Open. -
- -
- 📺 Android TV haqida - - TV uchun alohida build yo'q — bu **bir xil APK**. Manifest'da - `LEANBACK_LAUNCHER` e'lon qilingan, shuning uchun bitta binary ham - telefonda, ham televizorda ishlaydi. `tv-` prefiksi shunchaki - televizor oldida turgan odam uchun bitta aniq fayl bo'lsin degani. -
- -
- 🐛 Biror narsa ishlamayaptimi? - - - Manba/provider muammosi → [Manba ishlamayapti](../../issues/new?template=source_not_working.yml) - - Ilova xatosi → [Xato haqida xabar](../../issues/new?template=bug_report.yml) - - Savol → [Telegram](https://telegram.me/sozoapp) · [Discord](https://discord.gg/n22URhYvMR) -
- - MD - - printf '\n---\n\nBuild %s · yuklab olingan faylni `SHA256SUMS.txt` bilan tekshirish mumkin.\n' "${BUILD}" - } > RELEASE_NOTES.md - + --previous "${PREV}" --log changes.txt --intro "${NOTES}" --auto \ + --out RELEASE_NOTES.md echo "── notes ──"; cat RELEASE_NOTES.md - name: Create or update the GitHub Release @@ -1341,6 +1295,11 @@ jobs: if: ${{ always() && !cancelled() && needs.version.result != 'skipped' && inputs.announce != false }} runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.version.outputs.sha }} + fetch-depth: 0 + # Not fatal: when every build failed there is nothing to download, and the # message saying so is exactly what this job now exists to send. - name: Download all build artifacts @@ -1359,6 +1318,38 @@ jobs: echo "Collected:" ls -lh out || true + # The banner as a picture (Telegram cannot show SVG) and the caption. + # Neither is fatal: without them the announcement goes out as text. + - name: Banner and caption for Telegram + if: always() + continue-on-error: true + env: + V: ${{ needs.version.outputs.name }} + SHA: ${{ needs.version.outputs.sha }} + TAG: ${{ needs.version.outputs.tag }} + NOTES: ${{ inputs.notes }} + run: | + set -uo pipefail + PREV="$(git tag --merged "${SHA}" --sort=-v:refname --list 'v*' | grep -vx "${TAG}" | head -1 || true)" + git log ${PREV:+"${PREV}..${SHA}"} --first-parent --format=%s > changes.txt + python3 tool/compose_release_notes.py --version "${V}" --log changes.txt \ + --intro "${NOTES}" --telegram caption.html + python3 tool/release_banner.py --version "${V}" --still --log changes.txt --out banner.svg + # The banner is set in Inter; without it the runner falls back to Liberation Sans. + timeout 120 sudo apt-get install -y -qq fonts-inter >/dev/null 2>&1 || true + CHROME="$(command -v google-chrome || command -v chromium || command -v chromium-browser || true)" + if [ -n "${CHROME}" ]; then + "${CHROME}" --headless=new --no-sandbox --disable-gpu --hide-scrollbars \ + --window-size=1280,640 --force-device-scale-factor=2 \ + --screenshot="${PWD}/banner.png" "file://${PWD}/banner.svg" || true + fi + if [ ! -s banner.png ]; then + timeout 120 sudo apt-get install -y -qq librsvg2-bin >/dev/null 2>&1 \ + && rsvg-convert -w 2560 -h 1280 banner.svg -o banner.png || true + fi + ls -l banner.png caption.html || true + echo "── caption ──"; cat caption.html || true + - name: Send to Telegram if: always() env: @@ -1372,6 +1363,7 @@ jobs: CDN_URL: ${{ needs.admin.outputs.url }} UPDATER: ${{ needs.admin.outputs.updater }} ADMIN_RESULT: ${{ needs.admin.result }} + RELEASE_MODE: ${{ inputs.release || 'publish' }} run: | set -uo pipefail @@ -1402,72 +1394,95 @@ jobs: echo "::warning title=Nothing to deliver::The run produced no artifacts; a failure notice was sent instead." exit 0 fi - # The version job is the single source of this number, so the message - # cannot disagree with what is actually inside the APKs. # The Release page, not the Actions run: a run URL is only visible to - # collaborators, so everybody else in the channel got a 404 where the - # desktop builds were supposed to be. + # collaborators. A draft's page is not public either, so a draft gets + # no release button. REL_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${RELEASE_TAG}" - HEAD="$(printf '🎬 Sozo %s (build %s)\n\n📦 Barcha fayllar (Android / Windows / Linux / macOS):\n%s' \ - "${VERSION_NAME}" "${VERSION_BUILD}" "${REL_URL}")" - - if [ -n "${RELEASE_NOTES}" ]; then - HEAD="$(printf '%s\n\n📝 %s' "${HEAD}" "${RELEASE_NOTES}")" - fi + # 1. The announcement: the banner with the caption under it, and + # buttons. The caption says what changed; the status of the CDN and + # the platform notes go with the files below it. + BUTTONS="$(jq -cn --arg cdn "${CDN_URL}" --arg rel "${REL_URL}" \ + --arg cdnok "${CDN_STATUS}" --arg mode "${RELEASE_MODE}" ' + [ (if $cdnok == "uploaded" and $cdn != "" then [{text: "⬇️ Android (arm64)", url: $cdn}] else empty end), + (if $mode == "publish" then [{text: "📦 Barcha platformalar", url: $rel}] else empty end), + [{text: "📣 Kanal", url: "https://t.me/sozoapp"}, {text: "💬 Discord", url: "https://discord.gg/n22URhYvMR"}] ] + | {inline_keyboard: .}')" + PLAIN="$(printf '🐉 Sozo %s (build %s)' "${VERSION_NAME}" "${VERSION_BUILD}")" + if [ -n "${RELEASE_NOTES}" ]; then PLAIN="$(printf '%s\n\n📝 %s' "${PLAIN}" "${RELEASE_NOTES}")"; fi + + # 2. Under the files: what a person needs to install them. + FOOT="$(printf '🐉 Sozo %s · build %s' "${VERSION_NAME}" "${VERSION_BUILD}")" case "${CDN_STATUS}:${UPDATER}" in - uploaded:published) HEAD="${HEAD}$(printf '\n\n⬇️ CDN (arm64): %s\n🔄 Ilova ichidagi yangilanish va yuklab olish sahifasi yangilandi.' "${CDN_URL}")" ;; - uploaded:*) HEAD="${HEAD}$(printf '\n\n⬇️ CDN (arm64): %s\n⚠️ Ilova ichidagi yangilanish YANGILANMADI.' "${CDN_URL}")" ;; - skipped:*) HEAD="${HEAD}$(printf '\n\n⚠️ CDN/adminka: o'"'"'tkazib yuborildi (SOZO_MOBILE_RELEASE_TOKEN yo'"'"'q).')" ;; - *) [ "${ADMIN_RESULT}" = failure ] && HEAD="${HEAD}$(printf '\n\n❌ CDN/adminka yangilash YIQILDI: %s' "${RUN_URL}")" ;; + uploaded:published) FOOT="${FOOT}$(printf '\n🔄 Ilova ichidagi yangilanish va yuklab olish sahifasi yangilandi.')" ;; + uploaded:*) FOOT="${FOOT}$(printf '\n⚠️ Ilova ichidagi yangilanish YANGILANMADI.')" ;; + skipped:*) FOOT="${FOOT}$(printf '\n⚠️ CDN/adminka: o‘tkazib yuborildi (SOZO_MOBILE_RELEASE_TOKEN yo‘q).')" ;; + *) [ "${ADMIN_RESULT}" = failure ] && FOOT="${FOOT}$(printf '\n❌ CDN/adminka yangilash YIQILDI: %s' "${RUN_URL}")" ;; esac + FOOT="${FOOT}$(printf '\n\n🟢 arm64-v8a: ko‘pchilik telefonlar · 🟡 armeabi-v7a: eski telefonlar\n📺 Android TV: alohida build yo‘q, xuddi shu APK — tv-arm64-v8a (eski boks: tv-armeabi-v7a)\n🍎 macOS “damaged” desa: xattr -dr com.apple.quarantine /Applications/Sozo.app')" - # macOS is ad-hoc signed (no Apple cert), so first open needs one step. - HEAD="${HEAD}$(printf '\n\n🍎 macOS: agar "damaged/ochilmadi" chiqsa, Applications ga qo'"'"'ying va Terminal da: xattr -dr com.apple.quarantine /Applications/Sozo.app (yo'"'"'riqnoma DMG ichida).')" - - # Android TV is the SAME APK (the manifest carries LEANBACK_LAUNCHER), - # so say it in plain terms — otherwise people hunt the run artifacts - # for a separate "TV build" that was never produced. - HEAD="${HEAD}$(printf '\n\n📺 Android TV: alohida build yo'"'"'q — bir xil APK, faqat aniq nom bilan. Release sahifasidan Sozo-v%s-tv-arm64-v8a.apk ni oling (eski/arzon boks bo'"'"'lsa tv-armeabi-v7a).' "${VERSION_NAME}")" - - # Files too big for the bot are only listed (the run artifacts have them). + # Files too big for the bot are only listed (the Release page has them). BIG="" + SMALL=() for f in out/*; do [ -f "${f}" ] || continue sz="$(stat -c%s "${f}")" if [ "${sz}" -gt "${MAX}" ]; then BIG="${BIG}\n• $(basename "${f}") ($((sz/1024/1024)) MB)" + else + SMALL+=("${f}") fi done if [ -n "${BIG}" ]; then - HEAD="${HEAD}$(printf '\n\n⬇️ Telegram limiti (50MB) dan katta, run artifacts dan oling:%b' "${BIG}")" + FOOT="${FOOT}$(printf '\n\n📦 50 MB dan katta, Release sahifasida:%b' "${BIG}")" fi + announce() { + local chat="$1" + if [ -s banner.png ] && [ -s caption.html ]; then + curl -sS --fail-with-body -X POST "${API}/sendPhoto" \ + -F "chat_id=${chat}" -F "photo=@banner.png" -F "caption= +Sozo v3.2.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PATCH RELEASE · NOVEMBER 2026 + Sozo + v3.2.1 + Playback that recovers, + downloads that finish. + Server switchingCorner playerDownloads16 languages + + diff --git a/docs/releases/v3.2.1.md b/docs/releases/v3.2.1.md index 876319b5..c7c7da17 100644 --- a/docs/releases/v3.2.1.md +++ b/docs/releases/v3.2.1.md @@ -1,3 +1,8 @@ +

Sozo v3.2.1 is a patch release that fixes what you reported after v3.2.0.
Videos no longer load forever, dropped connections recover, and more downloads work.
diff --git a/tool/compose_release_notes.py b/tool/compose_release_notes.py index 5cf77203..b1b59eaa 100644 --- a/tool/compose_release_notes.py +++ b/tool/compose_release_notes.py @@ -8,15 +8,27 @@ becomes a table of the files actually attached. -Exit codes: 0 written, 3 no notes file for this version (the workflow then falls -back to its generated notes). +The version's banner (tool/release_banner.py) goes on top when the notes do not +already show one. + +With --auto, a version that has no notes file still gets a full page in the +same layout, built from the titles of what was merged since the last tag. + +--telegram writes the caption of the Telegram announcement (HTML, at most 1024 +characters): the Uzbek summary of the notes when they have one, otherwise the +merged changes. + +Exit codes: 0 written, 3 no notes file for this version and no --auto. """ import argparse +import html import posixpath import re import sys from pathlib import Path +from release_banner import banner_text, kind_of + # Longest suffix first: "tv-arm64-v8a.apk" also ends in "arm64-v8a.apk". PLATFORMS = ( ("tv-arm64-v8a.apk", "📺", "Android TV"), @@ -95,24 +107,233 @@ def downloads_table(assets, repo, tag, version): return "\n".join(lines) +SITE = "https://github.com/professorDeveloper/sozo" +BANNER_BLOCK = re.compile(r"\n*", re.S) + +# Merged-change titles read "Area: what changed (#12)". These areas are about +# the repository, not the app, and stay out of the notes. +INTERNAL = {"release", "ci", "chore", "docs", "doc", "issue forms", "build", "test", + "tests", "deps", "workflow", "readme", "merge"} +AREA_ICONS = {"player": "▶️", "desktop player": "🖥️", "desktop": "🖥️", "sources": "🧩", + "source": "🧩", "downloads": "⬇️", "download": "⬇️", "novels": "📚", + "manga": "📖", "tv": "📺", "ios": "📱", "android": "🤖", "settings": "⚙️", + "search": "🔎", "home": "🏠", "profiles": "👨‍👩‍👧", "subtitles": "💬", + "languages": "🌍", "highlights": "⭐"} +TITLE = re.compile(r"^(?P[^:]{1,30}):\s*(?P.+?)(?:\s*\(#(?P\d+)\))?$") + + +def changes(log_lines): + """[(area, text, pr)] from `git log --format=%s`, oldest first, app-facing only.""" + out = [] + for line in reversed([l.strip() for l in log_lines if l.strip()]): + m = TITLE.match(line) + if m: + area, text, pr = m.group("area").strip(), m.group("text"), m.group("pr") + else: + pr_m = re.search(r"\s*\(#(\d+)\)$", line) + area, text, pr = "", line[:pr_m.start()] if pr_m else line, pr_m and pr_m.group(1) + if area.lower() in INTERNAL or re.match(r"(?i)^(merge|revert|bump)\b", line): + continue + if re.match(r"(?i)^sozo\s+v?\d", area): + area = "Highlights" + text = text[:1].upper() + text[1:] + out.append((area or "Improvements", text, pr)) + return out + + +def ordered(items): + """Grouped by area: Highlights first, then in order of appearance, Improvements last.""" + order = list(dict.fromkeys(a for a, _, _ in items)) + rank = lambda a: 0 if a == "Highlights" else 2 if a == "Improvements" else 1 + order.sort(key=rank) + return [(area, [i for i in items if i[0] == area]) for area in order] + + +def areas(items): + return [a for a, _ in ordered(items) if a not in ("Highlights", "Improvements")] + + +def icon(area): + return AREA_ICONS.get(area.lower(), "✨") + + +def add_banner(text, version, repo, sha, repo_root): + path = f"docs/images/v{version}/banner.svg" + text = BANNER_BLOCK.sub("", text) + if "banner.svg" in text or not (repo_root / path).is_file(): + return text + url = f"https://raw.githubusercontent.com/{repo}/{sha}/{path}" + return (f'

\n Sozo v{version}\n' + f"

\n\n{text}") + + +def notes_path(repo_root, version): + return repo_root / "docs" / "releases" / f"v{version}.md" + + def compose(version, sha, repo, tag, assets, repo_root, warn): - notes = repo_root / "docs" / "releases" / f"v{version}.md" + notes = notes_path(repo_root, version) if not notes.is_file(): return None text = notes.read_text(encoding="utf-8") text = rewrite_images(text, notes, repo_root, repo, sha, warn) + text = add_banner(text, version, repo, sha, repo_root) return text.replace("", downloads_table(assets, repo, tag, version)) +def generate(version, sha, repo, tag, previous, assets, repo_root, log_lines, intro=""): + """A page in the layout of docs/releases/v3.2.0.md, for a version nobody wrote up.""" + items = changes(log_lines) + t = banner_text(version, "", areas(items)) + patch = kind_of(version) == "PATCH RELEASE" + lines = [ + '

', + f" Sozo v{version} is a {'patch' if patch else 'new'} release.
", + f" {html.escape(t['line1'])} {html.escape(t['line2'])}", + "

", + "", + '

', + f' Download', + ' Telegram', + ' Discord', + f' Star Sozo', + "

", + "", + ] + if intro.strip(): + lines += [intro.strip(), ""] + lines += ["---", "", "## ✨ What's new", ""] + if items: + for area, group in ordered(items): + lines += [f"### {icon(area)} {area}", ""] + for _, text, pr in group: + link = f" ([#{pr}](https://github.com/{repo}/pull/{pr}))" if pr else "" + lines.append(f"- {text}{link}") + lines.append("") + else: + lines += ["Fixes and smaller improvements.", ""] + lines += [ + "---", "", "## ⬇ Download", "", + downloads_table(assets, repo, tag, version), "", + "
", + '🍎 macOS says the app is "damaged" or won\'t open', + "", + "The DMG isn't signed with an Apple certificate. Run this once in Terminal:", + "", + "```", "xattr -dr com.apple.quarantine /Applications/Sozo.app", "```", + "", + "Or in Applications, right-click Sozo.app → **Open** → **Open**.", + "
", + "", + "
", + "📺 Android TV", + "", + "There is no separate TV build: the same APK runs on phones and TVs. The `tv-` files are", + "named for the television so there is one obvious file to sideload. Older or cheaper boxes", + "need `tv-armeabi-v7a`.", + "
", + "", + "---", "", "## 💬 Join the community", "", + f"- 📣 **Telegram**: [@sozoapp](https://telegram.me/sozoapp) for new versions and announcements first.", + "- 🎧 **Discord**: [discord.gg/n22URhYvMR](https://discord.gg/n22URhYvMR) to suggest ideas and report bugs.", + "- 🛟 **In the app**: Profile → **Help & Support**.", + f"- 🐛 **On GitHub**: [a source isn't working]({SITE}/issues/new?template=source_not_working.yml) · [bug report]({SITE}/issues/new?template=bug_report.yml) · [feature request]({SITE}/issues/new?template=feature_request.yml)", + f"- ⭐ **If Sozo is useful to you, [star the repo]({SITE})**.", + "", + ] + if previous: + lines.append(f'Full list of changes: ' + f"{previous}...{tag}") + body = "\n".join(lines) + "\n" + return add_banner(body, version, repo, sha, repo_root) + + +# ---------------------------------------------------------------- Telegram ---- + +CAPTION_LIMIT = 1024 +UZ_SUMMARY = re.compile(r"[^<]*🇺🇿.*?(.*?)", re.S) + + +def md_to_tg(text): + text = html.escape(text, quote=False) + text = re.sub(r"\[([^\]]+)\]\((https?://[^)\s]+)\)", r'\1', text) + text = re.sub(r"\*\*(.+?)\*\*", r"\1", text) + text = re.sub(r"(?\1", text) + return re.sub(r"`([^`]+)`", r"\1", text) + + +def shorten(md, limit=230): + """Cuts a markdown bullet at a sentence end, never inside **bold**.""" + if len(md) <= limit: + return md + for m in reversed(list(re.finditer(r"[.!?](?=\s)", md[:limit]))): + head = md[:m.end()] + if head.count("**") % 2 == 0 and head.count("[") == head.count("]"): + return head + return md + + +def telegram_caption(version, notes_text, log_lines, intro=""): + t = banner_text(version, notes_text, areas(changes(log_lines))) + kind = "yamoq (patch)" if kind_of(version) == "PATCH RELEASE" else "yangi versiya" + head = [f"🐉 Sozo v{html.escape(version)} · {kind}", + f"{html.escape(t['line1'])} {html.escape(t['line2'])}"] + if intro.strip(): + head += ["", f"📝 {html.escape(intro.strip())}"] + head += ["", "✨ Nima yangi"] + tail = ["", "⬇️ Fayllar shu xabar ostida · 📣 @sozoapp"] + + bullets = [] + uz = UZ_SUMMARY.search(notes_text or "") + if uz: + bullets = [shorten(l.strip()[2:]) for l in uz.group(1).splitlines() + if l.strip().startswith("- ")] + if not bullets: + bullets = [f"{icon(a)} **{a}**: {txt}" for a, group in ordered(changes(log_lines)) + for _, txt, _ in group] + if not bullets: + bullets = ["Tuzatishlar va kichik yaxshilanishlar."] + + out = list(head) + for b in bullets: + line = "• " + md_to_tg(b) if not re.match(r"^\W", b) else md_to_tg(b) + if len("\n".join(out + [line] + tail)) > CAPTION_LIMIT: + break + out.append(line) + if len(out) == len(head): + out.append(md_to_tg(bullets[0])[:CAPTION_LIMIT - len("\n".join(head + tail)) - 2] + "…") + return "\n".join(out + tail) + + +def read_log(path): + return Path(path).read_text(encoding="utf-8").splitlines() if path else [] + + def main(): parser = argparse.ArgumentParser() - for name in ("version", "sha", "repo", "tag", "assets", "out"): - parser.add_argument(f"--{name}", required=True) + parser.add_argument("--version", required=True) + for name in ("sha", "repo", "tag", "assets", "out", "telegram", "previous", "log"): + parser.add_argument(f"--{name}", default="") + parser.add_argument("--intro", default="", help="text from the release form, put on top") + parser.add_argument("--auto", action="store_true", help="generate a page when there are no notes") parser.add_argument("--root", default=".") args = parser.parse_args() + root = Path(args.root).resolve() + log_lines = read_log(args.log) + + if args.telegram: + notes = notes_path(root, args.version) + text = notes.read_text(encoding="utf-8") if notes.is_file() else "" + Path(args.telegram).write_text( + telegram_caption(args.version, text, log_lines, args.intro), encoding="utf-8") + if not args.out: + return 0 + warn = lambda message: print(f"::warning::{message}") - body = compose(args.version, args.sha, args.repo, args.tag, Path(args.assets), - Path(args.root).resolve(), warn) + body = compose(args.version, args.sha, args.repo, args.tag, Path(args.assets), root, warn) + if body is None and args.auto: + body = generate(args.version, args.sha, args.repo, args.tag, args.previous, + Path(args.assets), root, log_lines, args.intro) if body is None: print(f"No docs/releases/v{args.version}.md") return 3 diff --git a/tool/compose_release_notes_test.py b/tool/compose_release_notes_test.py index beb8d362..6a1bde83 100644 --- a/tool/compose_release_notes_test.py +++ b/tool/compose_release_notes_test.py @@ -4,7 +4,11 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) -from compose_release_notes import compose +import datetime as dt +import re + +from compose_release_notes import changes, compose, generate, telegram_caption +from release_banner import banner_text, render, still SHA = "abc123" REPO = "o/r" @@ -66,6 +70,133 @@ def test_downloads_list_only_attached_files(self): def test_downloads_without_files(self): self.assertIn("attached", self.run_it("")) + def test_banner_goes_on_top_when_the_notes_have_none(self): + (self.root / "docs/images/v1/banner.svg").write_text("") + out = self.run_it("\n

Body

\n") + self.assertTrue(out.startswith('

\n ") + out = self.run_it('\n') + self.assertEqual(out.count("banner.svg"), 1) + + +LOG = [ + "Sources: show a renamed source under its current name (#76)", + "chore: 3.2.1+9", + "Release: put the APKs on the CDN (#74)", + "Player: skip Matroska on iPhone (#75)", + "Sozo 3.2.1: corner player and reconnect fixes (#46)", + "Issue forms: English first (#51)", + "fix a typo in the reader", +] + + +class GeneratedTest(unittest.TestCase): + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.root = Path(tmp.name) + self.assets = self.root / "rel" + self.assets.mkdir() + (self.assets / "Sozo-v3.2.2-arm64-v8a.apk").write_bytes(b"x") + + def test_changes_keep_what_users_see(self): + got = changes(LOG) + self.assertEqual([a for a, _, _ in got], ["Improvements", "Highlights", "Player", "Sources"]) + self.assertIn(("Player", "Skip Matroska on iPhone", "75"), got) + self.assertIn(("Improvements", "Fix a typo in the reader", None), got) + + def test_generated_page_has_the_v320_layout(self): + out = generate("3.2.2", "s", "o/r", "v3.2.2", "v3.2.1", self.assets, self.root, LOG, "Hotfix.") + for part in ("is a patch release", "Download_v3.2.2", "Hotfix.", "## ✨ What's new", + "### ▶️ Player", "[#75](https://github.com/o/r/pull/75)", "## ⬇ Download", + "Sozo-v3.2.2-arm64-v8a.apk", "## 💬 Join the community", + "compare/v3.2.1...v3.2.2"): + self.assertIn(part, out) + self.assertNotIn("CDN", out) + self.assertLess(out.index("Highlights"), out.index("Player")) + self.assertLess(out.index("Sources"), out.index("Improvements")) + + def test_generated_page_shows_the_committed_banner(self): + (self.root / "docs/images/v3.2.2").mkdir(parents=True) + (self.root / "docs/images/v3.2.2/banner.svg").write_text("") + out = generate("3.2.2", "s", "o/r", "v3.2.2", "", self.assets, self.root, LOG) + self.assertTrue(out.startswith('

\n +

+🇺🇿 O'zbekcha qisqacha + +**Sozo v3.2.1: tuzatishlar.** + +- ▶️ **Pleer.** Endi
+""" + + +class TelegramTest(unittest.TestCase): + def test_uses_the_uzbek_summary(self): + out = telegram_caption("3.2.1", UZ_NOTES, LOG) + self.assertIn("🐉 Sozo v3.2.1 · yamoq (patch)", out) + self.assertIn("Playback that recovers, downloads that finish.", out) + self.assertIn("▶️ Pleer. Endi <video> cheksiz turmaydi. Save to Downloads ishlaydi.", out) + self.assertIn('kanal', out) + self.assertNotIn("Matroska", out) + + def test_falls_back_to_the_merged_changes(self): + out = telegram_caption("3.3.0", "", LOG, "Bugun chiqdi") + self.assertIn("yangi versiya", out) + self.assertIn("📝 Bugun chiqdi", out) + self.assertIn("▶️ Player: Skip Matroska on iPhone", out) + self.assertNotIn("CDN", out) + + def test_never_longer_than_a_caption(self): + notes = UZ_NOTES.replace("", "\n".join(f"- **N{i}.** " + "so'z " * 40 for i in range(40)) + "\n") + out = telegram_caption("3.2.1", notes, LOG) + self.assertLessEqual(len(out), 1024) + self.assertEqual(out.count(""), out.count("")) + self.assertTrue(out.endswith("@sozoapp")) + + +TEMPLATE = Path(__file__).resolve().parent.parent / "docs/images/v3.2.0/banner.svg" + + +class BannerTest(unittest.TestCase): + def test_text_follows_the_version(self): + t = banner_text("3.2.4", "", ["Player"], dt.date(2026, 11, 14)) + self.assertEqual(t["eyebrow"], "PATCH RELEASE · NOVEMBER 2026") + self.assertEqual(t["chips"], ["Player"]) + self.assertEqual(banner_text("4.0.0", "", [], dt.date(2026, 1, 1))["eyebrow"], "NEW RELEASE · JANUARY 2026") + + def test_notes_override_every_line(self): + t = banner_text("3.2.1", "", ["Player"], + dt.date(2026, 11, 14)) + self.assertEqual((t["eyebrow"], t["line1"], t["line2"], t["chips"]), + ("HOTFIX · NOVEMBER 2026", "A", "B", ["x", "y"])) + + @unittest.skipUnless(TEMPLATE.is_file(), "template not checked out") + def test_render_keeps_the_art_and_swaps_the_words(self): + template = TEMPLATE.read_text(encoding="utf-8") + t = banner_text("3.2.10", "", ["Player & "] + ["Very long chip name " * 3] * 5) + svg = render(template, t) + self.assertEqual(svg[:svg.index('')], + re.sub(r".*?", "Sozo v3.2.10", + template[:template.index('')])) + self.assertIn(">v3.2.10", svg) + self.assertIn("Player & <Sources>", svg) + self.assertNotIn("Light novels", svg) + self.assertTrue(svg.rstrip().endswith("")) + self.assertIn("@media all{", still(svg)) + if __name__ == "__main__": unittest.main() diff --git a/tool/release_banner.py b/tool/release_banner.py new file mode 100644 index 00000000..00279c22 --- /dev/null +++ b/tool/release_banner.py @@ -0,0 +1,184 @@ +#!/usr/bin/env python3 +"""Draws the release banner for one version. + +The dragon artwork and its animation come from the v3.2.0 banner. Only the +right-hand column changes: the eyebrow, the version badge, two tagline lines +and up to four chips. + +The words come from a comment in docs/releases/v.md: + + + +Every key is optional. Without the comment, the eyebrow says NEW or PATCH +RELEASE and the month, the tagline is a generic one, and the chips name the +areas of the merged changes (see banner_text). + +--still writes a copy without animation, the frame a viewer with reduced motion +sees. It is the one rendered to PNG for Telegram, which cannot show SVG. +""" +import argparse +import datetime as dt +import html +import re +import sys +from pathlib import Path + +TEMPLATE = Path("docs/images/v3.2.0/banner.svg") +RIGHT = '' +COLUMN = 600 # room to the right of x=640 before the 40px margin +MAX_CHIPS = 4 + +# Advance widths of Inter, in em. Close enough to size pills and badges; text +# that might still overflow is squeezed with textLength. +WIDE = {"m": .87, "w": .79, "M": .85, "W": .95, "@": .95, "%": .8, "&": .66} +NARROW = {c: .26 for c in "ijlI.,:;'|!·()[] "} +NARROW.update({"f": .36, "t": .36, "r": .37, "-": .4, "/": .4}) + + +def text_width(text, size, spacing=0.0): + em = 0.0 + for ch in text: + if ch in WIDE: + em += WIDE[ch] + elif ch in NARROW: + em += NARROW[ch] + elif ch.isdigit(): + em += .62 + elif ch.isupper(): + em += .68 + else: + em += .56 + return em * size + spacing * len(text) + + +def parse_block(notes_text): + """The `` comment as a dict; empty when there is none.""" + match = re.search(r"", notes_text or "", re.S) + if not match: + return {} + out = {} + for line in match.group(1).splitlines(): + key, sep, value = line.partition(":") + if sep and key.strip(): + out[key.strip().lower()] = value.strip() + return out + + +def kind_of(version): + parts = (version.split(".") + ["0", "0"])[:3] + return "PATCH RELEASE" if parts[2] not in ("", "0") else "NEW RELEASE" + + +def banner_text(version, notes_text="", areas=(), today=None): + today = today or dt.date.today() + block = parse_block(notes_text) + patch = kind_of(version) == "PATCH RELEASE" + eyebrow = block.get("eyebrow") or kind_of(version) + if "·" not in eyebrow: + eyebrow = f"{eyebrow} · {today.strftime('%B %Y')}" + line1 = block.get("line1") or ("Fixes for what you reported," if patch + else f"Everything new in Sozo {version},") + line2 = block.get("line2") or "on every screen you watch on." + if block.get("chips"): + chips = [c.strip() for c in block["chips"].split("|") if c.strip()] + else: + chips = list(dict.fromkeys(a for a in areas if a)) + if not chips: + chips = ["Android · iOS", "Windows · macOS · Linux"] + return {"eyebrow": eyebrow.upper(), "version": f"v{version}", "line1": line1, + "line2": line2, "chips": chips[:MAX_CHIPS]} + + +def fitted(x, y, cls, text, size, extra=""): + attrs = f'x="{x}" y="{y}" class="{cls}"{extra}' + if text_width(text, size) > COLUMN: + attrs += f' textLength="{COLUMN}" lengthAdjust="spacingAndGlyphs"' + return f"{html.escape(text)}" + + +def right_column(t): + badge_w = max(150, round(text_width(t["version"], 30) + 62)) + chips, x = [], 0 + for chip in t["chips"]: + w = max(64, round(text_width(chip, 14.5) + 30)) + if x + w > COLUMN: + break + chips.append( + f'' + f'' + f"{html.escape(chip)}") + x += w + 10 + eyebrow = html.escape(t["eyebrow"]) + return "\n".join([ + RIGHT, + f' {eyebrow}', + ' Sozo', + f' ' + f'' + f'' + f'{html.escape(t["version"])}', + f' {fitted(0, 378, "tag", t["line1"], 25)}', + f' {fitted(0, 412, "tag2", t["line2"], 25)}', + f' {"".join(chips)}', + "", + "", + "", + ]) + + +def render(template_svg, t, still_frame=False): + cut = template_svg.find(RIGHT) + if cut < 0: + raise ValueError(f"the template has no {RIGHT}") + svg = template_svg[:cut] + right_column(t) + svg = re.sub(r".*?", f"Sozo {html.escape(t['version'])}", svg, count=1) + return still(svg) if still_frame else svg + + +def still(svg): + """The template's reduced-motion rule, applied to everyone: no pen strokes + or ring, the painted mark and every line of text in place.""" + return svg.replace("@media (prefers-reduced-motion: reduce){", "@media all{", 1) + + +def main(): + p = argparse.ArgumentParser() + p.add_argument("--version", required=True) + p.add_argument("--out", required=True) + p.add_argument("--still", action="store_true") + p.add_argument("--root", default=".") + p.add_argument("--log", default="", help="`git log --format=%%s` since the last tag; its areas are the chips when the notes name none") + p.add_argument("--keep", action="store_true", help="leave an existing banner alone") + a = p.parse_args() + root = Path(a.root) + out = Path(a.out) + if a.keep and out.is_file(): + print(f"{out} already exists; left as it is") + return 0 + notes = root / "docs" / "releases" / f"v{a.version}.md" + notes_text = notes.read_text(encoding="utf-8") if notes.is_file() else "" + committed = root / "docs" / "images" / f"v{a.version}" / "banner.svg" + if a.still and committed.is_file(): + # A banner already in the repository, drawn or hand-edited, is the one + # people saw on the release page; the PNG shows the same. + svg = still(committed.read_text(encoding="utf-8")) + t = {"from": str(committed)} + else: + from compose_release_notes import areas, changes + log = Path(a.log).read_text(encoding="utf-8").splitlines() if a.log else [] + t = banner_text(a.version, notes_text, areas(changes(log))) + svg = render((root / TEMPLATE).read_text(encoding="utf-8"), t, a.still) + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(svg, encoding="utf-8") + print(f"{out}: {t}") + return 0 + + +if __name__ == "__main__": + sys.exit(main())