用途:当 GitHub Actions CI 失败、需要排查分支或 PR 上的构建与测试错误、用户询问 CI 状态,或需要读取 GHA 构建日志内容时使用。该技能的核心是 tools/fetch_gha_logs.py 脚本。
主要能力:脚本自动处理代理设置、日志下载与错误/内容提取。相比 gh run view --log 或直接 gh api 调用,脚本下载完整日志 zip 并可靠提取全部内容,避免前者常出现的输出截断与步骤丢失。
常用命令: 当前分支最新失败:python3 tools/fetch_gha_logs.py --latest 指定分支:python3 tools/fetch_gha_logs.py --latest --branch main 指定 PR:python3 tools/fetch_gha_logs.py --pr 42 指定工作流:python3 tools/fetch_gha_logs.py --latest --workflow linux 指定运行 ID:python3 tools/fetch_gha_logs.py 12345678 保存错误到文件:python3 tools/fetch_gha_logs.py --latest --output /tmp/gha_errors.txt 完整原始日志:python3 tools/fetch_gha_logs.py --latest --raw 仅列出近期失败:python3 tools/fetch_gha_logs.py
失败排查流程:先运行 python3 tools/fetch_gha_logs.py --latest --output /tmp/gha_errors.txt,文件中包含多数构建错误、测试失败、链接器错误与 CMake 问题,并给出最近失败构建的原始日志位置,可供进一步查看;也可用 --pr <N> 或运行 ID 指定目标。随后定位并修复源代码中的问题。
日志分析流程:使用 --raw 并通过 grep 查找所需信息,例如 sccache 统计 python3 tools/fetch_gha_logs.py <run_id> --raw 2>&1 | grep -A 30 "sccache --show-stats";GHA 缓存列表用 grep -A 35 "gh cache list";缓存恢复结果用 grep "Cache restored"。可先用 gh run list 或 gh api 获取运行 ID 与步骤耗时元数据,再用本脚本查看实际日志内容。
适用场景:CI 报红、构建失败、检查任意分支或 PR 的 GHA 状态、调查构建性能、缓存命中率、sccache 统计与构建耗时,以及读取 GHA 构建日志全文。
限制:资料未提供脚本运行环境、依赖安装方式、权限与代理配置的具体要求,也未说明可处理的日志规模上限;使用前需确保仓库中存在该脚本并具备访问 GitHub Actions 日志的权限。