Files
MemoryBear/.github/workflows/release-notify-wechat.yml
Ke Sun b20971dc95 ci(wechat-notify): extract payload building logic to Python script
- Create new `.github/scripts/build_wechat_payload.py` to handle WeChat payload generation
- Replace inline Python string concatenation with dedicated script for better maintainability
- Add checkout step to access the script during workflow execution
- Simplify workflow by delegating payload construction to external script
- Improve code readability and reusability for future notification enhancements
2026-04-13 19:20:53 +08:00

101 lines
3.3 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
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 未同步
- name: Wait for ref sync
run: sleep 3
# 1⃣ 获取分支 HEAD
- name: Get HEAD
id: head
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
HEAD_SHA=$(curl -s \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/$REPO/git/ref/heads/$BASE_REF" \
| jq -r '.object.sha')
echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT
# 2⃣ 判断是否最终PR
- name: Check Latest
id: check
env:
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
HEAD_SHA: ${{ steps.head.outputs.head_sha }}
run: |
if [ "$MERGE_SHA" = "$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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMITS_URL: ${{ github.event.pull_request.commits_url }}
run: |
curl -s \
-H "Authorization: Bearer $GH_TOKEN" \
"$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
env:
DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
run: |
COMMIT_MESSAGES=$(cat commits.txt)
jq -n --arg msgs "请用中文总结以下代码提交输出3-5条面向测试人员
$COMMIT_MESSAGES" \
'{"model": "qwen-plus", "input": {"prompt": $msgs}}' > ai_payload.json
SUMMARY=$(curl -s https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d @ai_payload.json | jq -r '.output.text')
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# 5⃣ 企业微信通知Markdown
- name: Checkout for script
if: steps.check.outputs.ok == 'true'
uses: actions/checkout@v4
- name: Notify WeChat
if: steps.check.outputs.ok == 'true'
env:
WECHAT_WEBHOOK: ${{ secrets.WECHAT_WEBHOOK }}
BRANCH: ${{ github.event.pull_request.base.ref }}
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 }}
run: |
python3 .github/scripts/build_wechat_payload.py
curl -s "$WECHAT_WEBHOOK" \
-H 'Content-Type: application/json' \
-d @wechat_payload.json