Skip to content

Commit 14b4248

Browse files
chore: add Telegram Notifier to Nightly CI pipeline (#1934)
* chore: message type detection in release notes script * Remove redundant check for message prefix * update: community-release-notifier with Telegram support Updated community release notifier workflow to include Telegram notifications and improved variable handling. * Merge pull request #12 from UnschooledGamer/UnschooledGamer-patch-1-1 Add Telegram bot secrets to nightly-build.yml * Update Telegram action in workflow file * Refactor release variables for safety and clarity * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * chore: enhance community release notifier with delimiter * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update community-release-notifier.yml Mobile edits 😶🙏🙃 * Update community-release-notifier.yml Another mobile edits 😶 * Update .github/workflows/community-release-notifier.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update community-release-notifier.yml * chore: fix telegram creds requirements --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 01bbc5c commit 14b4248

File tree

2 files changed

+111
-27
lines changed

2 files changed

+111
-27
lines changed
Lines changed: 108 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,125 @@
11
name: community-release-notifier
2+
23
on:
34
release:
45
types: [ released ]
56
workflow_call:
67
inputs:
7-
tag_name:
8-
required: true
9-
description: "Release tag_name"
10-
type: 'string'
11-
url:
12-
required: true
13-
description: "release URL"
14-
type: 'string'
15-
body:
16-
required: true
17-
description: "Release Body"
18-
type: 'string'
19-
default: ''
8+
tag_name:
9+
required: true
10+
description: "Release tag_name"
11+
type: 'string'
12+
url:
13+
required: true
14+
description: "release URL"
15+
type: 'string'
16+
body:
17+
required: true
18+
description: "Release Body"
19+
type: 'string'
20+
default: ''
2021
secrets:
2122
DISCORD_WEBHOOK_RELEASE_NOTES:
2223
description: 'Discord Webhook for Notifying Releases to Discord'
2324
required: true
25+
TELEGRAM_BOT_TOKEN:
26+
description: 'Telegram Bot Token'
27+
required: true
28+
TELEGRAM_CHAT_ID:
29+
description: 'Telegram Chat ID (group/channel/supergroup)'
30+
required: true
31+
TELEGRAM_MESSAGE_THREAD_ID:
32+
description: 'Topic / message_thread_id for Telegram forum/topic'
33+
required: true
2434

2535
jobs:
26-
discord-release:
36+
notify:
2737
if: github.repository_owner == 'Acode-Foundation'
2838
runs-on: ubuntu-latest
2939
steps:
30-
- name: Get Release Content
31-
id: get-release-content
32-
uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1
33-
with:
34-
maxLength: 2000
35-
stringToTruncate: |
36-
📢 Acode [${{ github.event.release.tag_name || inputs.tag_name }}](<${{ github.event.release.url || inputs.url }}>) was just Released 🎉!
40+
- name: Prepare release variables
41+
id: vars
42+
env:
43+
INPUT_TAG: ${{ github.event.release.tag_name || inputs.tag_name }}
44+
INPUT_URL: ${{ github.event.release.url || inputs.url }}
45+
INPUT_BODY: ${{ github.event.release.body || inputs.body }}
46+
run: |
47+
TAG="$INPUT_TAG"
48+
URL="$INPUT_URL"
49+
50+
# Generate a random delimiter (hex string, safe and collision-resistant)
51+
DELIMITER=$(openssl rand -hex 16 || head -c 16 /dev/urandom | xxd -p -c 16)
3752
38-
${{ github.event.release.body || inputs.body }}
53+
# Escape problematic characters for MarkdownV2 (very conservative escaping)
54+
# We escape: _ * [ ] ( ) ~ ` > # + - = | { } . ! \
55+
BODY_SAFE=$(printf '%s' "$INPUT_BODY" | \
56+
sed 's/[_*[\]()~`>#+=|{}.!\\-]/\\&/g')
57+
TAG_SAFE=$(printf '%s' "$TAG" | sed 's/[_*[\]()~`>#+=|{}.!\\-]/\\&/g')
58+
59+
if [[ "$TAG" == *"-nightly"* ]]; then
60+
SUFFIX=" \\(Nightly Release\\)"
61+
SUFFIXPLAIN=" (Nightly Release)"
62+
else
63+
SUFFIX=""
64+
SUFFIXPLAIN=""
65+
fi
66+
67+
# Announcement line — also escape for safety
68+
ANNOUNCE_SAFE="📢 Acode [$TAG_SAFE]($URL) was just Released 🎉${SUFFIX}\\!"
69+
70+
echo "announce=$ANNOUNCE_SAFE" >> $GITHUB_OUTPUT
71+
{
72+
echo "body_safe<<$DELIMITER"
73+
printf '%s\n' "$BODY_SAFE"
74+
echo "$DELIMITER"
75+
} >> $GITHUB_OUTPUT
76+
77+
# Plain (MD) Announcement for Discord
78+
ANNOUNCE_PLAIN="📢 Acode [$TAG]($URL) was just Released 🎉${SUFFIXPLAIN}!"
79+
echo "announce_plain=$ANNOUNCE_PLAIN" >> $GITHUB_OUTPUT
80+
{
81+
echo "body_plain<<$DELIMITER"
82+
printf '%s\n' "$INPUT_BODY"
83+
echo "$DELIMITER"
84+
} >> $GITHUB_OUTPUT
85+
86+
# ────────────────────────────────────────────────
87+
# Truncate for Discord
88+
# ────────────────────────────────────────────────
89+
- name: Truncate message for Discord
90+
id: truncate-discord
91+
uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1
92+
with:
93+
maxLength: 2000
94+
stringToTruncate: |
95+
${{ steps.vars.outputs.announce_plain }}
96+
97+
${{ steps.vars.outputs.body_plain }}
98+
99+
# ────────────────────────────────────────────────
100+
# Discord notification
101+
# ────────────────────────────────────────────────
102+
- name: Discord Webhook (Publishing)
103+
uses: tsickert/discord-webhook@c840d45a03a323fbc3f7507ac7769dbd91bfb164 # v5.3.0
104+
with:
105+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
106+
content: ${{ steps.truncate-discord.outputs.string }}
107+
108+
# ────────────────────────────────────────────────
109+
# Telegram notification — MarkdownV2 + no link preview
110+
# ────────────────────────────────────────────────
111+
- name: Send to Telegram
112+
if: ${{ secrets.TELEGRAM_BOT_TOKEN != "" && secrets.TELEGRAM_CHAT_ID != "" && secrets.TELEGRAM_MESSAGE_THREAD_ID != "" }}
113+
uses: Salmansha08/telegram-github-action@17c9ce6b4210d2659dca29d34028b02fa29d70ad # or newer tag if available
114+
with:
115+
to: ${{ secrets.TELEGRAM_CHAT_ID }}
116+
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
117+
message: |
118+
${{ steps.vars.outputs.announce }}
39119
40-
- name: Discord Webhook Action (Publishing)
41-
uses: tsickert/discord-webhook@c840d45a03a323fbc3f7507ac7769dbd91bfb164 # v5.3.0
42-
with:
43-
webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
44-
content: ${{ steps.get-release-content.outputs.string }}
120+
${{ steps.vars.outputs.body_safe }}
121+
parse_mode: MarkdownV2
122+
disable_web_page_preview: true
123+
# Only needed for topic-enabled supergroups/channels
124+
message_thread_id: ${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }}
125+
continue-on-error: true

.github/workflows/nightly-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,6 @@
283283
body: ${{ needs.build.outputs.RELEASE_NOTES }}
284284
secrets:
285285
DISCORD_WEBHOOK_RELEASE_NOTES: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
286+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
287+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
288+
TELEGRAM_MESSAGE_THREAD_ID: ${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }}

0 commit comments

Comments
 (0)