Skip to content

Commit ecea250

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

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

.github/workflows/telegram-notify.yml

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ on:
1414
description: "Message to send to Telegram"
1515
required: true
1616
chat_id:
17-
description: "Optional: override TG_CHAT_ID (e.g. @YourChannel or numeric id)"
17+
description: "Override TG_CHAT_ID (optional)"
1818
required: false
1919
parse_mode:
20-
description: "Telegram parse mode (plain|MarkdownV2|HTML)"
20+
description: "plain | MarkdownV2 | HTML"
2121
required: false
2222
default: "plain"
2323

@@ -31,15 +31,14 @@ jobs:
3131
environment: SANDBOX
3232

3333
steps:
34-
- name: Check out (for commit list)
34+
- name: Checkout (for commit list)
3535
uses: actions/checkout@v4
3636
with:
3737
fetch-depth: 0
3838

3939
- name: Build message
4040
id: msg
4141
env:
42-
# Context values (moved to env so the script is pure bash)
4342
REPO: ${{ github.repository }}
4443
ACTOR: ${{ github.actor }}
4544
EVENT: ${{ github.event_name }}
@@ -61,87 +60,87 @@ jobs:
6160
REL_URL: ${{ github.event.release.html_url }}
6261

6362
DISPATCH_TEXT: ${{ github.event.inputs.text }}
64-
shell: bash
6563
run: |
64+
bash <<'BASH'
6665
set -euo pipefail
6766
6867
msg_header() {
69-
echo "📣 $1
68+
cat <<TXT
69+
📣 $1
7070
Repo: $REPO
7171
By: $ACTOR
7272
Ref: $REF_NAME
73-
Run: $RUN_URL"
73+
Run: $RUN_URL
74+
TXT
7475
}
75-
76-
if [[ "$EVENT" == "workflow_dispatch" ]]; then
76+
if [[ "${EVENT}" == "workflow_dispatch" ]]; then
7777
MESSAGE="$(msg_header "Manual notification")"$'\n\n'"${DISPATCH_TEXT:-}"
78-
elif [[ "$EVENT" == "push" ]]; then
78+
79+
elif [[ "${EVENT}" == "push" ]]; then
7980
BEFORE="${GIT_BEFORE:-}"
80-
AFTER="$GIT_SHA"
81+
AFTER="${GIT_SHA}"
8182
if [[ -z "$BEFORE" || "$BEFORE" =~ ^0+$ ]]; then
8283
COMMITS="$(git log --pretty=format:'- %s (%h) by %an' "$AFTER" -n 10 || true)"
8384
else
8485
COMMITS="$(git log --pretty=format:'- %s (%h) by %an' "$BEFORE..$AFTER" | head -n 10 || true)"
8586
fi
8687
[[ -z "${COMMITS:-}" ]] && COMMITS="- (no commit messages found)"
88+
MESSAGE="$(msg_header "New push detected")"$'\n'"Last changes:"$'\n'"$COMMITS"$'\n\n'"Repo: $REPO_URL"
8789

88-
MESSAGE="$(msg_header "New push detected")"$'\n'"Last changes:"$'\n'"$COMMITS"$'\n\n'"Repo: $REPO_URL"
89-
elif [[ "$EVENT" == "pull_request" ]]; then
90-
if [[ "$PR_ACTION" == "closed" ]]; then
91-
if [[ "$PR_MERGED" == "true" ]]; then
92-
STATUS="PR merged ✅"
93-
else
94-
STATUS="PR closed ❌"
95-
fi
90+
elif [[ "${EVENT}" == "pull_request" ]]; then
91+
if [[ "${PR_ACTION}" == "closed" ]]; then
92+
if [[ "${PR_MERGED}" == "true" ]]; then STATUS="PR merged ✅"; else STATUS="PR closed ❌"; fi
9693
else
9794
STATUS="PR updated ✏️"
9895
fi
99-
MESSAGE="$(msg_header "$STATUS")"$'\n'"#${PR_NUMBER}: ${PR_TITLE}"$'\n'"${PR_URL}"
100-
elif [[ "$EVENT" == "release" ]]; then
96+
MESSAGE="$(msg_header "$STATUS")"$'\n'"#${PR_NUMBER}: ${PR_TITLE}"$'\n'"${PR_URL}"
97+
98+
elif [[ "${EVENT}" == "release" ]]; then
10199
NAME="${REL_NAME:-$REL_TAG}"
102-
MESSAGE="$(msg_header "Release published 🏷️")"$'\n'"Tag: ${REL_TAG}"$'\n'"Name: ${NAME}"$'\n'"${REL_URL}"
100+
MESSAGE="$(msg_header "Release published 🏷️")"$'\n'"Tag: ${REL_TAG}"$'\n'"Name: ${NAME}"$'\n'"${REL_URL}"
101+
103102
else
104-
MESSAGE="$(msg_header "Event: $EVENT")"
103+
MESSAGE="$(msg_header "Event: ${EVENT}")"
105104
fi
106105

