Skip to content

Commit 2e1bb1d

Browse files
committed
Add chat notifier workflow
1 parent b7ebc23 commit 2e1bb1d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Push -> Telegram (read-only tags)
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
notify:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout pushed ref (full)
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Find latest rev tag
20+
id: latest
21+
run: |
22+
# find latest rev-* tag by creation date; leave empty if none
23+
entry=$(git for-each-ref --sort=-creatordate --format='%(refname:short) %(creatordate:unix)' refs/tags | grep '^rev-[0-9]\+' | head -n1 || true)
24+
if [ -z "$entry" ]; then
25+
echo "::set-output name=tag::"
26+
echo "::set-output name=ts::"
27+
else
28+
tag=$(echo "$entry" | awk '{print $1}')
29+
ts=$(echo "$entry" | awk '{print $2}')
30+
echo "::set-output name=tag::$tag"
31+
echo "::set-output name=ts::$ts"
32+
fi
33+
34+
- name: Build Telegram message
35+
id: message
36+
run: |
37+
repo="${GITHUB_REPOSITORY}"
38+
branch="${GITHUB_REF#refs/heads/}"
39+
sha_full="${GITHUB_SHA}"
40+
sha="${sha_full::7}"
41+
author="$(git --no-pager show -s --format='%an' $GITHUB_SHA || echo '')"
42+
msg="$(git --no-pager show -s --format='%s' $GITHUB_SHA || echo '')"
43+
latest_tag="${{ steps.latest.outputs.tag }}"
44+
tag_part="Rev: ${latest_tag:-(none)}"
45+
body="Repo: ${repo}%0ABranch: ${branch}%0ACommit: ${sha}%0AAuthor: ${author}%0AMessage: ${msg}%0A${tag_part}"
46+
echo "::set-output name=body::$body"
47+
48+
- name: Send Telegram notification
49+
env:
50+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
51+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
52+
run: |
53+
if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
54+
echo "Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID secrets; skipping send."
55+
exit 0
56+
fi
57+
body="${{ steps.message.outputs.body }}"
58+
curl -sS --fail -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
59+
-d "chat_id=${TELEGRAM_CHAT_ID}" \
60+
-d "text=${body}" \
61+
-d "parse_mode=HTML"

0 commit comments

Comments
 (0)