Skip to content

Commit e70393b

Browse files
committed
fix(ci): improve Telegram notifications, escape MarkdownV2
1 parent e990f31 commit e70393b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ jobs:
168168
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
169169
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
170170
RELEASE_TAG: ${{ needs.release.outputs.tag }}
171+
GITHUB_ACTOR: ${{ github.actor }}
171172
run: |
172173
if [ "${IS_ACT}" = "true" ]; then
173174
TAG="local-test"
@@ -181,7 +182,7 @@ jobs:
181182
DATE=$(date +"%Y-%m-%d %H:%M:%S UTC")
182183
183184
escape_md() {
184-
echo "$1" | sed -E 's/([_*\[\]()~`>#+=|{}.!-])/\\\1/g'
185+
echo "$1" | perl -pe 's/([_\*\[\]\(\)~`>#+=|\{\}\.\!\-])/\\$1/g'
185186
}
186187
187188
eTAG=$(escape_md "$TAG")
@@ -197,8 +198,8 @@ jobs:
197198
"🔗 [View GitHub Action Run](${eActionRun})"
198199
199200
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
200-
-d "chat_id=${TELEGRAM_CHAT_ID}" \
201-
-d "text=$MESSAGE" \
201+
--data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \
202+
--data-urlencode "text=${MESSAGE}" \
202203
-d "parse_mode=MarkdownV2"
203204
204205
notify-error:
@@ -220,6 +221,7 @@ jobs:
220221
GITHUB_ACTOR: ${{ github.actor }}
221222
GITHUB_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
222223
run: |
224+
LAST_AUTHOR="${GITHUB_ACTOR}"
223225
AUTHOR_LINK="https://github.com/${LAST_AUTHOR}"
224226
FAILED_STEPS=()
225227
@@ -241,14 +243,14 @@ jobs:
241243
FAILED_LIST=$(IFS=','; echo "${FAILED_STEPS[*]}")
242244
243245
escape_md() {
244-
echo "$1" | sed -E 's/([_*\[\]()~`>#+=|{}.!-])/\\\1/g'
246+
echo "$1" | perl -pe 's/([_\*\[\]\(\)~`>#+=|\{\}\.\!\-])/\\$1/g'
245247
}
246248
247249
eFailedList=$(escape_md "$FAILED_LIST")
248-
eActor=$(escape_md "$GITHUB_ACTOR")
250+
eActor=$(escape_md "$LAST_AUTHOR")
249251
eAuthorLink="$AUTHOR_LINK"
250252
eRunURL="$GITHUB_RUN_URL"
251-
eDate=$(escape_md "$(date +"%Y-%m-%d %H:%M:%S")")
253+
eDate=$(escape_md "$(date -u +"%Y-%m-%d %H:%M:%S UTC")")
252254
253255
MESSAGE="❌ *Pipeline Error Detected*\n"\
254256
"⚠️ Failed Steps: *${eFailedList}*\n"\
@@ -257,6 +259,6 @@ jobs:
257259
"🔗 Run URL: [View Run](${eRunURL})"
258260
259261
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
260-
-d "chat_id=${TELEGRAM_CHAT_ID}" \
261-
-d "text=$MESSAGE" \
262+
--data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \
263+
--data-urlencode "text=${MESSAGE}" \
262264
-d "parse_mode=MarkdownV2"

0 commit comments

Comments
 (0)