diff --git a/.github/workflows/release-notify-wechat.yml b/.github/workflows/release-notify-wechat.yml index d8f4e5aa..bc67518b 100644 --- a/.github/workflows/release-notify-wechat.yml +++ b/.github/workflows/release-notify-wechat.yml @@ -35,20 +35,52 @@ jobs: echo "ok=false" >> $GITHUB_OUTPUT fi - # 3️⃣ 获取 commits - - name: Get Commits + # 3️⃣ 尝试从 PR body 提取 Sourcery 摘要 + - name: Extract Sourcery Summary if: steps.check.outputs.ok == 'true' - id: commits + id: sourcery + env: + PR_BODY: ${{ github.event.pull_request.body }} + run: | + python3 << 'PYEOF' + import os, re + + body = os.environ.get("PR_BODY", "") or "" + match = re.search( + r"## Summary by Sourcery\s*\n(.*?)(?=\n## |\Z)", + body, + re.DOTALL + ) + + if match: + summary = match.group(1).strip() + found = "true" + else: + summary = "" + found = "false" + + with open("sourcery_summary.txt", "w", encoding="utf-8") as f: + f.write(summary) + + with open(os.environ["GITHUB_OUTPUT"], "a") as gh: + gh.write(f"found={found}\n") + gh.write("summary< commits.txt - # 4️⃣ 阿里 AI 总结(通义千问) - - name: AI Summary (Qwen) - if: steps.check.outputs.ok == 'true' - id: ai + - name: AI Summary (Qwen Fallback) + if: steps.check.outputs.ok == 'true' && steps.sourcery.outputs.found == 'false' + id: qwen env: DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }} run: | @@ -56,34 +88,30 @@ jobs: import json, os, urllib.request with open("commits.txt", "r") as f: - commits = f.read().strip() + commits = f.read().strip() prompt = "请用中文总结以下代码提交,输出3-5条要点,面向测试人员。直接输出编号列表,不要输出标题或前言:\n" + commits payload = {"model": "qwen-plus", "input": {"prompt": prompt}} data = json.dumps(payload, ensure_ascii=False).encode("utf-8") req = urllib.request.Request( - "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation", - data=data, - headers={ - "Authorization": "Bearer " + os.environ["DASHSCOPE_API_KEY"], - "Content-Type": "application/json" - } + "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation", + data=data, + headers={ + "Authorization": "Bearer " + os.environ["DASHSCOPE_API_KEY"], + "Content-Type": "application/json" + } ) resp = urllib.request.urlopen(req) result = json.loads(resp.read().decode()) summary = result.get("output", {}).get("text", "AI 摘要生成失败") - print(summary) - with open("ai_summary.txt", "w", encoding="utf-8") as f: - f.write(summary) + with open(os.environ["GITHUB_OUTPUT"], "a") as gh: + gh.write("summary<> $GITHUB_OUTPUT - echo "$SUMMARY" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - # 5️⃣ 企业微信通知(Markdown) - name: Notify WeChat if: steps.check.outputs.ok == 'true' @@ -93,17 +121,27 @@ jobs: AUTHOR: ${{ github.event.pull_request.user.login }} PR_TITLE: ${{ github.event.pull_request.title }} PR_URL: ${{ github.event.pull_request.html_url }} - AI_SUMMARY: ${{ steps.ai.outputs.summary }} + SOURCERY_FOUND: ${{ steps.sourcery.outputs.found }} + SOURCERY_SUMMARY: ${{ steps.sourcery.outputs.summary }} + QWEN_SUMMARY: ${{ steps.qwen.outputs.summary }} run: | python3 << 'PYEOF' import json, os, urllib.request + + if os.environ.get("SOURCERY_FOUND") == "true": + label = "Summary by Sourcery" + summary = os.environ.get("SOURCERY_SUMMARY", "") + else: + label = "AI变更摘要" + summary = os.environ.get("QWEN_SUMMARY", "AI 摘要生成失败") + content = ( "## 🚀 Release 发布通知\n" "> 📦 **分支**: " + os.environ["BRANCH"] + "\n" "> 👤 **提交人**: " + os.environ["AUTHOR"] + "\n" "> 📝 **标题**: " + os.environ["PR_TITLE"] + "\n\n" - "### 🧠 AI变更摘要\n" + - os.environ["AI_SUMMARY"] + "\n\n" + "### 🧠 " + label + "\n" + + summary + "\n\n" "---\n" "🔗 [查看PR详情](" + os.environ["PR_URL"] + ")" )