Communityコーディング&開発github.com

CI/CDと自動化

CI/CDパイプラインのセットアップを自動化します。ビルド・デプロイパイプラインの設定や変更時、品質ゲートの自動化、テストランナーのCI設定、デプロイ戦略の確立が必要な場合に使用します。

CDと自動化 とは?

このスキルは、品質ゲートを自動化することで、テスト、リント、型チェック、ビルドを通過せずに本番環境に変更が届くのを防ぐCI/CDパイプラインの設計と実装を支援します。Shift Leftの原則に基づき、パイプラインの上流で問題を早期に発見し、小さなバッチと頻繁なリリースでリスクを低減します。主にGitHub Actionsを用いた設定例を提供し、リント、型チェック、単体テスト、結合テスト、E2Eテスト、セキュリティ監査、バンドルサイズチェックからなる品質ゲートパイプラインを構築します。また、プレビューデプロイ、フィーチャーフラグ、段階的ロールアウト、ロールバック計画などのデプロイ戦略や、CIの最適化手法(キャッシュ、並列実行、パスフィルターなど)もカバーしています。さらに、CIの失敗をAIエージェントにフィードバックするループを構築し、開発サイクルを高速化します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/ci-cd-and-automation

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

CDと自動化 は何をしますか?

概要

テスト、リント、型チェック、ビルドをすべてパスしない限り、本番環境に変更が届かないように品質ゲートを自動化します。CI/CDは他のすべてのスキルを強制する仕組みであり、人間やエージェントが見逃す問題を、すべての変更に対して一貫してキャッチします。

Shift Left(早期発見・早期対策): パイプラインのできるだけ上流で問題を発見します。リンティングで見つかったバグの修正には数分しかかかりませんが、同じバグが本番環境で発見されると数時間かかります。静的解析はテストの前に、テストはステージングの前に、ステージングは本番の前に配置するなど、チェックを上流に移動させます。

高速化=安全性向上: バッチサイズを小さくしてリリース頻度を上げることで、リスクは増加せずむしろ減少します。3つの変更を含むデプロイは、30の変更を含むデプロイよりもデバッグが容易です。頻繁なリリースはリリースプロセス自体への信頼を高めます。

使用するタイミング

  • 新しいプロジェクトのCIパイプラインを設定するとき
  • 自動チェックを追加または変更するとき
  • デプロイパイプラインを設定するとき
  • 変更が自動検証をトリガーするべきとき
  • CIの失敗をデバッグするとき

品質ゲートパイプライン

すべての変更はマージ前にこれらのゲートを通過します:

プルリクエスト作成
    │
    ▼
┌─────────────────┐
│   リントチェック   │  eslint, prettier
│   ↓ 合格         │
│   型チェック       │  tsc --noEmit
│   ↓ 合格         │
│   単体テスト       │  jest/vitest
│   ↓ 合格         │
│   ビルド          │  npm run build
│   ↓ 合格         │
│   結合テスト       │  API/DBテスト
│   ↓ 合格         │
│   E2E(任意)     │  Playwright/Cypress
│   ↓ 合格         │
│   セキュリティ監査  │  npm audit
│   ↓ 合格         │
│   バンドルサイズ    │  バンドルサイズチェック
└─────────────────┘
    │
    ▼
  レビュー準備完了

どのゲートもスキップできません。 リントが失敗したらリントを修正してください。ルールを無効にしてはいけません。テストが失敗したらコードを修正し、テストをスキップしてはいけません。

GitHub Actionsの設定

基本的なCIパイプライン

# .github/workflows/ci.yml
name: CI

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'

      - name: 依存関係のインストール
        run: npm ci

      - name: リント
        run: npm run lint

      - name: 型チェック
        run: npx tsc --noEmit

      - name: テスト
        run: npm test -- --coverage

      - name: ビルド
        run: npm run build

      - name: セキュリティ監査
        run: npm audit --audit-level=high

