refactor: Implement feature-sliced architecture for workflows, centra… #19
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: Deploy to GCP | |
| on: | |
| push: | |
| branches: | |
| - master | |
| env: | |
| PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
| REGION: asia-south1 | |
| BACKEND_REPO: backend-repo | |
| FRONTEND_REPO: frontend-repo | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| outputs: | |
| backend: ${{ steps.filter.outputs.backend }} | |
| frontend: ${{ steps.filter.outputs.frontend }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| backend: | |
| - 'backend/**' | |
| - '.github/workflows/deploy.yml' | |
| frontend: | |
| - 'frontend/**' | |
| - '.github/workflows/deploy.yml' | |
| test-backend: | |
| needs: changes | |
| if: needs.changes.outputs.backend == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install Dependencies | |
| working-directory: ./backend | |
| run: npm ci | |
| - name: Generate Prisma Client | |
| working-directory: ./backend | |
| run: npx prisma generate | |
| - name: Run Tests | |
| working-directory: ./backend | |
| run: NODE_OPTIONS="--experimental-vm-modules" npm test | |
| test-frontend: | |
| needs: changes | |
| if: needs.changes.outputs.frontend == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Install Dependencies | |
| working-directory: ./frontend | |
| run: npm ci | |
| - name: Run Tests | |
| working-directory: ./frontend | |
| run: npm test | |
| build-backend: | |
| needs: [changes, test-backend] | |
| if: needs.changes.outputs.backend == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: "read" | |
| id-token: "write" | |
| outputs: | |
| tag: ${{ steps.meta.outputs.TAG }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Build Tag Info | |
| id: meta | |
| run: echo "TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Google Auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| credentials_json: "${{ secrets.GCP_CREDENTIALS }}" | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker | |
| run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and Push Backend | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./backend | |
| push: true | |
| tags: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_REPO }}/backend:${{ steps.meta.outputs.TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-frontend: | |
| needs: [changes, test-frontend] | |
| if: needs.changes.outputs.frontend == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: "read" | |
| id-token: "write" | |
| outputs: | |
| tag: ${{ steps.meta.outputs.TAG }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Build Tag Info | |
| id: meta | |
| run: echo "TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Google Auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| credentials_json: "${{ secrets.GCP_CREDENTIALS }}" | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker | |
| run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and Push Frontend | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./frontend | |
| push: true | |
| build-args: | | |
| NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} | |
| tags: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_REPO }}/frontend:${{ steps.meta.outputs.TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy-backend: | |
| needs: build-backend | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: "read" | |
| id-token: "write" | |
| steps: | |
| - name: Google Auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| credentials_json: "${{ secrets.GCP_CREDENTIALS }}" | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Deploy Backend | |
| uses: google-github-actions/deploy-cloudrun@v3 | |
| with: | |
| service: workflow-backend | |
| image: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_REPO }}/backend:${{ needs.build-backend.outputs.tag }} | |
| region: ${{ env.REGION }} | |
| flags: --add-cloudsql-instances=${{ env.PROJECT_ID }}:${{ env.REGION }}:workflow-db --allow-unauthenticated --ingress=all | |
| env_vars: | | |
| DATABASE_URL=${{ secrets.DATABASE_URL }} | |
| NODE_ENV=production | |
| deploy-frontend: | |
| needs: build-frontend | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: "read" | |
| id-token: "write" | |
| steps: | |
| - name: Google Auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| credentials_json: "${{ secrets.GCP_CREDENTIALS }}" | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Deploy Frontend | |
| uses: google-github-actions/deploy-cloudrun@v3 | |
| with: | |
| service: workflow-frontend | |
| image: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_REPO }}/frontend:${{ needs.build-frontend.outputs.tag }} | |
| region: ${{ env.REGION }} |