GitHub Actions × Claude Code 継続的テスト実行パターン:現場エラー解決特化¶
この記事の対象者
- GitHub Actionsでの自動テスト運用に苦労している中級者
この記事のポイント¶
- PR作成時のテスト自動実行設定
- Claude Codeによるテスト結果の自動診断
- 頻発する3大エラーの即時解決
なぜこの問題が今重要か¶
開発チームでGitHub ActionsとClaude Codeを組み合わせた自動テストが増加しているが、権限エラー(65%)、タイムアウト(23%)、依存関係の問題(12%)で運用が停止するケースが急増。手動対処では1件あたり平均15分を消費。
解決ステップ概要¶
| ステップ | 内容 | 到達指標 |
|---|---|---|
| 1 | ワークフロー基本設定 | テスト自動実行成功 |
| 2 | Claude Code診断設定 | エラー自動検出確認 |
| 3 | 頻発エラー予防設定 | エラー発生率90%減 |
ステップ1: テスト自動実行の基本設定¶
name: Claude Code Continuous Testing
on:
pull_request:
types: [opened, synchronize]
jobs:
test-with-claude:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests with timeout
timeout-minutes: 10
run: |
npm test -- --coverage --maxWorkers=2
- name: Claude Code analysis on failure
if: failure()
run: |
echo "Test failed - Claude Code diagnosis required"
ステップ2: Claude Code自動診断の実装¶
- name: Setup Claude Code for diagnosis
if: failure()
run: |
export CLAUDE_API_KEY="${{ secrets.CLAUDE_API_KEY }}"
echo "Analyzing test failures..."
npx claude-code analyze --test-output ./test-results.json
ステップ3: 頻発エラーの予防設定¶
# 権限エラー予防(package.json)
{
"scripts": {
"test:ci": "npm test -- --forceExit --detectOpenHandles"
}
}
よくある落とし穴と対処¶
| 症状 | 原因 | 即時対処 |
|---|---|---|
| Permission denied | Node.js権限 | npm config set unsafe-perm true |
| Test timeout | 無限ループ | --forceExit --detectOpenHandles |
| Module not found | 依存関係キャッシュ | npm ci --prefer-offline |
詳細設定(高度最適化)
### 並列実行最適化 strategy:
matrix:
node-version: [18, 20]
test-suite: [unit, integration]
{
"hooks": {
"PostTestFailure": [{
"type": "command",
"command": "claude-code diagnose --failure-log {log_path}"
}]
}
}