-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (56 loc) · 2.03 KB
/
update-materials.yml
File metadata and controls
64 lines (56 loc) · 2.03 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
name: Daily Material Update
on:
schedule:
# 每天北京时间早上 8 点运行(UTC 0:00)
- cron: '0 0 * * *'
workflow_dispatch: # 允许手动触发
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # 需要完整历史来检查最后人类提交时间
- name: Check repo activity
id: activity
run: |
# 获取最后一次非 bot 提交的时间戳
LAST_HUMAN_COMMIT=$(git log --format='%ct' --invert-grep --author='github-actions\[bot\]' -1 2>/dev/null || echo "")
if [ -z "$LAST_HUMAN_COMMIT" ]; then
echo "skip=false" >> $GITHUB_OUTPUT
echo "未找到提交记录,继续运行"
exit 0
fi
NOW=$(date +%s)
DAYS=$(( (NOW - LAST_HUMAN_COMMIT) / 86400 ))
echo "距离最后一次人类提交: ${DAYS} 天"
if [ "$DAYS" -gt 300 ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "超过 300 天无人类提交,跳过本次更新"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Set up Python
if: steps.activity.outputs.skip != 'true'
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
if: steps.activity.outputs.skip != 'true'
run: pip install -r requirements.txt
- name: Run updater
if: steps.activity.outputs.skip != 'true'
env:
HELIO_TOKEN: ${{ secrets.HELIO_TOKEN }}
run: python helio_material_updater.py
- name: Commit and push
if: steps.activity.outputs.skip != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git diff --cached --quiet || git commit -m "chore: update materials data $(date -u +%Y-%m-%d)"
git push