Files
lunar-mini/.gitea/scripts/notify.sh
T
gouki b5bdf4c88d
Publish Mini Program Dev Version / publish (push) Failing after 10m47s
Build and Deploy Server / build (push) Failing after 2s
fix(wish-tree): 修复切换树时导航栏消失问题
- Canvas添加z-index: 1,确保不覆盖导航栏
- top-bar添加pointer-events: none,子元素恢复auto
- WXML添加trees.length保护,防止空数组访问
- switchTree添加空数组保护
2026-08-07 21:56:38 +00:00

186 lines
4.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 部署通知脚本 - 支持 Telegram 和 Discord
# 使用方法: ./notify.sh <status> <title> <message> [color]
# status: success 或 failure
# title: 通知标题
# message: 通知内容
# color: Discord 消息颜色(可选,默认根据 status 自动选择)
set -e
STATUS="$1"
TITLE="$2"
MESSAGE="$3"
COLOR="${4:-}"
# 根据状态设置默认值
if [ "$STATUS" = "success" ]; then
EMOJI="✅"
DEFAULT_COLOR="3066993" # 绿色
STATUS_TEXT="成功"
elif [ "$STATUS" = "failure" ]; then
EMOJI="❌"
DEFAULT_COLOR="15158332" # 红色
STATUS_TEXT="失败"
else
EMOJI="️"
DEFAULT_COLOR="3447003" # 蓝色
STATUS_TEXT="通知"
fi
COLOR="${COLOR:-$DEFAULT_COLOR}"
# 获取 Git 信息
REPO="${GITEA_REPO:-unknown}"
BRANCH="${GITEA_REF_NAME:-unknown}"
COMMIT_SHA="${GITEA_SHA:-unknown}"
COMMIT_SHORT="${COMMIT_SHA:0:7}"
AUTHOR="${GITEA_ACTOR:-unknown}"
WORKFLOW="${GITEA_WORKFLOW:-unknown}"
RUN_NUMBER="${GITEA_RUN_NUMBER:-unknown}"
RUN_URL="${GITEA_SERVER_URL:-}/${GITEA_REPO}/actions/runs/${GITEA_RUN_ID:-}"
# ==================== Telegram 通知 ====================
send_telegram() {
if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "⚠️ Telegram 配置缺失,跳过通知"
return 0
fi
local tg_message="${EMOJI} <b>${TITLE}</b>
<b>状态:</b> ${STATUS_TEXT}
<b>仓库:</b> ${REPO}
<b>分支:</b> ${BRANCH}
<b>提交:</b> <code>${COMMIT_SHORT}</code>
<b>作者:</b> ${AUTHOR}
<b>工作流:</b> ${WORKFLOW} #${RUN_NUMBER}
${MESSAGE}
<a href=\"${RUN_URL}\">查看详情</a>"
echo "📤 发送 Telegram 通知..."
local response
response=$(curl -s -X POST \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d "chat_id=${TELEGRAM_CHAT_ID}" \
-d "text=${tg_message}" \
-d "parse_mode=HTML" \
-d "disable_web_page_preview=true")
if echo "$response" | grep -q '"ok":true'; then
echo "✅ Telegram 通知发送成功"
else
echo "❌ Telegram 通知发送失败: $response"
return 1
fi
}
# ==================== Discord 通知 ====================
send_discord() {
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "⚠️ Discord Webhook 配置缺失,跳过通知"
return 0
fi
echo "📤 发送 Discord 通知..."
# 构建 Discord Embed JSON
local discord_payload
discord_payload=$(cat <<EOF
{
"embeds": [{
"title": "${EMOJI} ${TITLE}",
"description": "${MESSAGE}",
"color": ${COLOR},
"fields": [
{
"name": "状态",
"value": "${STATUS_TEXT}",
"inline": true
},
{
"name": "仓库",
"value": "${REPO}",
"inline": true
},
{
"name": "分支",
"value": "${BRANCH}",
"inline": true
},
{
"name": "提交",
"value": "\`${COMMIT_SHORT}\`",
"inline": true
},
{
"name": "作者",
"value": "${AUTHOR}",
"inline": true
},
{
"name": "工作流",
"value": "${WORKFLOW} #${RUN_NUMBER}",
"inline": true
}
],
"footer": {
"text": "Gitea Actions"
},
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"url": "${RUN_URL}"
}]
}
EOF
)
local response
response=$(curl -s -X POST \
"$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$discord_payload")
if [ -z "$response" ] || echo "$response" | grep -q '"id"'; then
echo "✅ Discord 通知发送成功"
else
echo "❌ Discord 通知发送失败: $response"
return 1
fi
}
# ==================== 主流程 ====================
main() {
echo "🔔 开始发送部署通知..."
echo "状态: $STATUS"
echo "标题: $TITLE"
echo "消息: $MESSAGE"
echo ""
local failed=0
# 发送 Telegram 通知
if ! send_telegram; then
failed=$((failed + 1))
fi
echo ""
# 发送 Discord 通知
if ! send_discord; then
failed=$((failed + 1))
fi
echo ""
if [ $failed -eq 0 ]; then
echo "✅ 所有通知发送完成"
else
echo "⚠️ 部分通知发送失败 ($failed 个)"
# 不退出脚本,避免影响主流程
fi
}
main