doc-watch #3
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: doc-watch | |
| # 每日抓取上游文档站(Loomy Docs / AstronClaw 使用指南),与仓库基线对比: | |
| # 1) 始终:发现新增内容时维护一条 [doc-watch] Issue 汇总待补全清单。 | |
| # 2) 可选:若配置了 OPENAI_API_KEY secret,则用 OpenAI(自带 web_search,按你自己的 | |
| # API 计费、不消耗 Claude 额度)起草新页面+下载配图+联网检索官方更新,并开一个待审 PR。 | |
| # | |
| # 触发:每天 01:00 UTC(北京时间 09:00)+ 可手动触发。 | |
| # | |
| # 需要的仓库配置(用到 PR 自动起草时): | |
| # - Secret OPENAI_API_KEY :你的 OpenAI key | |
| # - Variable OPENAI_MODEL :可选,默认 gpt-4.1(须支持 web_search) | |
| # - 仓库 Settings → Actions → General → 勾选 “Allow GitHub Actions to create and approve pull requests” | |
| on: | |
| schedule: | |
| - cron: '0 1 * * *' | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| watch: | |
| runs-on: ubuntu-latest | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| OPENAI_MODEL: ${{ vars.OPENAI_MODEL }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Run doc-watch | |
| id: watch | |
| run: | | |
| set +e | |
| node scripts/doc-watch/check-updates.mjs --report doc-watch-report.md | |
| echo "code=$?" >> "$GITHUB_OUTPUT" | |
| set -e | |
| - name: Upsert summary issue on changes | |
| if: steps.watch.outputs.code == '1' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| BODY_FILE=doc-watch-report.md | |
| { | |
| echo "" | |
| echo "---" | |
| echo "_由 \`doc-watch\` 工作流自动生成 · run [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})_" | |
| echo "" | |
| echo "处理完成后,在补全内容的 PR 里执行 \`node scripts/doc-watch/check-updates.mjs --update\` 刷新基线,本 Issue 即可关闭。" | |
| } >> "$BODY_FILE" | |
| TITLE="[doc-watch] 上游文档有新增内容待补全" | |
| EXISTING=$(gh issue list --label doc-watch --state open --json number --jq '.[0].number' 2>/dev/null) | |
| if [ -n "$EXISTING" ]; then | |
| gh issue edit "$EXISTING" --body-file "$BODY_FILE" | |
| gh issue comment "$EXISTING" --body "🔄 巡检报告已于本次 run 更新(run #${{ github.run_number }})。" | |
| echo "Updated issue #$EXISTING" | |
| else | |
| gh label create doc-watch --color FBCA04 --description "上游文档巡检" 2>/dev/null || true | |
| gh issue create --title "$TITLE" --label doc-watch --body-file "$BODY_FILE" | |
| fi | |
| # ---- 可选:OpenAI 起草 + 自动开 PR(仅在配置了 OPENAI_API_KEY 时启用)---- | |
| - name: Draft new pages with OpenAI | |
| id: draft | |
| if: steps.watch.outputs.code == '1' && env.OPENAI_API_KEY != '' | |
| run: | | |
| set +e | |
| node scripts/doc-watch/draft-with-openai.mjs | |
| echo "code=$?" >> "$GITHUB_OUTPUT" | |
| set -e | |
| - name: Build, refresh baseline and open PR | |
| if: steps.watch.outputs.code == '1' && env.OPENAI_API_KEY != '' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if [ -z "$(git status --porcelain docs/)" ]; then | |
| echo "OpenAI 未产出可落地的页面改动,跳过 PR(详情见 doc-watch Issue)。" | |
| exit 0 | |
| fi | |
| npm ci | |
| npm run docs:build | |
| node scripts/doc-watch/check-updates.mjs --update || true | |
| DATE=$(date +%Y-%m-%d) | |
| BRANCH="docs/sync-upstream-$(date +%Y%m%d-%H%M)" | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor }}@users.noreply.github.com" | |
| git checkout -b "$BRANCH" | |
| # 只提交源文件与重建的搜索索引,避免把已被 .gitignore 但历史已跟踪的 | |
| # docs/.vitepress/dist|cache 构建产物卷进来。 | |
| git add docs/guide docs/en docs/public/loomy docs/public/astronclaw \ | |
| docs/public/docs-index.json docs/.vitepress/config.mts \ | |
| scripts/doc-watch/baseline/ | |
| git commit -m "docs: 同步上游文档新增内容 ($DATE)" | |
| git push -u origin "$BRANCH" | |
| gh pr create --base main --head "$BRANCH" \ | |
| --title "docs: 同步上游文档新增内容 ($DATE)" \ | |
| --body-file doc-watch-draft-pr.md | |
| - name: Report capture failure | |
| if: steps.watch.outputs.code == '2' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh label create doc-watch --color FBCA04 --description "上游文档巡检" 2>/dev/null || true | |
| gh issue create \ | |
| --title "[doc-watch] ⚠️ 巡检抓取失败" \ | |
| --label doc-watch \ | |
| --body "doc-watch 工作流抓取上游文档时出错,请查看 run [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) 日志。可能是上游站点改版或网络问题。" | |
| - name: Upload report artifact | |
| if: steps.watch.outputs.code == '1' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: doc-watch-report | |
| path: doc-watch-report.md |