mcpField
B
building-ci-pipelines

building-ci-pipelines

github.com/ancolemanクラウド・DevOps52570 回インストール46 週間前に更新
リポジトリ

building-ci-pipelines について

GitHub Actions、GitLab CI、Argo Workflows、Jenkinsを使ったCIパイプライン設計を解説するスキルです。テストとビルドの自動化に加え、セキュリティ、モノレポ最適化、キャッシュ、並列実行を扱います。

主な機能

  1. 01CIプラットフォーム選定ガイド
  2. 02再利用可能なパイプラインパターン
  3. 03SLSA来歴証明とOIDCセキュリティ
  4. 04モノレポ最適化と依存関係キャッシュ
  5. 05並列ジョブとテスト分割
  6. 06ワークフローの検証・生成スクリプト

活用シーン

  1. 01新規プロジェクトのCI設定
  2. 02モノレポのパイプライン実行時間短縮
  3. 03来歴証明付きイメージのビルド
  4. 04クロスプラットフォームテストの自動化

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/ancoleman/ai-design-components --skill building-ci-pipelines

インストール後、Claude Code で/building-ci-pipelinesを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

outputs.yaml
examples/github-actions-basic/
README.md
examples/github-actions-basic/.github/workflows/
ci.yml
examples/github-actions-monorepo/
README.md
turbo.json
examples/github-actions-monorepo/.github/workflows/
ci.yml
references/
caching-strategies.md
github-actions-patterns.md
monorepo-ci-strategies.md
slsa-security-framework.md
scripts/
validate_workflow.py

詳細

CI パイプラインの構築

目的

CI/CD パイプラインは、ソフトウェアのテスト、ビルド、デプロイを自動化します。このスキルでは、GitHub Actions、GitLab CI、Argo Workflows、Jenkins にわたって、堅牢で安全かつ効率的なパイプラインを構築するためのパターンを紹介します。主な対象領域は、サプライチェーンセキュリティ(SLSA)、モノレポの最適化、キャッシュ、並列化です。

このスキルを使う場面

次の場合に呼び出します:

  • 新しいプロジェクトで継続的インテグレーションを設定するとき
  • 自動テストのワークフローを実装するとき
  • セキュリティプロベナンス付きのコンテナイメージをビルドするとき
  • 遅い CI パイプラインを最適化するとき(特にモノレポ)
  • SLSA サプライチェーンセキュリティを実装するとき
  • マルチプラットフォームビルドを設定するとき
  • GitOps の自動化を設定するとき
  • レガシー CI システムから移行するとき

プラットフォームの選択

GitHub ホスト → GitHub Actions(SLSA ネイティブ対応、10K 以上のアクション、OIDC) GitLab ホスト → GitLab CI(親子パイプライン、組み込みのセキュリティ機能) Kubernetes → Argo Workflows(DAG ベース、イベント駆動) レガシー → Jenkins(可能であれば移行)

プラットフォームの比較
機能GitHub ActionsGitLab CIArgoJenkins
使いやすさ⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
SLSAネイティブ手動良好手動
モノレポ良好優秀手動プラグイン

クイックスタートパターン

パターン 1:基本的な CI(Lint → Test → Build)
# GitHub Actions
name: CI
on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run lint

  test:
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run build
パターン 2:マトリックス戦略(マルチプラットフォーム)
test:
  runs-on: ${{ matrix.os }}
  strategy:
    matrix:
      os: [ubuntu-latest, windows-latest, macos-latest]
      node-version: [18, 20, 22]
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm test

9 個のジョブ(3 OS × 3 バージョン)を並列実行します。逐次実行なら 45 分かかるところ、5 分で完了します。

パターン 3:モノレポでの影響範囲検出(Turborepo)
build:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Required for affected detection

    - uses: actions/setup-node@v4
      with:
        node-version: 20

    - name: Build affected
      run: npx turbo run build --filter='...[origin/main]'
      env:
        TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
        TURBO_TEAM: ${{ vars.TURBO_TEAM }}