データベース結合テストを含む場合

  integration:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_DB: testdb
          POSTGRES_USER: ci_user
          POSTGRES_PASSWORD: ${{ secrets.CI_DB_PASSWORD }}
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci
      - name: マイグレーションの実行
        run: npx prisma migrate deploy
        env:
          DATABASE_URL: postgresql://ci_user:${{ secrets.CI_DB_PASSWORD }}@localhost:5432/testdb
      - name: 結合テスト
        run: npm run test:integration
        env:
          DATABASE_URL: postgresql://ci_user:${{ secrets.CI_DB_PASSWORD }}@localhost:5432/testdb

注: CI専用のテストデータベースであっても、認証情報はハードコーディングせずにGitHub Secretsを使用してください。これにより良い習慣が身につき、テスト用の認証情報が他のコンテキストで誤って使用されるのを防ぎます。

E2Eテスト

  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci
      - name: Playwrightのインストール
        run: npx playwright install --with-deps chromium
      - name: ビルド
        run: npm run build
      - name: E2Eテストの実行
        run: npx playwright test
      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: playwright-report
          path: playwright-report/

CIの失敗をエージェントにフィードバックする

AIエージェントを使ったCIの真価はフィードバックループにあります。CIが失敗したとき:

CI失敗
    │
    ▼
失敗出力をコピー
    │
    ▼
エージェントに渡す:
「CIパイプラインが次のエラーで失敗しました:
[具体的なエラーを貼り付け]
問題を修正し、再度プッシュする前にローカルで確認してください。」
    │
    ▼
エージェントが修正 → プッシュ → CIが再度実行

重要なパターン:

リント失敗 → エージェントが `npm run lint --fix` を実行してコミット
型エラー  → エージェントがエラー箇所を読み、型を修正
テスト失敗 → エージェントがデバッグおよびエラー回復スキルに従う
ビルドエラー → エージェントが設定と依存関係を確認

デプロイ戦略

プレビューデプロイ

すべてのPRに手動テスト用のプレビューデプロイを提供します:

# PRでプレビューデプロイ(Vercel/Netlify等)
deploy-preview:
  runs-on: ubuntu-latest
  if: github.event_name == 'pull_request'
  steps:
    - uses: actions/checkout@v4
    - name: プレビューデプロイ
      run: npx vercel --token=${{ secrets.VERCEL_TOKEN }}

フィーチャーフラグ

フィーチャーフラグはデプロイとリリースを分離します。不完全またはリスクのある機能をフラグの背後にデプロイすることで、以下のことが可能になります:

  • コードを有効にせずに出荷する。 準備ができたら有効にするため、早期にmainにマージします。
  • 再デプロイせずにロールバックする。 コードを元に戻す代わりにフラグを無効にします。
  • 新機能をカナリアリリースする。 まず1%のユーザーに有効にし、次に10%、そして100%へと段階的に広げます。
  • A/Bテストを実行する。 機能がある場合とない場合の動作を比較します。
// シンプルなフィーチャーフラグパターン
if (featureFlags.isEnabled('new-checkout-flow', { userId })) {
  return renderNewCheckout();
}
return renderLegacyCheckout();

フラグのライフサイクル: 作成 → テスト用に有効化 → カナリアリリース → フルロールアウト → フラグとデッドコードの削除。永遠に残るフラグは技術負債になります。作成時にクリーンアップ日を設定しましょう。

段階的ロールアウト

PRがmainにマージ
    │
    ▼
  ステージングデプロイ(自動)
    │ 手動確認
    ▼
  本番デプロイ(手動トリガーまたはステージング後に自動)
    │
    ▼
  エラーモニタリング(15分間のウィンドウ)
    │
    ├── エラー検出 → ロールバック
    └── 問題なし → 完了

ロールバック計画

すべてのデプロイは元に戻せるようにする必要があります:

# 手動ロールバックワークフロー
name: Rollback
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'ロールバック先のバージョン'
        required: true

jobs:
  rollback:
    runs-on: ubuntu-latest
    steps:
      - name: デプロイのロールバック
        run: |
          # 指定された以前のバージョンをデプロイ
          npx vercel rollback ${{ inputs.version }}

