🌟 GitHub Stars Index同步 #34
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: 🌟 GitHub Stars Index同步 | |
| on: | |
| # ── 定时触发 ────────────────────────────────────────────── | |
| # 修改下方 cron 表达式以自定义执行频率(UTC 时间) | |
| # 示例: | |
| # "0 2 * * 1" → 每周一 UTC 02:00(北京时间 10:00) | |
| # "0 18 * * *" → 每天 UTC 18:00(北京时间次日 02:00) | |
| # "0 2 1 * *" → 每月 1 日 UTC 02:00 | |
| # cron 在线生成器: https://crontab.guru | |
| schedule: | |
| - cron: "18 18 * * *" # ← 在此修改你的定时频率 | |
| # ── 手动触发 ────────────────────────────────────────────── | |
| workflow_dispatch: | |
| inputs: | |
| force_rebuild: | |
| description: "强制重新生成所有摘要(重建 JSON 数据集)" | |
| required: false | |
| default: "false" | |
| type: choice | |
| options: | |
| - "false" | |
| - "true" | |
| test_limit: | |
| description: "测试模式:限制处理的项目数量(如填 5 则只处理 5 个新项目,留空不限制)" | |
| required: false | |
| default: "" | |
| type: string | |
| permissions: | |
| contents: write # 允许 Action 提交文件到本仓库 | |
| jobs: | |
| sync: | |
| name: 抓取 Stars 并生成摘要 | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 # 超时保护(Stars 较多时可能耗时长) | |
| steps: | |
| # ── 1. 检出代码 ─────────────────────────────────────── | |
| - name: Checkout 仓库 | |
| uses: actions/checkout@v4 | |
| # ── 2. 设置 Python 环境 ─────────────────────────────── | |
| - name: 设置 Python 3.11 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: "pip" | |
| # ── 3. 安装依赖 ─────────────────────────────────────── | |
| - name: 安装依赖 | |
| run: pip install -r requirements.txt | |
| # ── 4. 可选:强制重置数据集 ────────────────────── | |
| - name: 重置数据集(仅在 force_rebuild=true 时执行) | |
| if: github.event.inputs.force_rebuild == 'true' | |
| run: | | |
| echo "⚠️ 强制重建模式:删除现有数据" | |
| rm -rf data/stars.json | |
| # ── 5. 执行同步脚本 ─────────────────────────────────── | |
| - name: 同步 GitHub Stars | |
| env: | |
| # ── Secrets(机密,加密保存)── | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Actions 自动注入,无需手动添加 | |
| AI_API_KEY: ${{ secrets.AI_API_KEY }} # AI API Key | |
| VAULT_PAT: ${{ secrets.VAULT_PAT }} # Vault 仓库写权限 PAT(Vault 同步时必填) | |
| # ── Variables(非机密,明文,在 Settings → Variables 中配置)── | |
| GH_USERNAME: ${{ vars.GH_USERNAME }} # 要抓取 Stars 的 GitHub 用户名 | |
| AI_BASE_URL: ${{ vars.AI_BASE_URL }} # AI 接口地址 | |
| AI_MODEL: ${{ vars.AI_MODEL }} | |
| MAX_CONCURRENCY: ${{ vars.MAX_CONCURRENCY }} | |
| OUTPUT_FILENAME: ${{ vars.OUTPUT_FILENAME }} | |
| VAULT_SYNC_ENABLED: ${{ vars.VAULT_SYNC_ENABLED }} | |
| VAULT_REPO: ${{ vars.VAULT_REPO }} | |
| VAULT_SYNC_PATH: ${{ vars.VAULT_SYNC_PATH }} | |
| TEST_LIMIT: ${{ github.event.inputs.test_limit }} | |
| PAGES_SYNC_ENABLED: ${{ vars.PAGES_SYNC_ENABLED }} | |
| run: python scripts/sync_stars.py | |
| # ── 6. 提交变更到本仓库 ─────────────────────────────── | |
| - name: 提交并推送变更 | |
| run: | | |
| set -e | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add data/stars.json | |
| if git diff --staged --quiet; then | |
| echo "✅ 无新内容,跳过提交" | |
| exit 0 | |
| fi | |
| git commit -m "🤖 自动更新 GitHub Stars 摘要 [$(date -u '+%Y-%m-%d %H:%M UTC')]" | |
| echo "🔄 同步远程最新代码..." | |
| git fetch origin main | |
| git rebase origin/main | |
| echo "🚀 推送更新..." | |
| git push origin main | |
| # ── 7. 部署到 GitHub Pages ───────────────────────────── | |
| - name: 部署到 GitHub Pages | |
| if: vars.PAGES_SYNC_ENABLED == 'true' | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| folder: dist # 同步 dist 文件夹的内容 | |
| branch: gh-pages # 目标分支 | |
| clean: true # 保持分支整洁 |