@@ -3,7 +3,7 @@ name: Scheduled Update of Release Notes
33on :
44  workflow_dispatch :
55  schedule :
6-     - cron : " 0 2 * * 3"   #  每周三UTC时间2点运行一次,即北京时间10点 
6+     - cron : " 0 2 * * 3" #  Runs every Wednesday at 2:00 UTC (10:00 Beijing Time) 
77
88permissions :
99  contents : write 
@@ -12,125 +12,76 @@ permissions:
1212jobs :
1313  run-script :
1414    runs-on : ubuntu-latest 
15+     timeout-minutes : 15 
16+     env :
17+       RELEASE_NOTES_FILE : ${{ secrets.RELEASE_NOTES_FILE }} 
1518
1619    steps :
1720      - name : Checkout repo 
18-         uses : actions/checkout@v3  
21+         uses : actions/checkout@v4  
1922        with :
2023          fetch-depth : 0 
24+           ref : main 
2125
2226      - name : Setup Python 
23-         uses : actions/setup-python@v4  
27+         uses : actions/setup-python@v5  
2428        with :
25-           python-version : 3.9 
29+           python-version : " 3.9" 
30+           cache : pip 
2631
2732      - name : Install dependencies 
28-         run : pip install requests pandas pyyaml jq 
33+         run : pip install requests pandas pyyaml jq mdformat  
2934
3035      - name : Prepare branch 
3136        id : prepare_branch 
3237        run : | 
33-           DATE=$(date +%Y%m%d) 
34-           BRANCH="update-rel-notes-$DATE" 
35-           git fetch origin "$BRANCH" || true  
36- 
37-           if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then 
38-             git checkout -b "$BRANCH" "origin/$BRANCH" 
39-           else 
40-             git checkout -b "$BRANCH" 
41-           fi 
38+           BRANCH="update-rel-notes-${{ github.run_id }}" 
39+           git switch -c "$BRANCH" 
4240          echo "branch=$BRANCH" >> $GITHUB_OUTPUT 
4341
44- name : Run auto-release-notes.py script 
42+ name : Run Script 
43+         id : run_script 
4544        env :
4645          FEISHU_SECRET : ${{ secrets.FEISHU_SECRET }} 
47-           RELEASE_NOTES_FILE : ${{ secrets.RELEASE_NOTES_FILE }} 
4846        run : | 
47+           set -e 
4948          IFS=',' read -r APP_ID APP_SECRET URL <<< "$FEISHU_SECRET" 
50-           export APP_ID APP_SECRET URL 
51-           export FILENAME="${RELEASE_NOTES_FILE}" 
49+           export APP_ID APP_SECRET URL FILENAME="$RELEASE_NOTES_FILE" 
5250          python scripts/auto-release-notes.py 
53-            
54- name : Check if release notes file changed and commit  
51+ 
52+ name : Check Changes  
5553        id : check_changes 
56-         env :
57-           RELEASE_NOTES_FILE : ${{ secrets.RELEASE_NOTES_FILE }} 
5854        run : | 
59-           echo "File to check: $RELEASE_NOTES_FILE" 
60-            
61-           # Show git status for context 
62-           echo "Current git status:" 
63-           git status --porcelain 
64-            
65-           # Check if file has changes compared to origin/main 
55+           if [ ! -f "$RELEASE_NOTES_FILE" ]; then 
56+             echo "❌ Release notes file not found: $RELEASE_NOTES_FILE" 
57+             exit 1 
58+           fi 
6659          if git diff --quiet origin/main -- "$RELEASE_NOTES_FILE"; then 
67-             echo "No changes detected in release notes file" 
68-             echo "File content is identical to origin/main" 
6960            echo "files_are_same=true" >> $GITHUB_OUTPUT 
7061          else 
71-             echo "Changes detected in release notes file!" 
72-             echo "Showing diff summary:" 
73-             git diff --stat origin/main -- "$RELEASE_NOTES_FILE" 
74-             echo "" 
75-             echo "Detailed changes:" 
76-             git diff origin/main -- "$RELEASE_NOTES_FILE" | head -50 
7762            echo "files_are_same=false" >> $GITHUB_OUTPUT 
63+             git diff --stat origin/main -- "$RELEASE_NOTES_FILE" 
7864          fi 
79-            
80-           echo "Check completed. files_are_same=$(git diff --quiet origin/main -- "$RELEASE_NOTES_FILE" && echo 'true' || echo 'false')" 
81- 
82-       - name : Skip commit - No changes detected 
83-         if : steps.check_changes.outputs.files_are_same == 'true' 
84-         run : | 
85-           echo "Skipping commit and PR creation - no changes detected" 
8665
87- name : Commit and push release notes update 
66+ name : Commit and Push If Changes Exist 
67+         id : commit_and_push 
8868        if : steps.check_changes.outputs.files_are_same == 'false' 
8969        uses : stefanzweifel/git-auto-commit-action@v5 
9070        with :
9171          commit_message : Update rel-notes.md via automation 
9272          file_pattern : ${{ secrets.RELEASE_NOTES_FILE }} 
73+           skip_dirty_check : true 
9374          push_options : --set-upstream 
9475          branch : ${{ steps.prepare_branch.outputs.branch }} 
95-         env :
96-           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
9776
98-       #  使用这个有问题,会覆盖分支且不提交pr
99-       #  - name: Create Pull Request
100-       #    if: steps.check_changes.outputs.files_are_same == 'false'
101-       #    uses: peter-evans/create-pull-request@v7
102-       #    with:
103-       #      token: ${{ secrets.GITHUB_TOKEN }}
104-       #      title: "Automated update of rel-notes.md"
105-       #      body: "This PR updates rel-notes.md automatically."
106-       #      base: main
107-       #      branch: ${{ steps.prepare_branch.outputs.branch }}  # 你新建的分支名
108-       #      draft: true  # 以草稿状态创建,避免自动合并
109-       
110-       - name : Skip PR creation - No changes detected 
111-         if : steps.check_changes.outputs.files_are_same == 'true' 
112-         run : | 
113-           echo "Skipping PR creation - no changes detected" 
114- 
115- name : Create Pull Request via API 
116-         if : steps.check_changes.outputs.files_are_same == 'false' 
77+       - name : Create Pull Request If Push Succeeded 
78+         if : steps.commit_and_push.outcome == 'success' 
11779        env :
11880          GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
11981        run : | 
120-           echo "Creating Pull Request for branch: ${{ steps.prepare_branch.outputs.branch }}" 
121-            
122-           PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ 
123-             -H "Accept: application/vnd.github+json" \ 
124-             https://api.github.com/repos/${{ github.repository }}/pulls \ 
125-             -d @- << EOF 
126-           { 
127-             "title": "Automated update of rel-notes.md", 
128-             "head": "${{ steps.prepare_branch.outputs.branch }}", 
129-             "base": "main", 
130-             "body": "This PR updates rel-notes.md automatically." 
131-           } 
132-           EOF 
133-           ) 
134-            
135-           echo "Pull Request Response:" 
136-           echo "$PR_RESPONSE" | jq -r '"PR #" + (.number | tostring) + " created successfully: " + .html_url' 2>/dev/null || echo "$PR_RESPONSE" 
82+           gh pr create \ 
83+             --title "Automated update of rel-notes.md" \ 
84+             --body "This PR updates rel-notes.md automatically." \ 
85+             --base main \ 
86+             --head "${{ steps.prepare_branch.outputs.branch }}" \ 
87+             --repo "${{ github.repository }}" 
0 commit comments