-
Notifications
You must be signed in to change notification settings - Fork 1
70 lines (59 loc) · 2.17 KB
/
update-readme.yml
File metadata and controls
70 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Auto Update README
on:
push:
branches:
- main
# 添加写权限
permissions:
contents: write
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
# 检查推送中的所有提交是否包含 [ptr]
- name: Check for [ptr] in commits
id: check_ptr
run: |
echo "Checking commits for [ptr] marker..."
echo "Before: ${{ github.event.before }}"
echo "After: ${{ github.sha }}"
# 获取所有推送的提交消息(包括合并提交中的所有提交)
# 使用 --first-parent 避免重复检查,使用 --all-match 确保准确性
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
# 首次推送或强制推送
COMMITS=$(git log --format=%B -1)
else
# 正常推送,获取本次push的所有提交(包括合并进来的提交)
COMMITS=$(git log --format=%B ${{ github.event.before }}..${{ github.sha }})
fi
echo "Commits:"
echo "$COMMITS"
if echo "$COMMITS" | grep -q "\[ptr\]"; then
echo "Found [ptr] marker!"
echo "has_ptr=true" >> $GITHUB_OUTPUT
else
echo "No [ptr] marker found"
echo "has_ptr=false" >> $GITHUB_OUTPUT
fi
- name: Update README
if: steps.check_ptr.outputs.has_ptr == 'true'
env:
COMMIT_SHA: ${{ github.sha }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
BEFORE_SHA: ${{ github.event.before }}
run: node scripts/update-readme.mjs
- name: Commit changes
if: steps.check_ptr.outputs.has_ptr == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "docs: auto update README [skip ci]"
file_pattern: README.md