「GitHub Actionsのワークフローを書くのが面倒」「CI/CDパイプラインの構築に時間がかかりすぎる」——そんな悩みを抱えるエンジニアに朗報です。
Claude CodeとGitHub Actionsを組み合わせることで、CI/CDパイプラインの設計・構築・運用を大幅に効率化できます。YAMLファイルの生成からテストの自動化、デプロイフローの最適化まで、AIがあなたの右腕になります。
- Claude CodeでGitHub Actionsワークフローを自動生成し、CI/CD構築時間を70%短縮
- テスト自動化・セキュリティスキャン・デプロイまでの一気通貫パイプラインを構築
- SES現場でのDevOps案件で即活用できるプロンプトテンプレート付き
Claude Code × GitHub Actions連携の全体像

GitHub Actionsは、GitHubリポジトリに統合されたCI/CDプラットフォームです。プッシュ、プルリクエスト、スケジュールなどのイベントをトリガーに、ビルド・テスト・デプロイを自動化できます。
Claude Codeと組み合わせることで、以下のメリットが得られます:
- ワークフローYAMLの自動生成 — 複雑な設定もプロンプト一つで
- テストコードの同時生成 — CIで実行するテストも一緒に作成
- エラーの自動診断・修正 — CI失敗時のログ解析と修正提案
- セキュリティ統合 — 依存関係スキャン・SAST・シークレット管理の組み込み
- Claude Codeを使ったGitHub Actionsワークフローの自動生成方法
- テスト・ビルド・デプロイの一気通貫パイプライン構築
- マトリクスビルド・キャッシュ最適化・並列実行のテクニック
- SES現場で使えるDevOps自動化の実践パターン
GitHub Actionsワークフローの自動生成
基本的なCI/CDワークフローの生成
Claude Codeに以下のようなプロンプトを投げるだけで、プロジェクトに最適なワークフローを生成できます。
claude "このNext.jsプロジェクトに最適なGitHub Actionsワークフローを作成して。
要件:
- mainブランチへのPRでテスト・lint・型チェックを実行
- mainマージ時にVercelへ自動デプロイ
- Node.js 20を使用
- pnpmパッケージマネージャー
- テスト結果をPRにコメント"
Claude Codeは、プロジェクトの構成を自動解析し、以下のようなワークフローを生成します:
# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
pull_request:
branches: [main]
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-and-typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm typecheck
test:
runs-on: ubuntu-latest
needs: lint-and-typecheck
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test -- --coverage
- name: テスト結果をPRにコメント
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
## テスト結果 ✅
カバレッジレポートは Artifacts をご確認ください。
deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [lint-and-typecheck, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: '--prod'
プロジェクト解析の活用
Claude Codeはプロジェクト構造を理解した上でワークフローを生成するため、以下の要素を自動的に考慮します:
| 解析対象 | 反映内容 |
|---|---|
package.json | パッケージマネージャー、スクリプト名 |
tsconfig.json | TypeScript設定、型チェックコマンド |
.eslintrc / eslint.config.js | Lintルール、使用プラグイン |
Dockerfile | コンテナビルドステップ |
| テストフレームワーク | Jest / Vitest / Playwright の自動検出 |
| デプロイ先 | Vercel / AWS / GCP の設定ファイル |
# プロジェクト構造を解析させてから生成
claude "プロジェクト全体を分析して、最適なCI/CDパイプラインを提案して。
- 使用しているフレームワーク・ライブラリを自動検出
- 既存のテスト設定を考慮
- パフォーマンスを最適化(キャッシュ、並列実行)"
マトリクスビルドとキャッシュ最適化
マトリクス戦略の自動生成
複数のNode.jsバージョンやOSでテストを実行するマトリクスビルドも、Claude Codeで簡単に構築できます。
claude "GitHub ActionsのマトリクスビルドをGitHub Actionsに追加して。
- Node.js 18, 20, 22 でテスト
- ubuntu-latest と macos-latest
- 失敗しても他のジョブは継続(fail-fast: false)"
生成されるワークフロー:
jobs:
test-matrix:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
node-version: [18, 20, 22]
exclude:
- os: macos-latest
node-version: 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test
キャッシュ戦略の最適化
CI/CDの実行速度を改善するキャッシュ戦略をClaude Codeに最適化させましょう。
claude "GitHub Actionsのキャッシュを最適化して。
- 依存関係のキャッシュ
- ビルドキャッシュ(Next.js .next/cache)
- Turborepoキャッシュ(モノレポの場合)
- Docker レイヤーキャッシュ"
# 最適化されたキャッシュ設定の例
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
# Next.js ビルドキャッシュ
- uses: actions/cache@v4
with:
path: |
.next/cache
node_modules/.cache
key: nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.ts', '**/*.tsx') }}
restore-keys: |
nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
nextjs-${{ runner.os }}-
# Turborepo キャッシュ(モノレポ)
- uses: actions/cache@v4
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: turbo-${{ runner.os }}-
テスト自動化とカバレッジ統合
テストとCIの一体化
Claude Codeを使って、テストコードの生成とCIでの実行を同時に設定できます。
claude "以下を実行して:
1. src/以下の全ファイルに対するユニットテストを生成
2. E2Eテスト(Playwright)をCI上で実行する設定を追加
3. カバレッジレポートをPRコメントとして投稿する設定"
E2Eテストの統合
e2e-test:
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: Playwright ブラウザインストール
run: pnpm exec playwright install --with-deps chromium
- name: E2Eテスト実行
run: pnpm exec playwright test
env:
CI: true
- name: テスト結果アップロード
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 14
カバレッジの可視化
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test -- --coverage --coverageReporters=json-summary
- name: カバレッジコメント
if: github.event_name == 'pull_request'
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-path: coverage/coverage-summary.json
セキュリティスキャンの統合
依存関係とコードのスキャン
CI/CDパイプラインにセキュリティスキャンを組み込むことは、現代の開発では必須です。
claude "GitHub Actionsにセキュリティスキャンを追加して:
- npm audit(依存関係の脆弱性チェック)
- CodeQL(静的解析)
- Trivy(コンテナイメージスキャン)
- シークレットスキャン(GitLeaks)"
security-scan:
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# 依存関係の脆弱性チェック
- name: npm audit
run: pnpm audit --audit-level=high
continue-on-error: true
# CodeQL静的解析
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript-typescript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
# シークレットスキャン
- name: GitLeaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
container-scan:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t app:${{ github.sha }} .
- name: Trivy スキャン
uses: aquasecurity/trivy-action@master
with:
image-ref: app:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
デプロイ自動化パターン
環境別デプロイ戦略
Claude Codeを使って、ステージング → プロダクションの段階的デプロイを構築します。
claude "以下の環境別デプロイフローを構築して:
- PR作成時 → プレビュー環境にデプロイ
- developマージ → ステージングにデプロイ
- mainマージ → 手動承認後にプロダクションデプロイ
- デプロイ先はAWS ECS Fargate"
deploy-staging:
if: github.ref == 'refs/heads/develop'
needs: [test, security-scan]
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1
- name: ECRにプッシュ
run: |
aws ecr get-login-password | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
docker build -t ${{ secrets.ECR_REGISTRY }}/app:staging-${{ github.sha }} .
docker push ${{ secrets.ECR_REGISTRY }}/app:staging-${{ github.sha }}
- name: ECSデプロイ(ステージング)
run: |
aws ecs update-service \
--cluster staging-cluster \
--service app-service \
--force-new-deployment
deploy-production:
if: github.ref == 'refs/heads/main'
needs: [test, security-scan]
runs-on: ubuntu-latest
environment:
name: production
url: https://app.example.com
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ap-northeast-1
- name: ECRにプッシュ
run: |
aws ecr get-login-password | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
docker build -t ${{ secrets.ECR_REGISTRY }}/app:${{ github.sha }} .
docker push ${{ secrets.ECR_REGISTRY }}/app:${{ github.sha }}
- name: ECSデプロイ(プロダクション)
run: |
aws ecs update-service \
--cluster production-cluster \
--service app-service \
--force-new-deployment
ブルー/グリーンデプロイの実装
claude "ECS Fargateのブルー/グリーンデプロイをGitHub Actionsで実装して。
CodeDeployを使って、トラフィックの段階的切り替えを行う構成で。"
blue-green-deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ap-northeast-1
- name: タスク定義の更新
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: app
image: ${{ secrets.ECR_REGISTRY }}/app:${{ github.sha }}
- name: CodeDeployでブルー/グリーンデプロイ
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: app-service
cluster: production-cluster
codedeploy-appspec: appspec.yaml
codedeploy-application: app-deploy
codedeploy-deployment-group: app-deploy-group
wait-for-service-stability: true
CI失敗時の自動診断と修正
Claude Codeによるエラー解析
CIが失敗した場合、Claude Codeにログを渡して原因分析と修正を自動化できます。
# CI失敗ログをClaude Codeに渡す
gh run view --log-failed | claude "このCI失敗ログを分析して:
1. 失敗の根本原因を特定
2. 修正方法を具体的に提案
3. 修正コードを生成して適用"
自動修正ワークフロー
auto-fix:
if: failure()
needs: [lint-and-typecheck]
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
# Lint自動修正
- name: ESLint自動修正
run: pnpm lint --fix || true
# Prettier自動フォーマット
- name: Prettier自動フォーマット
run: pnpm format || true
# 変更をコミット
- name: 自動修正をコミット
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "fix: CI自動修正(lint/format)"
branch: ${{ github.head_ref }}
Reusable Workflowsで再利用性を高める
共通ワークフローのテンプレート化
複数のリポジトリで同じCI/CDパターンを使う場合、Reusable Workflowsが有効です。
claude "以下の要件でReusable Workflowを作成して:
- Node.jsプロジェクト共通のCI(lint, test, build)
- 入力パラメータでNode.jsバージョンとパッケージマネージャーを指定可能
- 出力としてビルドアーティファクトとカバレッジレポートを返す"
# .github/workflows/reusable-ci.yml
name: Reusable CI
on:
workflow_call:
inputs:
node-version:
description: 'Node.js version'
required: false
default: '20'
type: string
package-manager:
description: 'Package manager (npm, pnpm, yarn)'
required: false
default: 'pnpm'
type: string
run-e2e:
description: 'Run E2E tests'
required: false
default: false
type: boolean
secrets:
CODECOV_TOKEN:
required: false
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
if: inputs.package-manager == 'pnpm'
uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.package-manager }}
- name: Install dependencies
run: |
if [ "${{ inputs.package-manager }}" = "pnpm" ]; then
pnpm install --frozen-lockfile
elif [ "${{ inputs.package-manager }}" = "yarn" ]; then
yarn install --frozen-lockfile
else
npm ci
fi
- run: ${{ inputs.package-manager }} run lint
- run: ${{ inputs.package-manager }} run typecheck
- run: ${{ inputs.package-manager }} run test -- --coverage
- run: ${{ inputs.package-manager }} run build
呼び出し側のワークフロー
# .github/workflows/ci.yml
name: CI
on:
pull_request:
branches: [main]
jobs:
ci:
uses: your-org/.github/.github/workflows/reusable-ci.yml@main
with:
node-version: '20'
package-manager: 'pnpm'
run-e2e: true
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
モノレポでのCI/CD最適化
変更検知と選択的実行
モノレポでは、変更があったパッケージだけをテスト・ビルドする仕組みが重要です。
claude "Turborepoモノレポで、変更のあったパッケージだけCIを実行する
GitHub Actionsワークフローを作成して。
パッケージ構成: apps/web, apps/api, packages/ui, packages/utils"
detect-changes:
runs-on: ubuntu-latest
outputs:
web: ${{ steps.filter.outputs.web }}
api: ${{ steps.filter.outputs.api }}
ui: ${{ steps.filter.outputs.ui }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
web:
- 'apps/web/**'
- 'packages/**'
api:
- 'apps/api/**'
- 'packages/**'
ui:
- 'packages/ui/**'
test-web:
needs: detect-changes
if: needs.detect-changes.outputs.web == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pnpm turbo test --filter=web...
test-api:
needs: detect-changes
if: needs.detect-changes.outputs.api == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pnpm turbo test --filter=api...
通知とモニタリングの統合
Slack / Discord通知の設定
claude "CIの結果をSlackに通知するステップを追加して。
成功時は緑、失敗時は赤のメッセージで、
コミット情報・実行時間・結果サマリーを含める"
notify:
if: always()
needs: [test, deploy-production]
runs-on: ubuntu-latest
steps:
- name: Slack通知
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,workflow
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? '#36a64f' : '#cc0000',
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: `*${{ github.workflow }}* ${{ job.status == 'success' && '✅ 成功' || '❌ 失敗' }}\n*リポジトリ:* ${{ github.repository }}\n*ブランチ:* ${{ github.ref_name }}\n*コミット:* ${{ github.event.head_commit.message }}`
}
}
]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SES現場での活用パターン
DevOps案件でのCI/CD構築
SES現場でDevOps・インフラエンジニアとして参画する際、CI/CDパイプラインの構築は頻出タスクです。Claude Codeを活用することで、以下の効率化が可能です。
| 作業内容 | 従来の所要時間 | Claude Code活用後 | 短縮率 |
|---|---|---|---|
| ワークフローYAML作成 | 4-8時間 | 30分-1時間 | 85%短縮 |
| テスト統合 | 2-4時間 | 30分 | 80%短縮 |
| セキュリティスキャン設定 | 3-6時間 | 1時間 | 75%短縮 |
| デプロイフロー構築 | 8-16時間 | 2-3時間 | 75%短縮 |
| エラー診断・修正 | 1-3時間/回 | 15分/回 | 85%短縮 |
実践プロンプトテンプレート
新規プロジェクトのCI/CD一括セットアップ:
claude "このプロジェクトに以下のCI/CDを一括セットアップして:
1. PR時のCI:
- lint, typecheck, unit test, e2e test
- セキュリティスキャン(npm audit, CodeQL)
- PRコメントにテスト結果とカバレッジ
2. マージ時のCD:
- ステージング自動デプロイ(developブランチ)
- プロダクションデプロイ(mainブランチ、手動承認)
3. 定期実行:
- 依存関係の脆弱性チェック(週次)
- Renovateによる依存関係更新
4. 最適化:
- キャッシュ戦略(依存関係、ビルド出力)
- 並列実行とジョブ依存関係
- concurrencyによる重複実行防止"
既存CI/CDの改善:
claude ".github/workflows/以下の全ワークフローを分析して:
1. 実行時間の改善点を洗い出し
2. キャッシュの最適化
3. セキュリティのベストプラクティス適用
4. 冗長な設定の統合
改善案をまとめて、修正を適用して"
SES DevOps案件の単価相場
2026年現在、GitHub Actionsを使ったCI/CD構築・運用のスキルを持つエンジニアの需要は高まっています。
| スキルレベル | 月単価相場 | 求められるスキル |
|---|---|---|
| ジュニア | 50-65万円 | 基本的なワークフロー作成、テスト統合 |
| ミドル | 65-85万円 | マトリクスビルド、セキュリティ統合、IaC連携 |
| シニア | 85-110万円 | 大規模モノレポCI/CD、ブルーグリーンデプロイ、コスト最適化 |
トラブルシューティング
よくあるCI/CD問題と解決法
1. キャッシュが効かない
claude "GitHub Actionsのキャッシュが効かない。
以下のワークフローを確認して原因を特定して:
$(cat .github/workflows/ci.yml)"
よくある原因:
- キャッシュキーのハッシュ対象ファイルが不適切
restore-keysの設定漏れ- キャッシュサイズ上限(10GB)超過
2. シークレットが参照できない
# フォークからのPRではシークレットにアクセスできない
claude "フォークからのPRでもセキュリティを保ちつつCIを実行できる
ワークフローに修正して"
3. タイムアウトが発生する
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30 # デフォルト360分は長すぎる
steps:
- name: E2Eテスト
run: pnpm test:e2e
timeout-minutes: 15 # ステップ単位でも設定可能
ベストプラクティスまとめ
Claude CodeとGitHub Actionsを組み合わせる際のベストプラクティスをまとめます。
ワークフロー設計のポイント
- concurrencyで重複実行を防止 — 同じブランチの古いCIはキャンセル
- fail-fastの適切な設定 — マトリクスビルドでは
falseにして全パターンの結果を取得 - timeout-minutesの明示 — 暴走を防ぐために必ず設定
- if条件で不要なジョブをスキップ — パス変更検知と組み合わせる
- Reusable Workflowsで共通化 — 組織内で統一されたCIパイプラインを維持
セキュリティのポイント
- 最小権限の原則 —
permissionsを必要最小限に設定 - OIDC認証の活用 — 長期的なアクセスキーの代わりにOIDCでAWSに接続
- Dependabotの有効化 — 依存関係の自動更新
- シークレットの適切な管理 — Environment secretsで環境ごとに分離
まとめ:Claude Code × GitHub ActionsでDevOpsを加速する
Claude CodeとGitHub Actionsの連携は、CI/CDパイプラインの構築・運用を劇的に効率化します。
本記事のポイント:
- ワークフローYAMLの自動生成で構築時間を大幅短縮
- テスト・セキュリティ・デプロイの一気通貫パイプラインが簡単に構築可能
- Reusable Workflowsとモノレポ最適化で組織全体のCI/CDを標準化
- SES現場でのDevOps案件で即活用できるスキルセット
AIツールを活用したCI/CD構築のスキルは、2026年のSES市場で高い需要があります。Claude Codeを使いこなして、DevOpsエンジニアとしての市場価値を高めましょう。