mcpField
W
watch-ci

watch-ci

github.com/codervisor云与 DevOps30040 次安装23 周前更新
代码仓库

关于 watch-ci

用于监控 codervisor/leanspec 仓库当前 HEAD 提交的 GitHub Actions CI。技能通过 curl 调用 GitHub REST API,查找对应提交的运行、轮询任务状态并获取失败日志。

主要功能

  1. 01按提交 SHA 匹配工作流运行
  2. 02轮询任务状态直至完成
  3. 03获取失败任务日志
  4. 04汇报总体及各任务结果

适用场景

  1. 01跟踪当前分支提交的 CI
  2. 02等待 Node.js 和 Rust 任务完成
  3. 03检查失败任务步骤和日志

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/codervisor/leanspec --skill watch-ci

安装后在 Claude Code 中输入/watch-ci确认已加载。

详细介绍

监控 CI

轮询 GitHub Actions CI 流水线,直到当前 HEAD 提交的所有任务都完成。

环境

Claude VM 中无法使用 gh CLI。请通过 curl 使用 GitHub REST API。 仓库为 codervisor/leanspec。

步骤

  1. 获取当前提交 SHA 和分支:

    SHA=$(git rev-parse HEAD)
    BRANCH=$(git branch --show-current)
    echo "Watching CI for commit $SHA on branch $BRANCH"
    
  2. 查找与我们的提交完全匹配的工作流运行。API 按时间倒序返回运行记录;请按 head_sha 筛选。如果运行记录尚未出现(GitHub 可能需要几秒钟),请等待 10 秒后重试,最多 5 次:

    curl -sH "Accept: application/vnd.github+json" \
      "https://api.github.com/repos/codervisor/lean-spec/actions/runs?branch=$BRANCH&head_sha=$SHA&per_page=1" \
      | python3 -c "
    import json, sys
    data = json.load(sys.stdin)
    runs = data.get('workflow_runs', [])
    if not runs:
        print('NO_RUNS'); sys.exit()
    r = runs[0]
    print(f'RUN_ID={r[\"id\"]}')
    print(f'Status: {r[\"status\"]}  Conclusion: {r.get(\"conclusion\") or \"pending\"}  Commit: {r[\"head_sha\"][:8]}')"
    
  3. 轮询任务状态,直到全部完成(Rust 构建大约需要 8-10 分钟,因此每 60 秒轮询一次):

    curl -sH "Accept: application/vnd.github+json" \
      "https://api.github.com/repos/codervisor/lean-spec/actions/runs/$RUN_ID/jobs" \
      | python3 -c "
    import json, sys
    data = json.load(sys.stdin)
    for j in data.get('jobs', []):
        steps = [s for s in j.get('steps', []) if s['status'] == 'in_progress']
        step_info = f' -> {steps[0][\"name\"]}' if steps else ''
        print(f'{j[\"name\"]:40}  {j[\"status\"]:12}  {j.get(\"conclusion\") or \"\"}{step_info}')"
    
  4. 如果失败,获取失败任务的日志以进行诊断:

    curl -sH "Accept: application/vnd.github+json" \
      "https://api.github.com/repos/codervisor/lean-spec/actions/runs/$RUN_ID/jobs" \
      | python3 -c "
    import json, sys
    data = json.load(sys.stdin)
    for j in data.get('jobs', []):
        if j.get('conclusion') == 'failure':
            print(f'FAILED: {j[\"name\"]} (id: {j[\"id\"]})')
            for s in j.get('steps', []):
                if s.get('conclusion') == 'failure':
                    print(f'  Step: {s[\"name\"]}')"
    

CI 结构

  • node(约 2 分钟):pnpm install、build、typecheck、test
  • rust(约 8-10 分钟,依赖 node):cargo fmt、clippy、build、test、TS 绑定导出

状态报告

每次轮询后,向用户简要报告状态。完成后,请总结:

  • 总体结果(成功/失败)
  • 各任务的结果
  • 如果失败:失败的步骤及相关错误输出

评论

支持 Markdown