name: Release Notify Workflow on: pull_request: types: [closed] jobs: notify: if: > github.event.pull_request.merged == true && startsWith(github.event.pull_request.base.ref, 'release') runs-on: ubuntu-latest steps: # 防止 GitHub HEAD 未同步 - run: sleep 3 # 1️⃣ 获取分支 HEAD - name: Get HEAD id: head run: | HEAD_SHA=$(curl -s \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${{ github.event.pull_request.base.ref }} \ | jq -r '.object.sha') echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT # 2️⃣ 判断是否最终PR - name: Check Latest id: check run: | if [ "${{ github.event.pull_request.merge_commit_sha }}" = "${{ steps.head.outputs.head_sha }}" ]; then echo "ok=true" >> $GITHUB_OUTPUT else echo "ok=false" >> $GITHUB_OUTPUT fi # 3️⃣ 获取 commits - name: Get Commits if: steps.check.outputs.ok == 'true' id: commits run: | curl -s \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ ${{ github.event.pull_request.commits_url }} \ | jq -r '.[].commit.message' | head -n 20 > commits.txt # 4️⃣ 阿里 AI 总结(通义千问) - name: AI Summary (Qwen) if: steps.check.outputs.ok == 'true' id: ai run: | CONTENT=$(cat commits.txt | sed ':a;N;$!ba;s/\n/\\n/g') SUMMARY=$(curl -s https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation \ -H "Authorization: Bearer ${{ secrets.DASHSCOPE_API_KEY }}" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"qwen-plus\", \"input\": { \"prompt\": \"请用中文总结以下代码提交,输出3-5条,面向测试人员:\\n$CONTENT\" } }" | jq -r '.output.text') echo "summary<> $GITHUB_OUTPUT echo "$SUMMARY" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT # 5️⃣ 企业微信通知(Markdown) - name: Notify WeChat if: steps.check.outputs.ok == 'true' run: | curl '${{ secrets.WECHAT_WEBHOOK }}' \ -H 'Content-Type: application/json' \ -d "{ \"msgtype\": \"markdown\", \"markdown\": { \"content\": \"## 🚀 Release 发布通知\n> 📦 **分支**: ${{ github.event.pull_request.base.ref }}\n> 👤 **提交人**: ${{ github.event.pull_request.user.login }}\n> 📝 **标题**: ${{ github.event.pull_request.title }}\n\n### 🧠 AI变更摘要\n${{ steps.ai.outputs.summary }}\n\n---\n🔗 [查看PR详情](${{ github.event.pull_request.html_url }})\" } }"