環境変数管理

.env.example       → コミット(開発者向けテンプレート)
.env                → コミットしない(ローカル開発用)
.env.test           → コミット(テスト環境、実際のシークレットは含まない)
CIのシークレット    → GitHub Secrets / vaultに保存
本番シークレット    → デプロイプラットフォーム / vaultに保存

CIは本番のシークレットを持つべきではありません。CIテスト用には別のシークレットを使用してください。

CIを超えた自動化

Dependabot / Renovate

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule:
      interval: weekly
    open-pull-requests-limit: 5

ビルド担当者(Build Cop)の役割

CIをグリーンに保つ責任者を指名します。ビルドが壊れた場合、その原因を作った人ではなく、ビルド担当者が修正または元に戻す責任を負います。これにより、誰かが直してくれるだろうと皆が思い込み、壊れたビルドが蓄積されるのを防ぎます。

PRチェック

  • 必須レビュー: マージ前に少なくとも1件の承認が必要
  • 必須ステータスチェック: マージ前にCIが成功する必要がある
  • ブランチ保護: mainへのフォースプッシュを禁止
  • 自動マージ: すべてのチェックが成功し承認されれば自動的にマージ

CIの最適化

パイプラインが10分を超える場合、以下の戦略を効果の高い順に適用します:

CIパイプラインが遅い?
├── 依存関係をキャッシュ
│   └── node_modulesにactions/cacheまたはsetup-nodeのcacheオプションを使用
├── ジョブを並列実行
│   └── リント、型チェック、テスト、ビルドを別々の並列ジョブに分割
├── 変更があったものだけ実行
│   └── パスフィルターを使用して無関係なジョブをスキップ(例:ドキュメントのみのPRでe2eをスキップ)
├── マトリックスビルドを使用
│   └── テストスイートを複数のランナーに分割
├── テストスイートを最適化
│   └── クリティカルパスから遅いテストを削除し、代わりにスケジュール実行する
└── より大きなランナーを使用
    └── GitHubホストの大規模ランナー、またはCPU負荷の高いビルドにはセルフホストランナー

例:キャッシュと並列処理

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npm run lint

  typecheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npx tsc --noEmit

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: 'npm' }
      - run: npm ci
      - run: npm test -- --coverage

よくある言い訳

言い訳現実
「CIが遅すぎる」パイプラインを最適化してください(下記の「CIの最適化」参照)。スキップしてはいけません。5分のパイプラインで何時間ものデバッグを防げます。
「この変更は些細なものなのでCIをスキップ」些細な変更でもビルドを壊すことがあります。それに、CIは些細な変更に対しては高速です。
「テストがflakyなので再実行すればいい」Flakyなテストは実際のバグを隠し、全員の時間を無駄にします。flakyさを修正しましょう。
「CIは後で追加する」CIのないプロジェクトは壊れた状態が蓄積されます。初日から設定しましょう。
「手動テストで十分」手動テストはスケールせず、再現性もありません。可能なものは自動化しましょう。

レッドフラグ

  • プロジェクトにCIパイプラインがない
  • CIの失敗が無視または抑制されている
  • パイプラインを通すためにテストがCIで無効化されている
  • ステージングでの確認なしに本番デプロイが行われている
  • ロールバックメカニズムがない
  • シークレットがコードやCI設定ファイルに保存されている(シークレットマネージャーではない)
  • CI時間が長く、最適化の努力がされていない

確認リスト

CIを設定または変更した後:

  • すべての品質ゲートが存在する(リント、型、テスト、ビルド、監査)
  • すべてのPRとmainへのプッシュでパイプラインが実行される
  • 失敗がマージをブロックする(ブランチ保護が設定されている)
  • CI結果が開発ループにフィードバックされる
  • シークレットがシークレットマネージャーに保存され、コード内にはない
  • デプロイにロールバックメカニズムがある
  • テストスイートのパイプラインが10分以内に完了する

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

関連スキル