モノレポでは CI の所要時間を 60~80%削減できます。

パターン 4:SLSA レベル 3 のプロベナンス
name: SLSA Build
on:
  push:
    tags: ['v*']

permissions:
  id-token: write
  contents: read
  packages: write

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      digest: ${{ steps.build.outputs.digest }}
    steps:
      - uses: actions/checkout@v4
      - name: Build container
        id: build
        uses: docker/build-push-action@v5
        with:
          push: true
          tags: ghcr.io/${{ github.repository }}:${{ github.sha }}

  provenance:
    needs: build
    permissions:
      id-token: write
      actions: read
      packages: write
    uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
    with:
      image: ghcr.io/${{ github.repository }}
      digest: ${{ needs.build.outputs.digest }}
      registry-username: ${{ github.actor }}
    secrets:
      registry-password: ${{ secrets.GITHUB_TOKEN }}

検証:

cosign verify-attestation --type slsaprovenance \
  --certificate-identity-regexp "^https://github.com/slsa-framework" \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  ghcr.io/myorg/myapp@sha256:abcd...
パターン 5:OIDC フェデレーション(認証情報なし)
deploy:
  runs-on: ubuntu-latest
  permissions:
    id-token: write
    contents: read
  steps:
    - uses: actions/checkout@v4

    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsRole
        aws-region: us-east-1

    - name: Deploy
      run: aws s3 sync ./dist s3://my-bucket

メリット:保存された認証情報が不要で、有効期間は 1 時間、完全な監査証跡を確保できます。

パターン 6:セキュリティスキャン
security:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - name: Gitleaks (secret detection)
      uses: gitleaks/gitleaks-action@v2

    - name: Snyk (vulnerability scan)
      uses: snyk/actions/node@master
      env:
        SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

    - name: SBOM generation
      uses: anchore/sbom-action@v0
      with:
        format: spdx-json
        output-file: sbom.spdx.json

キャッシュ

依存関係の自動キャッシュ
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: 'npm'  # Auto-caches ~/.npm
- run: npm ci

対応対象:npm、yarn、pnpm、pip、poetry、cargo、go

手動でのキャッシュ制御
- uses: actions/cache@v4
  with:
    path: |
      ~/.cargo/bin
      ~/.cargo/registry
      target/
    key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
    restore-keys: |
      ${{ runner.os }}-cargo-
マルチレイヤーキャッシュ(Nx)
- name: Nx Cloud (build outputs)
  run: npx nx affected -t build
  env:
    NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

- name: Vite Cache
  uses: actions/cache@v4
  with:
    path: '**/node_modules/.vite'
    key: vite-${{ hashFiles('package-lock.json') }}

- name: TypeScript Cache
  uses: actions/cache@v4
  with:
    path: '**/tsconfig.tsbuildinfo'
    key: tsc-${{ hashFiles('tsconfig.json') }}

結果:ビルド時間を 70~90%削減できます。

並列化

ジョブレベルの並列化
jobs:
  unit-tests:
    steps:
      - run: npm run test:unit

  integration-tests:
    steps:
      - run: npm run test:integration

  e2e-tests:
    steps:
      - run: npm run test:e2e

3 つすべてを同時に実行します。

テストのシャーディング
test:
  strategy:
    matrix:
      shard: [1, 2, 3, 4]
  steps:
    - run: npm test -- --shard=${{ matrix.shard }}/4

20 分のテストスイートを 5 分で実行できます(4 倍高速化)。

言語別の例

Python
test:
  strategy:
    matrix:
      python-version: ['3.10', '3.11', '3.12']
  steps:
    - uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - run: pipx install poetry
    - run: poetry install
    - run: poetry run ruff check .
    - run: poetry run mypy .
    - run: poetry run pytest --cov
Rust
test:
  strategy:
    matrix:
      os: [ubuntu-latest, windows-latest, macos-latest]
      rust: [stable, nightly]
  steps:
    - uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
        components: rustfmt, clippy
    - uses: Swatinem/rust-cache@v2
    - run: cargo fmt -- --check
    - run: cargo clippy -- -D warnings
    - run: cargo test
