-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcode-release-notify-telegram.yml
More file actions
49 lines (43 loc) · 1.98 KB
/
Copy pathcode-release-notify-telegram.yml
File metadata and controls
49 lines (43 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Notify Telegram on Release
on:
schedule:
- cron: "0 6 * * 2" # Every Tuesday at 2:00pm SGT (UTC+8)
workflow_dispatch: # Allow manual trigger
permissions:
contents: read
jobs:
check-releases:
runs-on: ubuntu-latest
steps:
- name: Check for new releases in the last 7 days
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_TOPIC_ID: ${{ secrets.TELEGRAM_TOPIC_ID_CODE }}
run: |
# Get releases from the last 7 days via GitHub API
SINCE=$(date -u -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-7d +%Y-%m-%dT%H:%M:%SZ)
RESPONSE=$(curl -s -H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/releases?per_page=10")
# Parse releases newer than $SINCE and format message
MESSAGE=$(echo "$RESPONSE" | jq -r --arg since "$SINCE" '
map(select(.published_at > $since and .draft == false and .prerelease == false))
| if length == 0 then empty
else
"📦 *SGDS Web Component Releases (last 7 days)*\n\n" +
(map("• *" + .name + "*\n" + (.body | split("\n") | map(select(length > 0)) | first // "No description") + "\n [View on GitHub](" + .html_url + ")") | join("\n\n"))
end
')
# Send to Telegram if there are new releases
if [ -n "$MESSAGE" ]; then
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d chat_id="${TELEGRAM_CHAT_ID}" \
-d message_thread_id="${TELEGRAM_TOPIC_ID}" \
-d parse_mode="Markdown" \
-d text="${MESSAGE}"
echo "Notification sent."
else
echo "No new releases in the last 7 days."
fi