|
1 | 1 | name: community-release-notifier |
| 2 | + |
2 | 3 | on: |
3 | 4 | release: |
4 | 5 | types: [ released ] |
5 | 6 | workflow_call: |
6 | 7 | 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: '' |
20 | 21 | secrets: |
21 | 22 | DISCORD_WEBHOOK_RELEASE_NOTES: |
22 | 23 | description: 'Discord Webhook for Notifying Releases to Discord' |
23 | 24 | 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 |
24 | 34 |
|
25 | 35 | jobs: |
26 | | - discord-release: |
| 36 | + notify: |
27 | 37 | if: github.repository_owner == 'Acode-Foundation' |
28 | 38 | runs-on: ubuntu-latest |
29 | 39 | 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) |
37 | 52 | |
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@b217a69502f52803de774ded2b1ab7c282e99645 # v7.0.0 |
| 104 | + with: |
| 105 | + webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }} |
| 106 | + content: ${{ steps.truncate-discord.outputs.string }} |
| 107 | + flags: 4 # 1 << 2 - SUPPRESS_EMBEDS! |
| 108 | + |
| 109 | + # ──────────────────────────────────────────────── |
| 110 | + # Telegram notification — MarkdownV2 + no link preview |
| 111 | + # ──────────────────────────────────────────────── |
| 112 | + - name: Send to Telegram |
| 113 | + #if: ${{ secrets.TELEGRAM_BOT_TOKEN != '' && secrets.TELEGRAM_CHAT_ID != '' && secrets.TELEGRAM_MESSAGE_THREAD_ID != '' }} |
| 114 | + uses: Salmansha08/telegram-github-action@17c9ce6b4210d2659dca29d34028b02fa29d70ad # or newer tag if available |
| 115 | + with: |
| 116 | + to: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 117 | + token: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 118 | + message: | |
| 119 | + ${{ steps.vars.outputs.announce }} |
39 | 120 |
|
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 }} |
| 121 | + ${{ steps.vars.outputs.body_safe }} |
| 122 | + format: markdown |
| 123 | + disable_web_page_preview: true |
| 124 | + # Only needed for topic-enabled supergroups/channels |
| 125 | + message_thread_id: ${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }} |
| 126 | + continue-on-error: true |
0 commit comments