diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff4e2765..ab1fae64 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1385,12 +1385,19 @@ jobs: SHA: ${{ needs.version.outputs.sha }} TAG: ${{ needs.version.outputs.tag }} NOTES: ${{ inputs.notes }} + MODE: ${{ inputs.release || 'publish' }} + TV_REPO: ${{ vars.TV_REPO || 'professorDeveloper/sozo-tv' }} + GH_TOKEN: ${{ github.token }} 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 + # A draft's page is not public yet, so only a published release links to it. + REL="" + if [ "${MODE}" = publish ]; then REL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${TAG}"; fi + TV="$(gh api "repos/${TV_REPO}/releases/latest" --jq .html_url 2>/dev/null || true)" python3 tool/compose_release_notes.py --version "${V}" --log changes.txt \ - --intro "${NOTES}" --telegram caption.html + --intro "${NOTES}" --telegram caption.html --release-url "${REL}" --tv-url "${TV}" 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 @@ -1544,3 +1551,34 @@ jobs: send_files "${chat}" || { echo "::error::files ${chat}: $(cat /tmp/tg_doc.json)"; fail=1; } done exit "${fail}" + + # The public post: the banner with the caption, nothing else. Only for a + # release that was published, since the post links to its page. + - name: Announce on the channel + if: ${{ always() && (inputs.release || 'publish') == 'publish' && needs.publish.result == 'success' }} + continue-on-error: true + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_CHANNEL_BOT_TOKEN || secrets.TELEGRAM_BOT_TOKEN }} + CHANNEL: ${{ vars.TELEGRAM_CHANNEL }} + run: | + set -uo pipefail + if [ -z "${CHANNEL}" ] || [ -z "${TELEGRAM_BOT_TOKEN}" ]; then + echo "::notice title=Channel post skipped::Set the TELEGRAM_CHANNEL variable (for example @sozoapp) and make the bot an admin of that channel." + exit 0 + fi + if [ ! -s caption.html ]; then + echo "::warning title=Channel post skipped::No caption was built." + exit 0 + fi + API="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}" + if [ -s banner.png ]; then + curl -sS --fail-with-body -X POST "${API}/sendPhoto" -F "chat_id=${CHANNEL}" \ + -F "photo=@banner.png" -F "caption=
\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 visible_length(caption):
+ """What Telegram counts against the limit: text without tags, in UTF-16 units."""
+ text = html.unescape(re.sub(r"<[^>]+>", "", caption))
+ return len(text.encode("utf-16-le")) // 2
+
+
+def telegram_lines(notes_text):
+ """(tagline, bullets) from a hidden `` block in the notes.
+
+
+ """
+ m = TG_BLOCK.search(notes_text or "")
+ if not m:
+ return "", []
+ tagline, bullets = "", []
+ for line in m.group(1).splitlines():
+ line = line.strip()
+ if line.lower().startswith("tagline:"):
+ tagline = line.split(":", 1)[1].strip()
+ elif line.startswith("- "):
+ bullets.append(line[2:].strip())
+ return tagline, bullets
+
+
+def headlines(notes_text, most=7):
+ """The bold titles of the notes' rows and bullets: one per section in turn.
+
+ A bold label such as `**Windows:**` names a platform, not a change, and the
+ download and community sections are not news; both are left out.
+ """
+ sections, skip = [[]], False
+ for line in (notes_text or "").splitlines():
+ if line.startswith("## "):
+ sections.append([])
+ skip = bool(NOT_NEWS.search(line))
+ continue
+ m = HEADLINE.match(line)
+ if m and not skip and not m.group(2) and not m.group(1).rstrip().endswith(":"):
+ title = m.group(1).strip().rstrip(".")
+ if title and all(title not in s for s in sections):
+ sections[-1].append(title)
+ out = []
+ for i in range(max(len(s) for s in sections)):
+ out += [s[i] for s in sections if i < len(s)]
+ return out[:most]
-def telegram_caption(version, notes_text, log_lines, intro=""):
+def telegram_caption(version, notes_text, log_lines, intro="", release_url="", tv_url=""):
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("- ")]
+ tagline, bullets = telegram_lines(notes_text)
+ tagline = intro.strip() or tagline or f"{t['line1']} {t['line2']}"
+ if not bullets:
+ bullets = headlines(notes_text)
if not bullets:
- bullets = [f"{icon(a)} **{a}**: {txt}" for a, group in ordered(changes(log_lines))
- for _, txt, _ in group]
+ bullets = [txt for _, group in ordered(changes(log_lines)) for _, txt, _ in group]
if not bullets:
- bullets = ["Tuzatishlar va kichik yaxshilanishlar."]
+ bullets = ["Fixes and small improvements."]
+
+ head = [f"π Sozo {html.escape(version)} is out!", "",
+ f"{html.escape(tagline)}"]
+ tail = [""]
+ if release_url:
+ tail.append(f'All files (Windows, macOS, Linux, iOS, Android): '
+ f'Link')
+ if tv_url:
+ tail += ["", f'TV Side: Link']
+ tail += ["", f"π¬ Discord: {DISCORD}", "π Need help? Profile β Help & Support"]
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:
+ line = "- " + md_to_tg(b)
+ if visible_length("\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] + "β¦")
+ room = CAPTION_LIMIT - visible_length("\n".join(head + tail)) - 4
+ out.append("- " + html.escape(re.sub(r"[*`]", "", bullets[0]))[:max(room, 0)] + "β¦")
return "\n".join(out + tail)
@@ -312,7 +355,8 @@ def read_log(path):
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--version", required=True)
- for name in ("sha", "repo", "tag", "assets", "out", "telegram", "previous", "log"):
+ for name in ("sha", "repo", "tag", "assets", "out", "telegram", "previous", "log",
+ "release-url", "tv-url"):
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")
@@ -325,7 +369,8 @@ def main():
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")
+ telegram_caption(args.version, text, log_lines, args.intro,
+ args.release_url, args.tv_url), encoding="utf-8")
if not args.out:
return 0
diff --git a/tool/compose_release_notes_test.py b/tool/compose_release_notes_test.py
index 6a1bde83..875489aa 100644
--- a/tool/compose_release_notes_test.py
+++ b/tool/compose_release_notes_test.py
@@ -7,7 +7,7 @@
import datetime as dt
import re
-from compose_release_notes import changes, compose, generate, telegram_caption
+from compose_release_notes import changes, compose, generate, telegram_caption, visible_length
from release_banner import banner_text, render, still
SHA = "abc123"
@@ -128,43 +128,75 @@ def test_generated_page_shows_the_committed_banner(self):
self.assertNotIn("compare/", out)
-UZ_NOTES = """
-