107106
{
108107
echo "text<<EOF"
109108
echo "$MESSAGE"
110109
echo "EOF"
111110
} >> "$GITHUB_OUTPUT"
111+
BASH
112112

113113
- name: Send to Telegram
114-
env:
115-
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
116-
TG_CHAT_ID_DEFAULT: ${{ secrets.TG_CHAT_ID }}
117-
TEXT: ${{ steps.msg.outputs.text }}
118-
OVERRIDE_CHAT_ID: ${{ github.event.inputs.chat_id }}
119-
PARSE_MODE: ${{ github.event.inputs.parse_mode }}
120-
run: |
121-
set -euo pipefail
122-
123-
CHAT_ID="${OVERRIDE_CHAT_ID:-$TG_CHAT_ID_DEFAULT}"
124-
if [[ -z "$TG_BOT_TOKEN" || -z "$CHAT_ID" ]]; then
125-
echo "Telegram secrets missing (TG_BOT_TOKEN or TG_CHAT_ID)." >&2
126-
exit 1
127-
fi
128-
129-
case "${PARSE_MODE:-plain}" in
130-
MarkdownV2|HTML) PMODE="$PARSE_MODE" ;;
131-
*) PMODE="" ;;
132-
esac
133-
134-
if [[ -n "$PMODE" ]]; then
135-
PAYLOAD="$(jq -n --arg chat_id "$CHAT_ID" --arg text "$TEXT" --arg pm "$PMODE" \
136-
'{chat_id:$chat_id, text:$text, parse_mode:$pm, disable_web_page_preview:true}')"
137-
else
138-
PAYLOAD="$(jq -n --arg chat_id "$CHAT_ID" --arg text "$TEXT" \
139-
'{chat_id:$chat_id, text:$text, disable_web_page_preview:true}')"
140-
fi
141-
142-
curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
143-
-H 'Content-Type: application/json' \
144-
-d "$PAYLOAD" \
145-
| jq -e '.ok == true' >/dev/null
146-
147-
echo "✅ Message sent to Telegram."
114+
env:
115+
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
116+
TG_CHAT_ID_DEFAULT: ${{ secrets.TG_CHAT_ID }}
117+
TEXT: ${{ steps.msg.outputs.text }}
118+
OVERRIDE_CHAT_ID: ${{ github.event.inputs.chat_id }}
119+
PARSE_MODE: ${{ github.event.inputs.parse_mode }}
120+
run: |
121+
set -euo pipefail
122+
CHAT_ID="${OVERRIDE_CHAT_ID:-$TG_CHAT_ID_DEFAULT}"
123+
if [[ -z "$TG_BOT_TOKEN" || -z "$CHAT_ID" ]]; then
124+
echo "Telegram secrets missing (TG_BOT_TOKEN or TG_CHAT_ID)." >&2
125+
exit 1
126+
fi
127+
128+
case "${PARSE_MODE:-plain}" in
129+
MarkdownV2|HTML) PMODE="$PARSE_MODE" ;;
130+
*) PMODE="" ;;
131+
esac
132+
133+
if [[ -n "$PMODE" ]]; then
134+
PAYLOAD="$(jq -n --arg chat_id "$CHAT_ID" --arg text "$TEXT" --arg pm "$PMODE" \
135+
'{chat_id:$chat_id, text:$text, parse_mode:$pm, disable_web_page_preview:true}')"
136+
else
137+
PAYLOAD="$(jq -n --arg chat_id "$CHAT_ID" --arg text "$TEXT" \
138+
'{chat_id:$chat_id, text:$text, disable_web_page_preview:true}')"
139+
fi
140+
141+
curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
142+
-H 'Content-Type: application/json' \
143+
-d "$PAYLOAD" \
144+
| jq -e '.ok == true' >/dev/null
145+
146+
echo "✅ Message sent to Telegram."

0 commit comments

Comments
 (0)