CI/CDパイプライン構築
GitHub Actionsを使ったCI/CDパイプラインをAIと一緒に構築します。テスト、ビルド、デプロイを自動化しましょう。
CI/CDとは
CI(継続的インテグレーション)
コード変更時に自動でテスト・ビルドを実行
CD(継続的デリバリー)
テスト通過後に自動でデプロイ
GitHub Actions の構築
AIへの指示
Next.js + FastAPI プロジェクトのCI/CDパイプラインを GitHub Actionsで構築してください。 【要件】 - PR時: lint、テスト、型チェック - main マージ時: 上記 + ビルド + Vercel/Railwayへデプロイ - キャッシュを活用して高速化 フロントエンドとバックエンドは別ジョブで並列実行してください。
.github/workflows/ci.yml
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- run: cd frontend && npm ci
- run: cd frontend && npm run lint
- run: cd frontend && npm run type-check
- run: cd frontend && npm test
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- run: cd backend && pip install -r requirements.txt
- run: cd backend && pytest
deploy:
needs: [frontend, backend]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Vercel / Railway へのデプロイ
シークレットの管理
環境変数やAPIキーはGitHubのSecretsで管理
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
API_KEY: ${{ secrets.API_KEY }}
まとめ
- ✓自動テスト - PR時に必ず実行
- ✓並列実行 - フロント/バックを同時に
- ✓キャッシュ活用 - 依存関係をキャッシュして高速化