Go
test:
  steps:
    - uses: actions/setup-go@v5
      with:
        go-version: '1.23'
        cache: true
    - run: go mod verify
    - uses: golangci/golangci-lint-action@v4
    - run: go test -v -race -coverprofile=coverage.txt ./...
TypeScript
test:
  strategy:
    matrix:
      node-version: [18, 20, 22]
  steps:
    - uses: pnpm/action-setup@v3
      with:
        version: 8
    - uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'pnpm'
    - run: pnpm install --frozen-lockfile
    - run: pnpm run lint
    - run: pnpm run type-check
    - run: pnpm test

ベストプラクティス

セキュリティ

推奨事項:

  • 有効期間の長い認証情報の代わりに OIDC を使用する
  • アクションをコミット SHA に固定する:actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
  • 権限を制限する:permissions: { contents: read }
  • すべてのコミットでシークレットをスキャンする(Gitleaks)
  • リリース用の SLSA プロベナンスを生成する

避けるべきこと:

  • ログでシークレットを公開する
  • 検証せずに pull_request_target を使用する
  • 検証されていないサードパーティ製アクションを信頼する
パフォーマンス

推奨事項:

  • モノレポで影響範囲検出を使用する
  • 依存関係とビルド出力をキャッシュする
  • 独立したジョブを並列化する
  • 早期に失敗させる:strategy.fail-fast: true
  • リモートキャッシュを使用する(Turborepo/Nx Cloud)

避けるべきこと:

  • コミットのたびにすべてを再ビルドする
  • PR チェックで時間のかかるテストを実行する
  • 汎用的なキャッシュキーを使用する
デバッグ
# Enable debug logging
env:
  ACTIONS_STEP_DEBUG: true
  ACTIONS_RUNNER_DEBUG: true

# SSH into runner
- uses: mxschmitt/action-tmate@v3

高度なパターン

詳しいガイドは、以下のリファレンスを参照してください:

  • github-actions-patterns.md - 再利用可能なワークフロー、コンポジットアクション、マトリックス戦略、OIDC の設定
  • gitlab-ci-patterns.md - 親子パイプライン、動的生成、ランナーの設定
  • argo-workflows-guide.md - DAG テンプレート、アーティファクトの受け渡し、イベント駆動型トリガー
  • slsa-security-framework.md - SLSA レベル 1~4、プロベナンスの生成、cosign による検証
  • monorepo-ci-strategies.md - Turborepo/Nx/Bazel の影響範囲検出アルゴリズム
  • caching-strategies.md - マルチレイヤーキャッシュ、Docker の最適化、キャッシュの無効化
  • parallelization-patterns.md - テストのシャーディング、ジョブの依存関係、DAG の設計
  • secrets-management.md - AWS/GCP/Azure 向けの OIDC、Vault との統合、ローテーション

例

すぐに実行できるワークフロー:

  • examples/github-actions-basic/ - スターターテンプレート(lint/test/build)
  • examples/github-actions-monorepo/ - リモートキャッシュを使用する Turborepo
  • examples/github-actions-slsa/ - SLSA Level 3 の来歴
  • examples/gitlab-ci-monorepo/ - 親子関係の動的パイプライン
  • examples/argo-workflows-dag/ - ダイヤモンド DAG の並列化
  • examples/multi-language-matrix/ - クロスプラットフォームテスト

ユーティリティスクリプト

トークン不要で実行できます:

  • scripts/validate_workflow.py - YAML 構文とベストプラクティスを検証
  • scripts/generate_github_workflow.py - テンプレートからワークフローを生成
  • scripts/analyze_ci_performance.py - CI メトリクスを分析
  • scripts/setup_oidc_aws.py - AWS OIDC のセットアップを自動化

関連スキル

testing-strategies - テスト実行戦略(単体テスト、統合テスト、E2E) deploying-applications - デプロイの自動化と GitOps auth-security - シークレット管理と認証 observability - パイプラインの監視とアラート

コメント