ci: improve Telegram release notification layout
This commit is contained in:
@@ -271,31 +271,59 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import re
|
import html
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
notes = open("release-notes.md", "r", encoding="utf-8").read().strip()
|
notes = open("release-notes.md", "r", encoding="utf-8").read().strip()
|
||||||
lines = []
|
entries = []
|
||||||
for raw in notes.splitlines():
|
for raw in notes.splitlines():
|
||||||
line = re.sub(r"^#{1,6}\s+", "", raw).strip()
|
line = re.sub(r"^#{1,6}\s+", "", raw).strip()
|
||||||
|
line = re.sub(r"^[-*+]\s+", "", line)
|
||||||
line = re.sub(r"\*\*([^*]+)\*\*", r"\1", line)
|
line = re.sub(r"\*\*([^*]+)\*\*", r"\1", line)
|
||||||
line = re.sub(r"\[([^]]+)\]\(([^)]+)\)", r"\1:\2", line)
|
line = re.sub(r"`([^`]+)`", r"\1", line)
|
||||||
lines.append(line)
|
line = re.sub(r"\[([^]]+)\]\([^)]+\)", r"\1", line)
|
||||||
body = "\n".join(lines).strip()
|
if line:
|
||||||
|
entries.append(line)
|
||||||
|
|
||||||
|
sections = []
|
||||||
|
for index, entry in enumerate(entries, 1):
|
||||||
|
parts = re.split(r"[,;。]", entry, maxsplit=1)
|
||||||
|
title = parts[0].strip()
|
||||||
|
description = parts[1].strip() if len(parts) > 1 else ""
|
||||||
|
section = f"<b>{index:02d} {html.escape(title)}</b>"
|
||||||
|
if description:
|
||||||
|
section += "\n" + html.escape(description.rstrip("。") + "。")
|
||||||
|
sections.append(section)
|
||||||
|
|
||||||
tag = os.environ["RELEASE_TAG"]
|
tag = os.environ["RELEASE_TAG"]
|
||||||
release_url = os.environ["RELEASE_URL"]
|
prefix = f"<b>NewSzxcn Email {html.escape(tag)}</b>\n新版本现已发布\n\n<b>本次更新</b>\n\n"
|
||||||
prefix = f"NewSzxcn Email {tag}\n\n"
|
available = max(0, 3600 - len(prefix))
|
||||||
suffix = f"\n\n更新地址:{release_url}"
|
visible_sections = []
|
||||||
available = max(0, 3600 - len(prefix) - len(suffix))
|
used = 0
|
||||||
if len(body) > available:
|
for section in sections:
|
||||||
body = body[:available].rstrip() + "..."
|
added = len(section) + (2 if visible_sections else 0)
|
||||||
open("telegram-release-message.txt", "w", encoding="utf-8").write(prefix + body + suffix)
|
if used + added > available:
|
||||||
|
break
|
||||||
|
visible_sections.append(section)
|
||||||
|
used += added
|
||||||
|
body = "\n\n".join(visible_sections)
|
||||||
|
if len(visible_sections) < len(sections):
|
||||||
|
body += "\n\n更新内容较长,请点击下方按钮查看完整内容。"
|
||||||
|
open("telegram-release-message.txt", "w", encoding="utf-8").write(prefix + body)
|
||||||
PY
|
PY
|
||||||
|
|
||||||
jq -n \
|
jq -n \
|
||||||
--arg chat_id "${TELEGRAM_CHAT_ID}" \
|
--arg chat_id "${TELEGRAM_CHAT_ID}" \
|
||||||
|
--arg release_url "${RELEASE_URL}" \
|
||||||
--rawfile text telegram-release-message.txt \
|
--rawfile text telegram-release-message.txt \
|
||||||
'{chat_id:$chat_id,text:$text,disable_web_page_preview:true}' > telegram-release-payload.json
|
'{
|
||||||
|
chat_id:$chat_id,
|
||||||
|
text:$text,
|
||||||
|
parse_mode:"HTML",
|
||||||
|
disable_web_page_preview:true,
|
||||||
|
reply_markup:{inline_keyboard:[[{text:"查看本次更新 ↗",url:$release_url}]]}
|
||||||
|
}' > telegram-release-payload.json
|
||||||
|
|
||||||
http_code="$(curl -sS --retry 2 --retry-all-errors --connect-timeout 10 --max-time 30 \
|
http_code="$(curl -sS --retry 2 --retry-all-errors --connect-timeout 10 --max-time 30 \
|
||||||
-o telegram-release-response.json -w '%{http_code}' \
|
-o telegram-release-response.json -w '%{http_code}' \
|
||||||
|
|||||||
Reference in New Issue
Block a user