Skip to content

Commit d424ae5

Browse files
committed
feat: testing workflows for telegram commits
Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent e26cc83 commit d424ae5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Telegram – Last 10 Commits
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
send:
13+
runs-on: ubuntu-latest
14+
environment: SANDBOX # uses TG_BOT_TOKEN and TG_CHAT_ID secrets from your env
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 50 # fetch enough history for git log
20+
21+
- name: Build message
22+
id: msg
23+
shell: bash
24+
run: |
25+
set -euo pipefail
26+
27+
REPO="${{ github.repository }}"
28+
ACTOR="${{ github.actor }}"
29+
REF_NAME="${{ github.ref_name }}"
30+
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
31+
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
32+
33+
# Last 10 commits
34+
COMMITS="$(git log -n 10 --pretty=format:'- %s (%h) by %an' || true)"
35+
[[ -z "$COMMITS" ]] && COMMITS="- (no commit messages found)"
36+
37+
MESSAGE=$(
38+
printf "📣 Last 10 commits\nRepo: %s\nBy: %s\nRef: %s\nRun: %s\n\n%s\n\nRepo: %s\n" \
39+
"$REPO" "$ACTOR" "$REF_NAME" "$RUN_URL" "$COMMITS" "$REPO_URL"
40+
)
41+
42+
{
43+
echo "text<<EOF"
44+
echo "$MESSAGE"
45+
echo "EOF"
46+
} >> "$GITHUB_OUTPUT"
47+
48+
- name: Send to Telegram
49+
env:
50+
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
51+
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
52+
TEXT: ${{ steps.msg.outputs.text }}
53+
shell: bash
54+
run: |
55+
set -euo pipefail
56+
57+
if [[ -z "${TG_BOT_TOKEN:-}" || -z "${TG_CHAT_ID:-}" ]]; then
58+
echo "❌ Telegram secrets missing"
59+
exit 1
60+
fi
61+
62+
# Send message
63+
curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
64+
-H 'Content-Type: application/json' \
65+
-d "$(jq -n --arg chat_id "$TG_CHAT_ID" --arg text "$TEXT" \
66+
'{chat_id:$chat_id, text:$text, disable_web_page_preview:true}')"
67+
68+
echo "✅ Posted last 10 commits to Telegram channel."

0 commit comments

Comments
 (0)