11name : Update README Activity
22
33on :
4- workflow_dispatch : {} # 手動觸發(從 UI 選分支即可)
5- # 如要定期執行可解開:
4+ workflow_dispatch : {} # 手動觸發
65 # schedule:
76 # - cron: "0 */6 * * *" # 每 6 小時跑一次
87
98permissions :
10- contents : write # 最小必要權限
9+ contents : write
1110 pull-requests : read
1211
1312jobs :
1817 - name : Checkout
1918 uses : actions/checkout@v4
2019 with :
21- # 跑在哪個分支就 checkout 那個分支(手動觸發時會用 UI 選擇)
2220 ref : ${{ github.ref_name }}
2321 persist-credentials : false
2422
25- # 產生最近活動(最近合併 PR + 最近 commits),輸出為 steps.gen.outputs.content
2623 - name : Generate recent activity
2724 id : gen
2825 uses : actions/github-script@v7
@@ -33,13 +30,11 @@ jobs:
3330 const repo = context.repo.repo;
3431 const per = 5;
3532
36- // 最近合併的 PR
3733 const prs = await github.rest.pulls.list({
3834 owner, repo, state: 'closed', per_page: 20, sort: 'updated', direction: 'desc'
3935 });
4036 const merged = prs.data.filter(p => p.merged_at).slice(0, per);
4137
42- // 最近 commits
4338 const commits = await github.rest.repos.listCommits({ owner, repo, per_page: per });
4439
4540 function d(s){ return new Date(s).toISOString().slice(0,10); }
5449 ...commitLines
5550 ].join('\n');
5651
57- core.setOutput('content', md);
52+ core.setOutput('content', md)
5853
5954 - name : Write content file
6055 run : |
6459 shell : bash
6560 run : |
6661 echo "----- REF: ${{ github.ref_name }} -----"
67- echo "----- README (first 200 lines) -----"
6862 nl -ba README.md | sed -n '1,200p' || true
69- echo "----- Grep markers (tolerant) -----"
7063 grep -En '<!--[[:space:]]*RECENT_ACTIVITY:start[[:space:]]*-->' README.md || true
7164 grep -En '<!--[[:space:]]*RECENT_ACTIVITY:end[[:space:]]*-->' README.md || true
7265
@@ -77,22 +70,16 @@ jobs:
7770 start='<!--[[:space:]]*RECENT_ACTIVITY:start[[:space:]]*-->'
7871 end='<!--[[:space:]]*RECENT_ACTIVITY:end[[:space:]]*-->'
7972 if ! grep -Eq "$start" README.md || ! grep -Eq "$end" README.md; then
80- echo "::group::README preview"; nl -ba README.md | sed -n '1,200p'; echo "::endgroup::"
81- echo "::error ::README markers not found (check lines, spaces, or code blocks)"; exit 1
73+ echo "::error ::README markers not found"; exit 1
8274 fi
8375 python3 - <<'PY'
8476import re,sys
8577start = r'<!--[ \t]*RECENT_ACTIVITY:start[ \t]*-->'
8678end = r'<!--[ \t]*RECENT_ACTIVITY:end[ \t]*-->'
87- with open("README.md","r",encoding="utf-8") as f :
88- txt = f.read()
89- with open("_activity.md","r",encoding="utf-8") as f :
90- content = f.read().rstrip()
91- if not re.search(start, txt, flags=re.S) or not re.search(end, txt, flags=re.S) :
92- print("Markers not found", file=sys.stderr); sys.exit(1)
79+ txt = open("README.md","r",encoding="utf-8").read()
80+ content = open("_activity.md","r",encoding="utf-8").read().rstrip()
9381new = re.sub(start + r'.*?' + end, start + '\n' + content + '\n' + end, txt, flags=re.S)
94- with open("README.md","w",encoding="utf-8") as f :
95- f.write(new)
82+ open("README.md","w",encoding="utf-8").write(new)
9683print("README updated between markers.")
9784PY
9885
10491 if git diff --quiet README.md; then
10592 echo "No README changes"; exit 0
10693 fi
107- git config user.name "github-actions[bot]"
94+ git config user.name "github-actions[bot]"
10895 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
10996 git add README.md _activity.md || true
11097 git commit -m "chore(readme): update recent activity [skip ci]"
0 commit comments