🤖 Update Starred Repositories #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🤖 Update Starred Repositories | |
on: | |
# 每日自动运行(北京时间上午9点,UTC时间凌晨1点) | |
schedule: | |
- cron: '0 1 * * *' | |
# 手动触发,支持选择运行模式 | |
workflow_dispatch: | |
inputs: | |
mode: | |
description: '运行模式 (auto/daily/weekly)' | |
required: true | |
default: 'auto' | |
type: choice | |
options: | |
- auto | |
- daily | |
- weekly | |
force_reanalyze: | |
description: '强制重新分析所有仓库' | |
required: false | |
default: false | |
type: boolean | |
sample_size: | |
description: '测试模式:仅分析前N个仓库(留空则全部分析)' | |
required: false | |
type: string | |
jobs: | |
update-starred-repos: | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 # 设置超时时间为60分钟 | |
# 授予对仓库内容的写权限,以便可以 git push | |
permissions: | |
contents: write | |
steps: | |
- name: 📥 Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} # 使用具有写权限的 GITHUB_TOKEN | |
fetch-depth: 0 # 获取完整历史,以便正确 diff | |
- name: 🐍 Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: 💾 Cache pip dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: 📦 Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: 🚀 Run analysis | |
env: | |
# ======================= 环境变量配置 ======================= | |
# 敏感信息:从 GitHub Secrets 读取 | |
# 请确保在仓库的 Settings -> Secrets and variables -> Actions 中设置了这些值 | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
LLM_API_KEY: ${{ secrets.LLM_API_KEY }} | |
SILICONFLOW_API_KEY: ${{ secrets.SILICONFLOW_API_KEY }} # 如果你不用SiliconFlow,可以删除或留空这个secret | |
# 非敏感配置:直接写在这里,方便修改和版本控制 | |
LLM_API_BASE_URL: https://openrouter.ai/api/v1 | |
LLM_MODEL_NAME: qwen/qwen3-30b-a3b-instruct-2507 | |
# ========================================================== | |
run: | | |
# 检查关键的 secret 是否设置 | |
if [ -z "$LLM_API_KEY" ]; then | |
echo "::error::LLM_API_KEY secret is not set or empty! Please configure it in repository settings." | |
exit 1 | |
fi | |
# 构建命令参数 | |
CMD="python main_v3.py" | |
if [ -n "${{ github.event.inputs.mode }}" ]; then | |
CMD="$CMD --mode ${{ github.event.inputs.mode }}" | |
else | |
CMD="$CMD --mode auto" # schedule 触发时使用默认值 | |
fi | |
if [ "${{ github.event.inputs.force_reanalyze }}" = "true" ]; then | |
CMD="$CMD --force-reanalyze" | |
fi | |
if [ -n "${{ github.event.inputs.sample_size }}" ]; then | |
CMD="$CMD --sample ${{ github.event.inputs.sample_size }}" | |
fi | |
echo "执行命令: $CMD" | |
$CMD | |
- name: 📊 Show statistics | |
if: always() # 无论上一步是否成功,都尝试显示统计信息 | |
run: | | |
echo "=== 数据库统计信息 ===" | |
python main_v3.py --stats || echo "无法获取统计信息" | |
- name: 📝 Commit and push changes | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
# 检查是否有文件变更,如果没有就提前退出,避免空提交 | |
if git diff --quiet && git diff --cached --quiet; then | |
echo "没有文件变更,跳过提交" | |
exit 0 | |
fi | |
# 【关键修改】使用 'git add -A' 来暂存所有变更(新增、修改、删除) | |
# 这比指定具体文件名更健壮,不会因为某个文件不存在而失败 | |
echo "正在暂存所有变更..." | |
git add -A | |
# 再次检查暂存区,确保有内容可提交 | |
if git diff --cached --quiet; then | |
echo "暂存区为空,可能是 git add 失败或没有需要追踪的文件变更。" | |
exit 0 | |
fi | |
# 生成提交信息 | |
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S UTC') | |
MODE="${{ github.event.inputs.mode || 'auto' }}" | |
if [ "${{ github.event.inputs.force_reanalyze }}" = "true" ]; then | |
COMMIT_MSG="🔄 Chore: Force re-analyze all repos at $TIMESTAMP" | |
elif [ -n "${{ github.event.inputs.sample_size }}" ]; then | |
COMMIT_MSG="🧪 Test: Run on sample size of ${{ github.event.inputs.sample_size }} at $TIMESTAMP" | |
else | |
COMMIT_MSG="🤖 Feat: Auto-update starred repos analysis ($MODE mode) at $TIMESTAMP" | |
fi | |
# 提交变更 | |
echo "正在提交变更..." | |
git commit -m "$COMMIT_MSG" | |
echo "正在推送到远程仓库..." | |
git push | |
- name: 📋 Upload artifacts | |
uses: actions/upload-artifact@v4 | |
if: always() # 无论成功与否,都上传日志和数据库文件 | |
with: | |
name: analysis-results-${{ github.run_number }} | |
path: | | |
starred_repos.log | |
debug.log | |
data/starred_repos_v3.db | |
retention-days: 7 # 日志和数据库保留7天 | |
- name: 📈 Create job summary | |
if: always() | |
run: | | |
echo "## 🎯 运行总结" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "**运行时间**: $(date '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY | |
echo "**触发方式**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY | |
echo "**运行模式**: ${{ github.event.inputs.mode || 'auto' }}" >> $GITHUB_STEP_SUMMARY | |
echo "**强制重新分析**: ${{ github.event.inputs.force_reanalyze || 'false' }}" >> $GITHUB_STEP_SUMMARY | |
if [ -n "${{ github.event.inputs.sample_size }}" ]; then | |
echo "**测试模式**: 仅分析前 ${{ github.event.inputs.sample_size }} 个仓库" >> $GITHUB_STEP_SUMMARY | |
fi | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "### 📊 数据库统计" >> $GITHUB_STEP_SUMMARY | |
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
python main_v3.py --stats 2>/dev/null || echo "无法获取统计信息" >> $GITHUB_STEP_SUMMARY | |
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "### 🔗 相关链接" >> $GITHUB_STEP_SUMMARY | |
echo "- [📚 查看更新后的 README](https://github.com/${{ github.repository }}/blob/main/README.md)" >> $GITHUB_STEP_SUMMARY | |
if [ -f "weekly_report.md" ]; then | |
echo "- [📊 查看本周报告](https://github.com/${{ github.repository }}/blob/main/weekly_report.md)" >> $GITHUB_STEP_SUMMARY | |
fi |