-
Notifications
You must be signed in to change notification settings - Fork 64
120 lines (105 loc) · 3.73 KB
/
initialize.yml
File metadata and controls
120 lines (105 loc) · 3.73 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
119
120
name: Initialize Sources
on:
workflow_dispatch:
inputs:
target:
description: '目标书源数量'
required: false
default: '1000'
batch_size:
description: '验证批次大小'
required: false
default: '200'
concurrency:
description: '验证并发数'
required: false
default: '20'
timeout:
description: '验证超时时间(秒)'
required: false
default: '10'
jobs:
initialize:
runs-on: ubuntu-latest
timeout-minutes: 180 # 3 小时超时
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r scripts/requirements.txt
- name: Run initialization
id: initialize
run: |
set +e
python3 scripts/initialize_sources.py \
--base-dir sources/legado \
--target ${{ github.event.inputs.target || '1000' }} \
--batch-size ${{ github.event.inputs.batch_size || '200' }} \
--concurrency ${{ github.event.inputs.concurrency || '20' }} \
--timeout ${{ github.event.inputs.timeout || '10' }}
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -eq 0 ]; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=failed" >> $GITHUB_OUTPUT
exit $EXIT_CODE
fi
- name: Commit changes
if: steps.initialize.outputs.status == 'success'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# 更新 README 和站点数据
python3 scripts/update_sources.py --base-dir .
# 核心文件必须存在
git add sources/legado/main/full.json
# 可选文件容错
git add sources/legado/main/backups/ 2>/dev/null || true
git add sources/legado/pool/candidates.json 2>/dev/null || true
git add sources/legado/pool/invalid.json 2>/dev/null || true
git add README.md docs/index.html STATS.md 2>/dev/null || true
git commit -m "feat: 初始化书源系统 - 从 16,724 个筛选出 ${{ github.event.inputs.target || '1000' }} 个高质量书源" || echo "No changes to commit"
- name: Push changes
if: steps.initialize.outputs.status == 'success'
run: |
set +e
for i in 1 2 3; do
git push && break || {
echo "Push attempt $i failed, retrying in $((i * 5)) seconds..."
sleep $((i * 5))
}
done
set -e
- name: Upload artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: initialization-logs
path: |
sources/legado/temp/checkpoints/
retention-days: 7
- name: Create issue on failure
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '初始化流程失败',
body: `初始化流程在 ${new Date().toISOString()} 失败。\n\n请检查工作流日志:${context.payload.repository.html_url}/actions/runs/${context.runId}`,
labels: ['bug', 'automation']
})
- name: Cleanup
if: ${{ !cancelled() }}
run: |
rm -rf sources/legado/temp/checkpoints/*.json || true