-
Notifications
You must be signed in to change notification settings - Fork 7
87 lines (71 loc) · 2.97 KB
/
update-contributors.yml
File metadata and controls
87 lines (71 loc) · 2.97 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Update Contributors
on:
push:
branches:
- main
workflow_dispatch: # Allow manual trigger
permissions:
contents: write # 允许 Action 提交代码回仓库
jobs:
update-contributors:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # 需要完整的 Git 历史记录来统计作者
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Generate Contributors
run: |
python - << 'EOF'
import subprocess
import re
import os
# 1. 获取所有提交的 作者名称 和 邮箱
output = subprocess.check_output(['git', 'log', '--format=%aN|%aE']).decode('utf-8')
contributors = {}
for line in output.strip().split('\n'):
if not line: continue
name, email = line.split('|', 1)
name, email = name.strip(), email.strip().lower()
if re.search(r'(github-actions|dependabot|bot)', name, re.IGNORECASE) or 'bot@' in email:
continue
if email not in contributors:
contributors[email] = set()
contributors[email].add(name)
# 2. 逻辑处理:创始人固定 + 英文优先
final_list = []
for email, names in contributors.items():
if email == "killea@gmail.com":
continue
best_name = list(names)[0]
for n in names:
if n.isascii() and not best_name.isascii():
best_name = n
final_list.append(f"- {best_name} <{email}>")
final_list.sort(key=lambda x: x.lower())
# 3. Generate new content and compare with existing
new_content = "# Contributors\n\nThank you to the following people:\n\n"
new_content += "### Creator & Maintainer\n- Hank Wang <Killea@gmail.com>\n\n"
if final_list:
new_content += "### Project Contributors\n" + '\n'.join(final_list) + '\n'
old_content = ""
if os.path.exists("CONTRIBUTORS.md"):
with open("CONTRIBUTORS.md", "r", encoding="utf-8") as f:
old_content = f.read()
if new_content != old_content:
with open("CONTRIBUTORS.md", "w", encoding="utf-8") as f:
f.write(new_content)
print("CONTRIBUTORS.md updated.")
else:
print("No changes detected in contributors list.")
EOF
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "docs: auto-update contributors in README and CONTRIBUTORS.md"
file_pattern: "CONTRIBUTORS.md README.md"
branch: main