Repository navigation
118 lines (101 loc) · 4.29 KB
/
Copy pathupdate-readme.yml
File metadata and controls
118 lines (101 loc) · 4.29 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Update Profile README
on:
schedule:
- cron: '0 2 * * *' # 每天 10:00(UTC+8)
workflow_dispatch: {}
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install requests
- name: Update README sections
run: |
python - <<'PY'
import requests, os, re
user = 'ljxpython'
# 定义代表性项目列表
featured_repos = [
{'name': 'agent-platform', 'desc': '通用 AI 智能体平台工作区(平台控制面 + LangGraph 运行时)'},
{'name': 'locust_framework', 'desc': '基础压测框架'},
{'name': 'pytest_framework', 'desc': '自动化测试框架'},
{'name': 'test_platform', 'desc': '测试开发平台(前端 TS)'},
{'name': 'flask_platform_srv', 'desc': '测试平台后端'},
{'name': 'test_engineer', 'desc': '测试开发知识总结'}
]
# 1. 获取最近活动的仓库
repos = requests.get(
f'https://api.github.com/users/{user}/repos',
params={'per_page':100, 'sort':'updated'}
).json()
# 生成最近动态内容
activity_items = []
for r in sorted(repos, key=lambda x: x.get('pushed_at') or '', reverse=True)[:5]:
name = r['name']
url = r['html_url']
desc = r.get('description') or ''
activity_items.append(f'- [{name}]({url}) — {desc}')
activity_block = '\n'.join(activity_items) if activity_items else '- (暂无动态)'
# 2. 更新代表性项目的star数量
featured_items = []
for repo in featured_repos:
repo_name = repo['name']
desc = repo['desc']
try:
api_url = f'https://api.github.com/repos/{user}/{repo_name}'
response = requests.get(api_url)
if response.status_code == 200:
repo_data = response.json()
stars = repo_data.get('stargazers_count', 0)
url = repo_data.get('html_url', f'https://github.com/{user}/{repo_name}')
featured_items.append(f'- [{repo_name}]({url}) — {desc}({stars}★)')
else:
# 如果API失败,保持原有格式
featured_items.append(f'- [{repo_name}](https://github.com/{user}/{repo_name}) — {desc}(?★)')
except Exception as e:
featured_items.append(f'- [{repo_name}](https://github.com/{user}/{repo_name}) — {desc}(?★)')
featured_block = '\n'.join(featured_items)
# 3. 更新README文件
path = 'README.md'
with open(path, 'r', encoding='utf-8') as f:
content = f.read()
# 更新最近动态部分
content = re.sub(
r'<!--START_SECTION:activity-->[\s\S]*<!--END_SECTION:activity-->',
f'<!--START_SECTION:activity-->\n{activity_block}\n<!--END_SECTION:activity-->',
content,
)
# 更新代表性项目部分
content = re.sub(
r'(### 🌟 代表性项目\n)[\s\S]*?(\n\n> 想要更快了解项目)',
f'\\1{featured_block}\\2',
content,
)
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
print(f'✅ 活动动态更新完成')
print(f'✅ 代表性项目星标更新完成')
PY
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: update profile activity and project stars"
git push
fi