|
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: 'Optional: Topic / message_thread_id for Telegram forum/topic' |
| 33 | + required: false |
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 🎉! |
37 | | - |
38 | | - ${{ github.event.release.body || inputs.body }} |
39 | | -
|
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 }} |
| 40 | + - name: Prepare release variables |
| 41 | + id: vars |
| 42 | + run: | |
| 43 | + TAG="${{ github.event.release.tag_name || inputs.tag_name }}" |
| 44 | + URL="${{ github.event.release.url || inputs.url }}" |
| 45 | + # Escape problematic characters for MarkdownV2 (very conservative escaping) |
| 46 | + # We escape: _ * [ ] ( ) ~ ` > # + - = | { } . ! \ |
| 47 | + BODY_SAFE=$(printf '%s' "${{ github.event.release.body || inputs.body }}" | \ |
| 48 | + sed 's/[_*[\]()~`>#+-=|{}.!\\]/\\&/g') |
| 49 | +
|
| 50 | + if [[ "$TAG" == *"-nightly"* ]]; then |
| 51 | + SUFFIX=" (Nightly Release)" |
| 52 | + else |
| 53 | + SUFFIX="" |
| 54 | + fi |
| 55 | +
|
| 56 | + # Announcement line — also escape for safety |
| 57 | + ANNOUNCE_SAFE="📢 Acode \[$TAG\]($URL) was just Released 🎉$SUFFIX!" |
| 58 | +
|
| 59 | + echo "announce=$ANNOUNCE_SAFE" >> $GITHUB_OUTPUT |
| 60 | + echo "body_safe=$BODY_SAFE" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + # ──────────────────────────────────────────────── |
| 63 | + # Truncate for Discord |
| 64 | + # ──────────────────────────────────────────────── |
| 65 | + - name: Truncate message for Discord |
| 66 | + id: truncate-discord |
| 67 | + uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1 |
| 68 | + with: |
| 69 | + maxLength: 2000 |
| 70 | + stringToTruncate: | |
| 71 | + ${{ steps.vars.outputs.announce }} |
| 72 | +
|
| 73 | + ${{ steps.vars.outputs.body_safe }} |
| 74 | +
|
| 75 | + # ──────────────────────────────────────────────── |
| 76 | + # Discord notification |
| 77 | + # ──────────────────────────────────────────────── |
| 78 | + - name: Discord Webhook (Publishing) |
| 79 | + uses: tsickert/discord-webhook@c840d45a03a323fbc3f7507ac7769dbd91bfb164 # v5.3.0 |
| 80 | + with: |
| 81 | + webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }} |
| 82 | + content: ${{ steps.truncate-discord.outputs.string }} |
| 83 | + continue-on-error: true |
| 84 | + |
| 85 | + # ──────────────────────────────────────────────── |
| 86 | + # Telegram notification — MarkdownV2 + no link preview |
| 87 | + # ──────────────────────────────────────────────── |
| 88 | + - name: Send to Telegram |
| 89 | + uses: appleboy/telegram-action@v1.0.0 # or newer tag if available |
| 90 | + with: |
| 91 | + to: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 92 | + token: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 93 | + message: | |
| 94 | + ${{ steps.vars.outputs.announce }} |
| 95 | +
|
| 96 | + ${{ steps.vars.outputs.body_safe }} |
| 97 | + parse_mode: MarkdownV2 |
| 98 | + disable_web_page_preview: true |
| 99 | + # Only needed for topic-enabled supergroups/channels |
| 100 | + message_thread_id: ${{ secrets.TELEGRAM_MESSAGE_THREAD_ID }} |
| 101 | + continue-on-error: true |
0 commit comments