This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Workflow | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| # 0. バージョン取得 | |
| extract-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| node_version: ${{ steps.extract-versions.outputs.node_version }} | |
| pnpm_version: ${{ steps.extract-versions.outputs.pnpm_version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Extract versions from .prototools | |
| id: extract-versions | |
| run: | | |
| NODE_VERSION=$(grep 'node' .prototools | cut -d '"' -f2) | |
| PNPM_VERSION=$(grep 'pnpm' .prototools | cut -d '"' -f2) | |
| echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT | |
| echo "pnpm_version=$PNPM_VERSION" >> $GITHUB_OUTPUT | |
| echo $NODE_VERSION | |
| echo $PNPM_VERSION | |
| # 1. Turboによる変更検知 | |
| turbo: | |
| needs: extract-versions | |
| name: Detect Affected Apps | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_frontend_changed: ${{ steps.ex5.outputs.is_frontend_changed }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Cache turbo build setup | |
| uses: actions/cache@v4 | |
| with: | |
| path: .turbo | |
| key: ${{ runner.os }}-turbo-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-turbo- | |
| - name: pnpm v | |
| run: echo ${{ needs.extract-versions.outputs.pnpm_version }} | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ needs.extract-versions.outputs.pnpm_version }} | |
| - name: node v | |
| run: echo ${{ needs.extract-versions.outputs.node_version }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ needs.extract-versions.outputs.node_version }} | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Prune unnecessary packages | |
| run: pnpm prune | |
| # buildが必要なappを特定(turboのキャッシュを使う) | |
| - name: Run Turbo dry-run | |
| id: ex5 | |
| run: | | |
| pnpm turbo run build --dry-run=json > turbo-dry-run.json | |
| FRONTEND_CACHE_STATUS=$(cat turbo-dry-run.json | jq '.tasks[] | select(.package == "frontend")' | jq -r '.cache.status') | |
| if [ $FRONTEND_CACHE_STATUS = "HIT" ]; then | |
| echo "is_frontend_changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_frontend_changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| echo $FRONTEND_CACHE_STATUS | |
| # 2. Next.jsのテストとビルド | |
| build-next: | |
| if: ${{ needs.turbo.outputs.is_frontend_changed == 'true' }} | |
| name: Test and Build Next.js App | |
| runs-on: ubuntu-latest | |
| needs: [extract-versions, turbo] | |
| steps: | |
| - name: env | |
| run: echo ${{ needs.turbo.outputs.is_frontend_changed }} | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ needs.extract-versions.outputs.pnpm_version }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ needs.extract-versions.outputs.node_version }} | |
| cache: pnpm | |
| - name: Cache turbo build setup | |
| uses: actions/cache@v4 | |
| with: | |
| path: .turbo | |
| key: ${{ runner.os }}-turbo-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-turbo- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Prune unnecessary packages | |
| run: node -v | |
| - name: Pull Vercel Environment Information | |
| working-directory: apps/web | |
| run: pnpm vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Build | |
| run: pnpm turbo run vercel-gha-build --filter=web | |
| # 4. Next.jsのデプロイ (Vercel) | |
| deploy-next: | |
| if: github.event_name == 'push' | |
| name: Deploy Next.js App to Vercel | |
| runs-on: ubuntu-latest | |
| needs: [extract-versions, build-next] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: ${{ needs.extract-versions.outputs.pnpm_version }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ needs.extract-versions.outputs.node_version }} | |
| cache: pnpm | |
| - name: Cache turbo build setup | |
| uses: actions/cache@v4 | |
| with: | |
| path: .turbo | |
| key: ${{ runner.os }}-turbo-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-turbo- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Pull Vercel Environment Information | |
| run: pnpm vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Build | |
| run: pnpm turbo run vercel-gha-build --filter=web | |
| # - name: Cp n | |
| # run: cp -a apps/web/.next/. .next/ | |
| # - name: Cp v | |
| # run: cp -a apps/web/.vercel/. .vercel/ | |
| - name: Deploy Project Artifacts to Vercel | |
| working-directory: apps/web | |
| run: pnpm vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} |