fixing-streamlit-ci について
ブランチや PR の GitHub Actions CI 失敗を調査・修正するワークフロースキルです。`gh` と `git` でログや原因を確認し、修正を検証します。
主な機能
- 01PR と CI 状態の確認
- 02失敗ジョブの特定とログ分析
- 03主なエラーと対象ファイルの把握
- 04ローカルでの修正検証と CI 再確認
活用シーン
- 01PR の失敗したチェックの調査
- 02テスト、型、ビルドエラーの分析
- 03修正後のローカルチェックとワークフロー再確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ streamlit/ streamlit --skill fixing-streamlit-ciインストール後、Claude Code で/fixing-streamlit-ciを入力して読み込まれたか確認します。
詳細
CI 失敗の修正
gh CLI と git コマンドを使用して、現在のブランチ/PR で失敗した GitHub Actions CI ジョブを診断し、修正します。
使用するタイミング
- PR で CI チェックが失敗した場合
- ワークフローが失敗した理由を理解する必要がある場合
- 修正を適用し、ローカルで検証したい場合
ワークフロー
進捗を追跡するには、このチェックリストをコピーしてください:
- [ ] Verify authentication
- [ ] Gather context & find failed jobs
- [ ] Download & analyze logs
- [ ] Present diagnosis to user
- [ ] Apply fix & verify locally
- [ ] Push & recheck CI
1. 認証の確認
gh auth status
認証に失敗した場合は、適切なスコープを指定して gh auth login を実行するようユーザーに促します。
2. PR コンテキストの収集
# Get PR for current branch
gh pr view --json number,title,url,headRefName
# Get PR description and metadata
gh pr view --json title,body,labels,author
# List changed files
gh pr diff --name-only
# All changes
gh pr diff
3. CI ステータスの確認
# List all checks (shows pass/fail status)
gh pr checks
# Get detailed check info
gh pr checks --json name,state,conclusion,detailsUrl,startedAt,completedAt
# List only failed runs
gh run list --branch $(git branch --show-current) --status failure --limit 10
# Check if CI is still running
gh run list --branch $(git branch --show-current) --status in_progress
4. 失敗したジョブの特定
# View run details (get RUN_ID from previous step)
gh run view {RUN_ID}
# List failed jobs with IDs
gh run view {RUN_ID} --json jobs --jq '.jobs[] | select(.conclusion == "failure") | {id: .databaseId, name: .name}'
# List failed jobs with their failed steps
gh run view {RUN_ID} --json jobs --jq '.jobs[] | select(.conclusion == "failure") | {name: .name, steps: [.steps[] | select(.conclusion == "failure") | .name]}'
5. ログのダウンロードと分析
主要な方法:
# Get failed logs (last 250 lines usually contains the error)
gh run view {RUN_ID} --log-failed 2>&1 | tail -250
# Target a specific failed job by ID
gh run view {RUN_ID} --job {JOB_ID} --log-failed 2>&1 | tail -100
ログが保留中の場合のフォールバック:
REPO=$(gh repo view --json nameWithOwner --jq '.nameWithOwner')
gh api "/repos/${REPO}/actions/jobs/{JOB_ID}/logs"
スマートなログ抽出 (例):
# Context around failure markers
gh run view {RUN_ID} --log-failed 2>&1 | grep -B 5 -A 10 -iE "error|fail|exception|traceback|panic|fatal" | head -100
# Python tests - pytest summary
gh run view {RUN_ID} --log-failed 2>&1 | grep -E -A 50 "FAILED|ERROR|short test summary"
# TypeScript/ESLint errors
gh run view {RUN_ID} --log-failed 2>&1 | grep -E -B 2 -A 5 "error TS|error "
# E2E snapshot mismatches
gh run view {RUN_ID} --log-failed 2>&1 | grep -E -B 2 -A 5 "Missing snapshot for|Snapshot mismatch for"
6. 失敗の分析
以下を特定します:
- エラーの種類: Lint、型チェック、テスト失敗、ビルドエラー
- 根本原因: 最初の/主要なエラー (連鎖的な失敗ではない)
- 影響を受けるファイル: 変更が必要なファイル
- エラーメッセージ: 正確なエラーテキスト
一般的な CI 失敗のカテゴリ:
| カテゴリ | ワークフロー | Make コマンド | 自動修正 |
|---|---|---|---|
| Python lint | python-tests.yml | make python-lint | ✅ make autofix |
| Python types | python-tests.yml | make python-types | ❌ 手動 |
| Python tests | python-tests.yml | make python-tests | ❌ 手動 |
| Frontend lint | js-tests.yml | make frontend-lint | ✅ make autofix |
| Frontend types | js-tests.yml | make frontend-types | ❌ 手動 |
| Frontend tests | js-tests.yml | make frontend-tests | ❌ 手動 |
| E2E tests | playwright.yml | make run-e2e-test <file> | ❌ 手動 |
| E2E snapshots | playwright.yml | make run-e2e-test <file> | ✅ make update-snapshots |
| NOTICES | js-tests.yml | make update-notices | ✅ make update-notices |
| Min constraints | python-tests.yml | make update-min-deps | ✅ make update-min-deps |
| Pre-commit | enforce-pre-commit.yml | uv run pre-commit run --all-files | ✅ ほとんど自動修正 |
| Relative imports | ensure-relative-imports.yml | スクリプト出力を確認 | ❌ 手動 |
| PR Labels | require-labels.yml | N/A | ⏭️ 無視 |
💡 クイックウィン: lint/フォーマットの失敗には、まず
make autofixを実行してください。
7. 診断結果の提示
複数の失敗がある場合は、すべてをリストし、ユーザーに選択させます:
CI Failure Analysis for PR #{NUMBER}: {TITLE}
═══════════════════════════════════════════════════════════════
Found {N} failed jobs/checks:
─────────────────────────────────────────────────────────────────
1. [LINT] Python Unit Tests → Run Linters
Workflow: python-tests.yml (GitHub Actions)
Error: Ruff formatting error in lib/streamlit/elements/foo.py
Auto-fix: ✅ `make autofix`
2. [TYPE] Javascript Unit Tests → Run type checks
Workflow: js-tests.yml (GitHub Actions)
Error: TS2322: Type 'string' is not assignable to type 'number'
File: frontend/lib/src/components/Bar.tsx:42
Auto-fix: ❌ Manual fix required
─────────────────────────────────────────────────────────────────
Which failures should I address?
Recommended: "1" (auto-fixable)
Options: "1" | "1,2" | "1-2" | "all" | "only auto-fixable"
単一の失敗の場合は、詳細な分析を表示します:
─────────────────────────────────────────────────────────────────
Analyzing: [TYPE] Javascript Unit Tests → Run type checks
─────────────────────────────────────────────────────────────────
Category: TYPE
Workflow: js-tests.yml
Job: js-unit-tests (ID: 12345678)
Step: Run type checks
Error snippet:
frontend/lib/src/components/Bar.tsx:42:5
error TS2322: Type 'string' is not assignable to type 'number'.
Proposed Fix:
Change type annotation or fix the value type
─────────────────────────────────────────────────────────────────
Would you like me to:
[1] Apply the fix automatically
[2] Show the proposed changes first
[3] Run local verification only
[4] Skip this and move to next failure
8. 修正の適用とローカルでの検証
ユーザーの承認後、修正を適用して検証を実行します:
# Run all checks (lint, types, tests) on changed files
make check
# Python tests (specific)
uv run pytest lib/tests/path/to/test_file.py::test_name -v
# Frontend tests (specific)
cd frontend && yarn test path/to/test.test.tsx
# E2E tests
make run-e2e-test {test_file.py}
# E2E snapshots
make update-snapshots
9. まとめとプッシュ
git status --short
git diff --stat
何が失敗し、何が変更され、ローカル検証の結果がどうであったかを報告します。
git add -A
git commit -m "fix: resolve CI failure in {workflow/step}"
git push
10. CI ステータスの再確認
gh pr checks --watch
# Or re-run failed jobs
gh run rerun {RUN_ID} --failed
ルール
- 根本原因に焦点を当てる: 連鎖的な失敗ではなく、最初のエラー
- 最小限の修正: 問題を修正する最小の変更
- テストをスキップしない: CI を「修正」するためにテストを無効にしないこと
- ローカルで検証する: 常に適切なローカルコマンドを実行する
- 意図を保持する: コードが何をしようとしていたかを理解する
エラー処理
| 問題 | 解決策 |
|---|---|
| 認証失敗 | workflow/repo スコープを指定して gh auth login |
| ブランチに PR がない | gh run list でワークフロー実行を確認 |
| CI がまだ実行中 | gh pr checks --watch |
| ログが保留中 | job logs API で再試行 |
| 失敗したチェックがない | すべて成功 ✅ |
| レート制限 | 待機して再試行 |
| 不安定なテスト | 再実行: gh run rerun {RUN_ID} --failed |
コメント
Markdown 対応