我构建了一个使用 AI 解释你的 CI 失败原因的 GitHub Action
发布: (2026年1月9日 GMT+8 23:00)
3 分钟阅读
原文: Dev.to
Source: Dev.to
我是如何构建它的
我使用了 Claude Code(Anthropic 的 CLI 工具)在一次会话中完成了全部工作。从想法到可运行的 GitHub Action 大约用了一个小时——包括我在中途加入的 DM 功能,因为我想“如果它能直接给导致构建失败的人发消息,那不是很酷吗?”
Claude Code 处理了所有事情:GitHub Actions 的设置、Slack API 集成、日志解析,甚至写了 README。说实话,这是一段相当疯狂的体验。
它的功能
当你的工作流失败时:
- 从失败的作业中获取日志
- 将日志发送给 Claude 进行分析
在 Slack 中发布摘要,内容包括:
- 根本原因 — 实际导致失败的原因
- 错误信息 — 具体的错误信息
- 建议的修复 — 可执行的下一步操作
- 链接 — 指向完整日志的链接
炫酷功能:私信给导致构建失败的人
你可以配置它 直接私信提交者,而不是在频道里发布。它会在 Slack 中查找提交者的 GitHub 邮箱并发送私信。
不再需要“@channel 谁把构建弄坏了?”——负责的人会立即收到通知。
示例输出
CI Failed: Build and Test
Repository: your-org/your-repo
Branch: feature/new-feature
Commit: abc1234
Failed Jobs: test
---
1. **Root Cause**: Test assertion failed due to incorrect mock data
2. **Error**: Expected 200 but received 404 in api.test.js:42
3. **Suggested Fix**: Update the mock endpoint URL to match the new API route
快速设置(2 分钟)
notify-on-failure:
runs-on: ubuntu-latest
needs: [build, test]
if: failure()
steps:
- uses: galion96/ci-failure-sumarizer@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
notification_mode: dm # or 'channel' for webhook
成本
使用 Claude Sonnet:约 $0.01 每次失败。如果你的 CI 每月失败 100 次,费用约为 $1。
链接
- GitHub: https://github.com/galion96/ci-failure-sumarizer
- Setup Guide: Check the README for full instructions