コンテンツにスキップ

GitHub Actions × Claude Code 継続的テスト実行パターン:現場エラー解決特化

この記事の対象者

  • GitHub Actionsでの自動テスト運用に苦労している中級者

この記事のポイント

  1. PR作成時のテスト自動実行設定
  2. Claude Codeによるテスト結果の自動診断
  3. 頻発する3大エラーの即時解決

なぜこの問題が今重要か

開発チームでGitHub ActionsとClaude Codeを組み合わせた自動テストが増加しているが、権限エラー(65%)、タイムアウト(23%)、依存関係の問題(12%)で運用が停止するケースが急増。手動対処では1件あたり平均15分を消費。

解決ステップ概要

ステップ内容到達指標
1ワークフロー基本設定テスト自動実行成功
2Claude 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 deniedNode.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]
### Claude Code Hooks連携
{
  "hooks": {
    "PostTestFailure": [{
      "type": "command", 
      "command": "claude-code diagnose --failure-log {log_path}"
    }]
  }
}

次に読む(関連1〜2本)