-
Notifications
You must be signed in to change notification settings - Fork 64
147 lines (127 loc) · 4.76 KB
/
update-candidates.yml
File metadata and controls
147 lines (127 loc) · 4.76 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Update Candidates Pool
on:
schedule:
- cron: '0 19 * * 0' # 每周日凌晨 3 点(UTC+8)
workflow_dispatch:
inputs:
batch_size:
description: '验证批次大小'
required: false
default: '200'
concurrency:
description: '验证并发数'
required: false
default: '20'
timeout:
description: '验证超时时间(秒)'
required: false
default: '10'
jobs:
update-candidates:
runs-on: ubuntu-latest
timeout-minutes: 60
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: Update candidates pool
id: update
run: |
set +e
# 读取原始书源
echo "读取原始书源..."
RAW_COUNT=$(python3 -c "import json; print(len(json.load(open('sources/legado/pool/raw.json'))))" 2>&1)
if [ $? -ne 0 ]; then
echo "::error::统计原始书源失败: $RAW_COUNT"
RAW_COUNT="0"
fi
echo "原始书源数量: $RAW_COUNT"
# 快速过滤(使用独立脚本)
echo "执行快速过滤..."
python3 scripts/quick_filter.py \
--input sources/legado/pool/raw.json \
--output sources/legado/temp/filtered.json
FILTER_EXIT_CODE=$?
if [ $FILTER_EXIT_CODE -ne 0 ]; then
echo "::error::快速过滤失败,退出码: $FILTER_EXIT_CODE"
echo "status=failed" >> $GITHUB_OUTPUT
exit $FILTER_EXIT_CODE
fi
# 分批验证
echo "执行分批验证..."
python3 scripts/batch_validator.py \
--input sources/legado/temp/filtered.json \
--output-valid sources/legado/pool/candidates.json \
--output-invalid sources/legado/pool/invalid.json \
--batch-size ${{ github.event.inputs.batch_size || '200' }} \
--concurrency ${{ github.event.inputs.concurrency || '20' }} \
--timeout ${{ github.event.inputs.timeout || '10' }} \
--checkpoint-dir sources/legado/temp/checkpoints
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -eq 0 ]; then
echo "status=success" >> $GITHUB_OUTPUT
# 统计结果
CANDIDATES_COUNT=$(python3 -c "import json; print(len(json.load(open('sources/legado/pool/candidates.json'))))" 2>&1)
if [ $? -ne 0 ]; then
echo "::warning::统计候选书源失败: $CANDIDATES_COUNT"
CANDIDATES_COUNT="0"
fi
echo "candidates_count=$CANDIDATES_COUNT" >> $GITHUB_OUTPUT
else
echo "status=failed" >> $GITHUB_OUTPUT
exit $EXIT_CODE
fi
- name: Commit changes
if: steps.update.outputs.status == 'success'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add sources/legado/pool/candidates.json
git add sources/legado/pool/invalid.json
git commit -m "chore: 更新候选池 - 当前 ${{ steps.update.outputs.candidates_count }} 个候选书源" || echo "No changes to commit"
- name: Push changes
if: steps.update.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: update-candidates-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/filtered.json || true
rm -rf sources/legado/temp/checkpoints/*.json || true