|
| 1 | +name: Build and Deploy to Vercel |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: [main, master] |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + if: github.event.pull_request.merged == true |
| 10 | + |
| 11 | + name: "Build Application" |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout Code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: "20" |
| 22 | + |
| 23 | + - name: Install pnpm |
| 24 | + uses: pnpm/action-setup@v2 |
| 25 | + with: |
| 26 | + version: 8 |
| 27 | + run_install: false |
| 28 | + |
| 29 | + - name: Get pnpm store directory |
| 30 | + id: pnpm-cache |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 34 | +
|
| 35 | + - name: Setup pnpm cache |
| 36 | + uses: actions/cache@v3 |
| 37 | + with: |
| 38 | + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
| 39 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-pnpm-store- |
| 42 | +
|
| 43 | + - name: Install dependencies |
| 44 | + run: pnpm install --frozen-lockfile |
| 45 | + |
| 46 | + # Set up environment variables from GitHub secrets |
| 47 | + - name: Set up environment variables |
| 48 | + run: | |
| 49 | + # Create .env file |
| 50 | + touch .env |
| 51 | + # Add all secrets that start with "NEXT_PUBLIC_" to .env file |
| 52 | + for secret in $(compgen -A variable | grep NEXT_PUBLIC_); do |
| 53 | + echo "$secret=${!secret}" >> .env |
| 54 | + done |
| 55 | +
|
| 56 | + env: |
| 57 | + # Add other environment variables as needed |
| 58 | + CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }} |
| 59 | + CONVEX_DEPLOYMENT: ${{ secrets.CONVEX_DEPLOYMENT }} |
| 60 | + |
| 61 | + - name: Build |
| 62 | + run: pnpm build |
| 63 | + |
| 64 | + # Upload the build artifacts to be used by the deploy job |
| 65 | + - name: Upload build artifacts |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + with: |
| 68 | + name: build-output |
| 69 | + path: | |
| 70 | + .next |
| 71 | + public |
| 72 | + package.json |
| 73 | + pnpm-lock.yaml |
| 74 | + next.config.js |
| 75 | + .env |
| 76 | +
|
| 77 | + deploy: |
| 78 | + name: Deploy Application to Vercel |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: build |
| 81 | + environment: production |
| 82 | + steps: |
| 83 | + - name: Checkout Code |
| 84 | + uses: actions/checkout@v4 |
| 85 | + |
| 86 | + # Download build artifacts from previous job |
| 87 | + - name: Download build artifacts |
| 88 | + uses: actions/download-artifact@v3 |
| 89 | + with: |
| 90 | + name: build-output |
| 91 | + |
| 92 | + - name: Setup Node.js |
| 93 | + uses: actions/setup-node@v4 |
| 94 | + with: |
| 95 | + node-version: "20" |
| 96 | + |
| 97 | + - name: Install pnpm |
| 98 | + uses: pnpm/action-setup@v2 |
| 99 | + with: |
| 100 | + version: 8 |
| 101 | + run_install: false |
| 102 | + |
| 103 | + # Install Vercel CLI |
| 104 | + - name: Install Vercel CLI |
| 105 | + run: npm install --global vercel@latest |
| 106 | + |
| 107 | + # Deploy to Vercel |
| 108 | + - name: Deploy to Vercel Production |
| 109 | + run: vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --confirm --env-file .env |
| 110 | + env: |
| 111 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 112 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
0 commit comments