From 7af1bdbf4c16b64faac6bc602ded12391fbdb600 Mon Sep 17 00:00:00 2001 From: shaw Date: Sat, 27 Dec 2025 15:55:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20workflow=E5=A2=9E=E5=8A=A0TG=E9=A2=91?= =?UTF-8?q?=E9=81=93=E6=9B=B4=E6=96=B0=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6a5c09b..40359ced 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -143,3 +143,56 @@ jobs: repository: ${{ secrets.DOCKERHUB_USERNAME }}/sub2api short-description: "Sub2API - AI API Gateway Platform" readme-filepath: ./deploy/DOCKER.md + + # Send Telegram notification + - name: Send Telegram Notification + if: ${{ secrets.TELEGRAM_BOT_TOKEN != '' && secrets.TELEGRAM_CHAT_ID != '' }} + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + continue-on-error: true + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + VERSION=${TAG_NAME#v} + REPO="${{ github.repository }}" + DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api" + + # 获取 tag message 内容 + TAG_MESSAGE='${{ steps.tag_message.outputs.message }}' + + # 限制消息长度(Telegram 消息限制 4096 字符,预留空间给头尾固定内容) + if [ ${#TAG_MESSAGE} -gt 3500 ]; then + TAG_MESSAGE="${TAG_MESSAGE:0:3500}..." + fi + + # 构建消息内容 + MESSAGE="🚀 *Sub2API 新版本发布!*"$'\n'$'\n' + MESSAGE+="📦 版本号: \`${VERSION}\`"$'\n'$'\n' + + # 添加更新内容 + if [ -n "$TAG_MESSAGE" ]; then + MESSAGE+="${TAG_MESSAGE}"$'\n'$'\n' + fi + + MESSAGE+="🐳 *Docker 部署:*"$'\n' + MESSAGE+="\`\`\`bash"$'\n' + MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n' + MESSAGE+="docker pull ${DOCKER_IMAGE}:latest"$'\n' + MESSAGE+="\`\`\`"$'\n'$'\n' + MESSAGE+="🔗 *相关链接:*"$'\n' + MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n' + MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'$'\n' + MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}" + + # 发送消息 + 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: "Markdown", + disable_web_page_preview: true + }')"