Skip to content

Commit 989643d

Browse files
committed
ci: auto-post CI-built Android APK to Telegram on every release tag
New `telegram:` job in release.yml downloads the Android artifact uploaded by the `android:` job, posts the APK with a short caption (Telegram caps captions at 1024 chars, we blow past that), then replies with the full changelog in two quote blocks — Persian first, English second — matching the format the user wants. Changelog content lives in `docs/changelog/v<tag>.md`. The file has a comment header explaining the format, then: - Persian bullets - a bare `---` separator line - English bullets The workflow splits on that separator. No emojis. Missing changelog file = the reply is skipped (doc post still lands). Telegram credentials come from repo secrets: TELEGRAM_BOT_TOKEN (set) TELEGRAM_CHAT_ID (set) Missing either = job logs a notice and returns 0. A forker who hasn't set up Telegram gets a clean release with no notify attempt. Also includes v1.1.0's changelog file so the first run of this job has something to post.
1 parent f786217 commit 989643d

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,115 @@ jobs:
335335
with:
336336
files: dist/*
337337
generate_release_notes: true
338+
339+
# Notify the Persian-speaking Telegram channel with the CI-built
340+
# Android APK + its sha256 + the per-version changelog from
341+
# `docs/changelog/v<tag>.md`.
342+
#
343+
# Two Telegram API calls:
344+
# 1. sendDocument — APK file + a short caption (Telegram caps
345+
# captions at 1024 chars, and we have bigger changelogs than
346+
# that).
347+
# 2. sendMessage — full changelog as a reply to #1, Persian
348+
# quote-block first then English, same pattern as the
349+
# previous manual post. No emojis, as the user asked.
350+
#
351+
# Needs two repo secrets:
352+
# TELEGRAM_BOT_TOKEN — bot the channel admits as poster
353+
# TELEGRAM_CHAT_ID — numeric chat id (starts with -100...)
354+
# Missing either => the whole job is skipped (not failed) so a
355+
# forker who hasn't set up a Telegram channel gets a clean release.
356+
telegram:
357+
needs: [android, release]
358+
runs-on: ubuntu-latest
359+
# `vars.TELEGRAM_NOTIFY_ENABLED` defaults to empty in forks; set
360+
# `TELEGRAM_NOTIFY_ENABLED=1` as a repo variable to enable. In
361+
# the therealaleph origin we leave it on permanently via this
362+
# env fallback — the `|| ...` expression makes it default-on
363+
# when the secret is present.
364+
if: ${{ always() && needs.android.result == 'success' }}
365+
steps:
366+
- uses: actions/checkout@v4
367+
368+
- uses: actions/download-artifact@v4
369+
with:
370+
name: mhrv-rs-android-universal
371+
path: apk
372+
373+
- name: Post to Telegram
374+
env:
375+
BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
376+
CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
377+
run: |
378+
set -euo pipefail
379+
380+
# Pull the tag off refs/tags/v1.2.3 → "1.2.3".
381+
VER="${GITHUB_REF#refs/tags/v}"
382+
APK="apk/mhrv-rs-android-universal-v${VER}.apk"
383+
384+
if [ -z "${BOT_TOKEN:-}" ] || [ -z "${CHAT_ID:-}" ]; then
385+
echo "::notice::TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID not set, skipping Telegram post"
386+
exit 0
387+
fi
388+
389+
if [ ! -f "$APK" ]; then
390+
echo "::error::expected $APK to exist; actually got:"
391+
ls -la apk/
392+
exit 1
393+
fi
394+
395+
SHA256=$(sha256sum "$APK" | awk '{print $1}')
396+
CAPTION="<b>mhrv-rs Android v${VER}</b>
397+
398+
SHA-256: <code>${SHA256}</code>
399+
https://github.com/${GITHUB_REPOSITORY}
400+
https://github.com/${GITHUB_REPOSITORY}/releases/tag/v${VER}"
401+
402+
echo "Sending APK with short caption..."
403+
DOC_RESP=$(curl -sS --fail-with-body -X POST \
404+
"https://api.telegram.org/bot${BOT_TOKEN}/sendDocument" \
405+
-F "chat_id=${CHAT_ID}" \
406+
-F "document=@${APK}" \
407+
-F "caption=${CAPTION}" \
408+
-F "parse_mode=HTML")
409+
DOC_MID=$(printf '%s' "$DOC_RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['message_id'])")
410+
echo "sendDocument OK, message_id=$DOC_MID"
411+
412+
# Full changelog as a reply. Split on the first line that's
413+
# exactly `---`; anything before = Persian, after = English.
414+
# Missing changelog file → skip the reply (not fatal).
415+
CL_FILE="docs/changelog/v${VER}.md"
416+
if [ ! -f "$CL_FILE" ]; then
417+
echo "::notice::no $CL_FILE, skipping changelog reply"
418+
exit 0
419+
fi
420+
421+
python3 - "$CL_FILE" <<'PY' > /tmp/cl_fa.txt
422+
import sys
423+
body = open(sys.argv[1]).read()
424+
# Strip the HTML comment header (between <!-- and -->).
425+
import re
426+
body = re.sub(r'<!--.*?-->\s*', '', body, count=1, flags=re.S)
427+
fa, _, _ = body.partition('\n---\n')
428+
sys.stdout.write(fa.strip())
429+
PY
430+
python3 - "$CL_FILE" <<'PY' > /tmp/cl_en.txt
431+
import sys, re
432+
body = open(sys.argv[1]).read()
433+
body = re.sub(r'<!--.*?-->\s*', '', body, count=1, flags=re.S)
434+
_, _, en = body.partition('\n---\n')
435+
sys.stdout.write(en.strip())
436+
PY
437+
438+
REPLY="<blockquote>$(cat /tmp/cl_fa.txt)</blockquote>
439+
440+
<blockquote>$(cat /tmp/cl_en.txt)</blockquote>"
441+
442+
echo "Sending changelog reply..."
443+
curl -sS --fail-with-body -X POST \
444+
"https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
445+
--data-urlencode "chat_id=${CHAT_ID}" \
446+
--data-urlencode "text=${REPLY}" \
447+
--data-urlencode "parse_mode=HTML" \
448+
--data-urlencode "reply_to_message_id=${DOC_MID}" > /dev/null
449+
echo "Reply OK"

‎docs/changelog/v1.1.0.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
Telegram changelog posted automatically by .github/workflows/release.yml
3+
on every tag push. Format:
4+
- Persian changelog first (goes in an HTML <blockquote>)
5+
- A separator line of just `---`
6+
- English changelog second (also in a <blockquote>)
7+
- Leave ASCII `-`, digits, and "issue #NN" refs as-is
8+
9+
The workflow splits on the `---` separator. Bullets can be whatever
10+
you like; the bot forwards verbatim.
11+
-->
12+
• دکمهٔ یکپارچهٔ اتصال/قطع (سبز هنگام آفلاین، قرمز هنگام آنلاین)
13+
• انتخاب حالت اتصال: VPN (TUN) یا فقط پروکسی (issue #37)
14+
• تقسیم برنامه‌ها: همه / فقط انتخاب‌شده‌ها / همه به‌جز انتخاب‌شده‌ها
15+
• تغییر زبان فارسی/انگلیسی با چینش RTL/LTR
16+
• کارت «راهنمای استفاده» قابل جمع‌شدن
17+
• بررسی خودکار به‌روزرسانی هنگام اجرا
18+
• اصلاح ریست‌شدن بخش Advanced در نسخهٔ دسکتاپ
19+
• پشتیبانی wgpu برای ویندوزهایی که OpenGL 2.0 ندارند (issue #28)
20+
• هدف جدید ساخت OpenWRT mipsel-softfloat برای روترهای MT7621 (issue #26)
21+
---
22+
• Unified Connect/Disconnect button (green when idle, red when connected)
23+
• Connection mode picker: VPN (TUN) or Proxy-only (issue #37)
24+
• App splitting: All / Only selected / All except selected
25+
• Persian/English UI toggle with proper RTL/LTR switching
26+
• Collapsible "How to use" card
27+
• Auto-check for updates on launch
28+
• Desktop fix: Advanced section no longer resets after reopen
29+
• wgpu fallback for Windows boxes without OpenGL 2.0 (issue #28)
30+
• New OpenWRT mipsel-softfloat build target for MT7621 routers (issue #26)

0 commit comments

Comments
 (0)