${TAG}"$'\n'"🔗 查看 Release"
+
+ # 发送 Telegram 消息(使用 jq 转义 JSON)
+ curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
+ -H "Content-Type: application/json" \
+ -d "$(jq -n \
+ --arg chat_id "$TELEGRAM_CHAT_ID" \
+ --arg text "$MESSAGE" \
+ '{chat_id: $chat_id, text: $text, parse_mode: "HTML", disable_web_page_preview: false}')" > /tmp/telegram_response.json
+
+ # 检查发送结果
+ if [ $? -eq 0 ]; then
+ RESPONSE=$(cat /tmp/telegram_response.json)
+ if echo "$RESPONSE" | grep -q '"ok":true'; then
+ echo "✅ Telegram 通知发送成功"
+ else
+ echo "❌ Telegram 通知发送失败: $RESPONSE"
+ # 通知失败不应该导致整个 job 失败
+ exit 0
+ fi
+ else
+ echo "❌ 发送 Telegram 消息时发生错误"
+ # 通知失败不应该导致整个 job 失败
+ exit 0
+ fi
+
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
@@ -65,3 +108,49 @@ jobs:
GITHUB_REPO_URL=https://github.com/WrBug/PolyHermes
cache-from: type=registry,ref=wrbug/polyhermes:latest
cache-to: type=inline
+
+ - name: Send Telegram notification
+ env:
+ TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
+ TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
+ run: |
+ # 检查必要的环境变量
+ if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
+ echo "⚠️ Telegram Bot Token 或 Chat ID 未配置,跳过通知"
+ exit 0
+ fi
+
+ # 获取构建信息
+ VERSION="${{ steps.extract_version.outputs.VERSION }}"
+ TAG="${{ steps.extract_version.outputs.TAG }}"
+ RELEASE_NAME="${{ github.event.release.name }}"
+ RELEASE_URL="${{ github.event.release.html_url }}"
+ REPO_NAME="${{ github.repository }}"
+
+ # 构建消息内容(仅包含关键信息)
+ DEPLOY_DOC_URL="https://github.com/WrBug/PolyHermes/blob/main/docs/zh/DEPLOYMENT.md"
+ MESSAGE="✅ Docker 镜像构建成功"$'\n'$'\n'"📦 版本: ${VERSION}"$'\n'"🏷️ Tag: ${TAG}"$'\n'"🔗 查看 Release"$'\n'"📚 Docker 部署文档"
+
+ # 发送 Telegram 消息(使用 jq 转义 JSON)
+ curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
+ -H "Content-Type: application/json" \
+ -d "$(jq -n \
+ --arg chat_id "$TELEGRAM_CHAT_ID" \
+ --arg text "$MESSAGE" \
+ '{chat_id: $chat_id, text: $text, parse_mode: "HTML", disable_web_page_preview: false}')" > /tmp/telegram_response.json
+
+ # 检查发送结果
+ if [ $? -eq 0 ]; then
+ RESPONSE=$(cat /tmp/telegram_response.json)
+ if echo "$RESPONSE" | grep -q '"ok":true'; then
+ echo "✅ Telegram 通知发送成功"
+ else
+ echo "❌ Telegram 通知发送失败: $RESPONSE"
+ # 构建成功,通知失败不应该导致整个 job 失败
+ exit 0
+ fi
+ else
+ echo "❌ 发送 Telegram 消息时发生错误"
+ # 构建成功,通知失败不应该导致整个 job 失败
+ exit 0
+ fi
\ No newline at end of file
diff --git a/.github/workflows/telegram-notify.yml b/.github/workflows/telegram-notify.yml
new file mode 100644
index 0000000..7ae205c
--- /dev/null
+++ b/.github/workflows/telegram-notify.yml
@@ -0,0 +1,103 @@
+name: Telegram Notification on PR Merge
+
+on:
+ pull_request:
+ types:
+ - closed # 当 PR 被关闭(合并或关闭)时触发
+
+jobs:
+ notify:
+ runs-on: ubuntu-latest
+
+ # 只在 PR 被合并到 main 分支时执行
+ if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Get PR details
+ id: pr_details
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ PR_NUMBER="${{ github.event.pull_request.number }}"
+ REPO="${{ github.repository }}"
+
+ # 获取 PR 详细信息
+ PR_RESPONSE=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
+ -H "Accept: application/vnd.github.v3+json" \
+ "https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}")
+
+ # 获取 PR 变更的文件列表
+ FILES_RESPONSE=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
+ -H "Accept: application/vnd.github.v3+json" \
+ "https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/files")
+
+ # 提取 PR 描述(body),保留换行,限制长度
+ PR_BODY=$(echo "$PR_RESPONSE" | jq -r '.body // ""')
+ if [ ${#PR_BODY} -gt 500 ]; then
+ PR_BODY="${PR_BODY:0:500}..."
+ fi
+
+ # 保存到输出变量(使用 base64 编码避免特殊字符问题)
+ echo "pr_body<