Repository navigation
183 lines (157 loc) · 7.46 KB
/
Copy pathanalyze.yml
File metadata and controls
183 lines (157 loc) · 7.46 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Submission-Triggered Analyze (via PR)
# 与 auto-analyze.yml 的关系:
# - auto-analyze.yml 服务「定时调度 / 维护者 /analyze 评论」,结果直接 push main
# - 本 workflow 服务「外部用户站点 submit 提交」,结果走 PR 审核后合并
# 两条流并存,触发条件不重叠
on:
issues:
types: [opened, labeled]
permissions:
contents: write
issues: write
pull-requests: write
# 按 issue 编号分组:同一 issue 的重复触发(opened+labeled 双发、或手动重打标签)合并成一次,
# 取消旧 run 只留最新;不同 issue 各跑各的(各自 analyze/<slug> 分支,互不干扰)。
concurrency:
group: analyze-issue-${{ github.event.issue.number }}
cancel-in-progress: true
jobs:
analyze:
# 按事件类型精确 gate,避免 opened 与 labeled 对同一 issue 双触发:
# - opened:带 analyze-request 标签,或标题以 [Analyze] 开头(无标签兜底)
# - labeled:只认新加的那枚标签恰为 analyze-request(加别的标签不打扰运行中的分析)
if: >-
(github.event.action == 'opened'
&& (contains(github.event.issue.labels.*.name, 'analyze-request')
|| startsWith(github.event.issue.title, '[Analyze]')))
|| (github.event.action == 'labeled'
&& github.event.label.name == 'analyze-request')
runs-on: ubuntu-latest
timeout-minutes: 60
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
MINIMAX_BASE_URL: ${{ secrets.MINIMAX_BASE_URL }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Dump issue body to file
env:
BODY: ${{ github.event.issue.body }}
run: |
mkdir -p /tmp/runner
printf '%s' "$BODY" > /tmp/runner/issue_body.md
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: requirements-ci.txt
- name: Install Python deps
run: pip install -r requirements-ci.txt
- name: Validate submission
id: validate
run: python3 src/scripts/validate_submission.py /tmp/runner/issue_body.md
- name: Reject & close on validation failure
if: failure() && steps.validate.outcome == 'failure'
run: |
MSG="${{ steps.validate.outputs.comment || '❌ 校验失败' }}"
gh issue comment "$ISSUE_NUMBER" --body "$MSG"
gh issue edit "$ISSUE_NUMBER" --add-label "analyze-failed" --remove-label "analyze-request" || true
gh issue close "$ISSUE_NUMBER"
exit 1
- name: Comment in-progress
run: gh issue comment "$ISSUE_NUMBER" --body "🔧 校验通过,开始分析 \`${{ steps.validate.outputs.repo_url }}\`,约 10-30 分钟。"
- uses: actions/setup-node@v4
with: { node-version: "20" }
# 缓存用户级 tokei 二进制;key 含 setup_ci_env.sh hash → TOKEI_VERSION 改即失效
- name: Cache tokei binary
uses: actions/cache@v4
with:
path: ~/.local/bin/tokei
key: tokei-${{ runner.os }}-${{ hashFiles('src/scripts/setup_ci_env.sh') }}
# 缓存用户级 npm 全局目录(含 @anthropic-ai/claude-code);同上 key 策略
- name: Cache npm global (claude-code CLI)
uses: actions/cache@v4
with:
path: ~/.npm-global
key: npm-global-${{ runner.os }}-${{ hashFiles('src/scripts/setup_ci_env.sh') }}
- name: Bootstrap CI env (gh / jq / tokei / claude / vendored skills)
run: bash src/scripts/setup_ci_env.sh
- name: Run /repo-miner (via run_skill.sh, dual-backend)
env:
REPO_URL: ${{ steps.validate.outputs.repo_url }}
REPORT_PATH: ${{ steps.validate.outputs.report_path }}
run: |
PROMPT="/repo-miner $REPO_URL ,中间过程文件输出到 tmp/ ,最终分析报告输出到 $REPORT_PATH"
bash src/scripts/run_skill.sh "$PROMPT" --timeout 1800 --log "tmp/logs/repo-miner-$ISSUE_NUMBER.log"
- name: Verify report file
id: verify
env:
REPORT_PATH: ${{ steps.validate.outputs.report_path }}
run: |
if [ ! -s "$REPORT_PATH" ]; then
echo "::error::分析跑完但未产出 $REPORT_PATH"
exit 1
fi
echo "lines=$(wc -l < "$REPORT_PATH")" >> "$GITHUB_OUTPUT"
- name: Prefix report title(统一加「GitHub推荐:」前缀)
# 确定性后处理:给新产报告的 H1 加前缀(幂等)。
# 必须在 build_reports_index 之前,reports.json 索引的 title 才会带上前缀。
# 只改本次新产报告,不动历史。
env:
REPORT_PATH: ${{ steps.validate.outputs.report_path }}
run: python3 src/scripts/prefix_report_title.py "$REPORT_PATH"
- name: Refresh site metadata (DB-backed)
# 阶段 1-4:reports + tags + starred + trending + publish_history 主写 DB
# JSON/YAML 由 export-json dump;publish_history.jsonl 是 publish 历史的 SoR
run: |
python3 src/scripts/init_db.py init
python3 src/scripts/init_db.py seed-publish
python3 src/scripts/build_reports_index.py
python3 src/scripts/extract_tags.py
python3 src/scripts/parse_starred.py
python3 src/scripts/seed_trending.py
python3 src/scripts/init_db.py export-json
- name: Open PR
if: success()
uses: peter-evans/create-pull-request@v6
with:
# org 策略禁用了 GITHUB_TOKEN 建 PR,这里改用 PAT(fine-grained:Contents+Pull requests=write)
# 缺失时回退到 GITHUB_TOKEN(仍会被 org 策略挡住,但不至于让表达式报错)
token: ${{ secrets.PAT_PR || secrets.GITHUB_TOKEN }}
branch: analyze/${{ steps.validate.outputs.slug }}
delete-branch: true
base: main
title: "Add report: ${{ steps.validate.outputs.owner }}/${{ steps.validate.outputs.repo }}"
body: |
Auto-generated from issue #${{ github.event.issue.number }}.
- Repo: ${{ steps.validate.outputs.repo_url }}
- Report: `${{ steps.validate.outputs.report_path }}`
- Lines: ${{ steps.verify.outputs.lines }}
Closes #${{ github.event.issue.number }}
commit-message: "feat(report): ${{ steps.validate.outputs.owner }}/${{ steps.validate.outputs.repo }}"
add-paths: |
src/analysis_report/
src/data/
- name: Comment success
if: success()
run: gh issue comment "$ISSUE_NUMBER" --body "✅ 分析完成,PR 已开,合并后 5 分钟内上线站点。"
- name: Comment failure
if: failure() && steps.validate.outcome == 'success'
run: |
gh issue comment "$ISSUE_NUMBER" --body "❌ 分析失败。日志:${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
gh issue edit "$ISSUE_NUMBER" --add-label "analyze-failed" || true
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: submission-logs-${{ github.event.issue.number }}
path: |
tmp/logs/
tmp/*.md
retention-days: 14
if-no-files-found: warn