fix(cd): 修復 Telegram 通知 400 錯誤 - 改用 printf + data-urlencode
%0A 在 curl -d 不會被 Telegram 正確解析導致 400。 改用 printf '%b' + --data-urlencode 'text@-' 管道方式, 確保換行符正確 URL encode 後傳送。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,11 +43,13 @@ jobs:
|
||||
echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Notify Pipeline Start
|
||||
env:
|
||||
TG_MSG: "🚀 <b>AWOOOI 部署開始</b>\n├ 📝 ${{ steps.commit.outputs.message }}\n├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>\n├ 👤 ${{ github.actor }}\n└ 🌿 main"
|
||||
run: |
|
||||
curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d parse_mode="HTML" \
|
||||
-d "text=🚀 <b>AWOOOI 部署開始</b>%0A├ 📝 ${{ steps.commit.outputs.message }}%0A├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>%0A├ 👤 ${{ github.actor }}%0A└ 🌿 main"
|
||||
printf '%b' "$TG_MSG" | curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d "parse_mode=HTML" \
|
||||
--data-urlencode "text@-"
|
||||
|
||||
|
||||
|
||||
@@ -206,20 +208,24 @@ jobs:
|
||||
CHECK
|
||||
|
||||
- name: Notify Health Check Success
|
||||
env:
|
||||
TG_MSG: "✅ <b>AWOOOI 部署完成</b>\n├ 📝 ${{ steps.commit.outputs.message }}\n├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>\n├ ⏱️ 耗時: ${MINUTES}m ${SECONDS}s\n├ 📦 API: ✅ Web: ✅\n└ 🩺 Health: ✅"
|
||||
run: |
|
||||
END_TIME=$(date +%s)
|
||||
DURATION=$((END_TIME - ${{ steps.commit.outputs.start_time }}))
|
||||
MINUTES=$((DURATION / 60))
|
||||
SECONDS=$((DURATION % 60))
|
||||
curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d parse_mode="HTML" \
|
||||
-d "text=✅ <b>AWOOOI 部署完成</b>%0A├ 📝 ${{ steps.commit.outputs.message }}%0A├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>%0A├ ⏱️ 耗時: ${MINUTES}m ${SECONDS}s%0A├ 📦 API: ✅ Web: ✅%0A└ 🩺 Health: ✅"
|
||||
printf '%b' "$TG_MSG" | curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d "parse_mode=HTML" \
|
||||
--data-urlencode "text@-"
|
||||
|
||||
- name: Notify Pipeline Failure
|
||||
if: failure()
|
||||
env:
|
||||
TG_MSG: "❌ <b>AWOOOI 部署失敗</b>\n├ 📝 ${{ steps.commit.outputs.message }}\n├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>\n├ 👤 ${{ github.actor }}\n└ 🔗 <a href=\"http://192.168.0.110:3001/wooo/awoooi/actions\">查看日誌</a>"
|
||||
run: |
|
||||
curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d parse_mode="HTML" \
|
||||
-d "text=❌ <b>AWOOOI 部署失敗</b>%0A├ 📝 ${{ steps.commit.outputs.message }}%0A├ 🔖 <code>${{ steps.commit.outputs.short_sha }}</code>%0A├ 👤 ${{ github.actor }}%0A└ 🔗 <a href=\"http://192.168.0.110:3001/wooo/awoooi/actions\">查看日誌</a>"
|
||||
printf '%b' "$TG_MSG" | curl -fS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
|
||||
-d "parse_mode=HTML" \
|
||||
--data-urlencode "text@-"
|
||||
|
||||
Reference in New Issue
Block a user