feat: add build and deploy action #1
Workflow file for this run
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: Build and Deploy to Vercel | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [main, master] | |
| jobs: | |
| build: | |
| if: github.event.pull_request.merged == true | |
| name: "Build Application" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| run_install: false | |
| - name: Get pnpm store directory | |
| id: pnpm-cache | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
| - name: Setup pnpm cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| # Set up environment variables from GitHub secrets | |
| - name: Set up environment variables | |
| run: | | |
| # Create .env file | |
| touch .env | |
| # Add all secrets that start with "NEXT_PUBLIC_" to .env file | |
| for secret in $(compgen -A variable | grep NEXT_PUBLIC_); do | |
| echo "$secret=${!secret}" >> .env | |
| done | |
| env: | |
| # Add other environment variables as needed | |
| CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }} | |
| CONVEX_DEPLOYMENT: ${{ secrets.CONVEX_DEPLOYMENT }} | |
| - name: Build | |
| run: pnpm build | |
| # Upload the build artifacts to be used by the deploy job | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: build-output | |
| path: | | |
| .next | |
| public | |
| package.json | |
| pnpm-lock.yaml | |
| next.config.js | |
| .env | |
| deploy: | |
| name: Deploy Application to Vercel | |
| runs-on: ubuntu-latest | |
| needs: build | |
| environment: production | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| # Download build artifacts from previous job | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: build-output | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| run_install: false | |
| # Install Vercel CLI | |
| - name: Install Vercel CLI | |
| run: npm install --global vercel@latest | |
| # Deploy to Vercel | |
| - name: Deploy to Vercel Production | |
| run: vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --confirm --env-file .env | |
| env: | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |