cicd-automation について
CI/CD ワークフロー、テスト、品質チェック、リリースやデプロイの自動化を設定するスキルです。リポジトリのパイプラインを構成する開発者向けに、GitHub Actions のパターンを示します。
主な機能
- 01GitHub Actions ワークフローの設定
- 02プッシュとプルリクエストのトリガー
- 03テストとカバレッジの設定
- 04依存関係のキャッシュとマトリックステスト
- 05リリース公開と Docker イメージのビルド
活用シーン
- 01コード変更時のテスト実行
- 02OS と Python バージョンをまたぐテスト
- 03リリース時のパッケージ公開
- 04Docker イメージのビルドとプッシュ
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ autumnsgrove/ lattice --skill cicd-automationインストール後、Claude Code で/cicd-automationを入力して読み込まれたか確認します。
詳細
CI/CD 自動化スキル
有効化するタイミング
以下の場合にこのスキルを有効にします:
- GitHub Actions ワークフローを作成するとき
- 自動テストを設定するとき
- デプロイパイプラインを構成するとき
- CI にコード品質チェックを追加するとき
- リリースプロセスを自動化するとき
クイックスタートワークフロー
.github/workflows/ci.yml を作成します:
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Add UV to PATH
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Install dependencies
run: uv sync
- name: Run tests
run: uv run pytest tests/ -v --cov=src
- name: Lint with Ruff
run: uv run ruff check src/ tests/
- name: Check formatting
run: uv run black --check src/ tests/
ワークフローの構成
.github/
└── workflows/
├── ci.yml # Tests and linting
├── release.yml # Package publishing
└── deploy.yml # Deployment
一般的なトリガー
# Every push and PR
on: [push, pull_request]
# Specific branches
on:
push:
branches: [main]
pull_request:
branches: [main]
# Manual trigger
on: workflow_dispatch
# Scheduled (cron)
on:
schedule:
- cron: '0 0 * * *' # Daily at midnight
カバレッジを含むテスト
- name: Run tests with coverage
run: |
uv run pytest tests/ \
--cov=src \
--cov-report=xml \
--cov-report=term-missing \
--junitxml=junit.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
fail_ci_if_error: true
複数環境でのテスト
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Run tests
run: uv run pytest tests/
依存関係のキャッシュ
- name: Cache UV dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync
ワークフローでのシークレット
- name: Deploy
env:
API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: uv run python deploy.py
シークレットの設定:
- リポジトリの Settings → Secrets and variables → Actions を開きます
- "New repository secret" をクリックします
- 名前と値を追加します
PyPI への公開
name: Publish
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Build package
run: uv build
- name: Publish to PyPI
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish --token $UV_PUBLISH_TOKEN
Docker イメージのビルド
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: user/app:latest,user/app:${{ github.sha }}
ステータスバッジ
README に追加します:

[](https://codecov.io/gh/username/repo)
ベストプラクティス
実施すること ✅
- すべてのプッシュでテストを実行する
- 速度向上のために依存関係をキャッシュする
- クロスプラットフォームテストにはマトリックスを使用する
- CI ワークフローと CD ワークフローを分ける
- 機密データにはシークレットを使用する
避けること ❌
- CI でのリンティングを省略する
- テストの失敗を無視する
- コード内にシークレットを保存する
- 不要なジョブを実行する
CI/CD を使用するタイミング
まずは以下から始めます:
- すべてのプッシュでテストを実行する
- コード品質チェック(lint、format)
- セキュリティスキャン
後から追加します:
- デプロイの自動化
- Docker のビルド
- ドキュメントの生成
関連リソース
完全なドキュメント(以下を含む)は AgentUsage/ci_cd_patterns.md を参照してください:
- 複雑なワークフローの例
- 環境固有の設定
- 高度なキャッシュ戦略
- デプロイパターン
コメント
Markdown 対応