Feat/0323 #4
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: Deploy to Cloudflare Pages | |
| on: | |
| pull_request: | |
| branches: [develop] | |
| types: [opened, synchronize, reopened, closed] | |
| push: | |
| branches: [main, develop] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| deploy-preview: | |
| if: github.event_name == 'pull_request' && github.event.action != 'closed' | |
| runs-on: ubuntu-latest | |
| environment: Preview | |
| env: | |
| CONVEX_PREVIEW_NAME: pr-${{ github.event.pull_request.number }}-deploy | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup | |
| uses: ./.github/actions/setup | |
| - name: Deploy Convex Preview | |
| id: convex | |
| run: | | |
| npx convex deploy --preview-create "$CONVEX_PREVIEW_NAME" \ | |
| --cmd 'echo "PREVIEW_URL=$CONVEX_URL" >> "$GITHUB_OUTPUT"' \ | |
| --cmd-url-env-var-name CONVEX_URL | |
| env: | |
| CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }} | |
| - name: Seed Database | |
| run: | | |
| npx convex import --replace-all convex-seeds/seeds/db.zip --yes \ | |
| --preview-name "${{ env.CONVEX_PREVIEW_NAME }}" | |
| env: | |
| CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }} | |
| - name: Build | |
| run: pnpm build | |
| env: | |
| VITE_CONVEX_URL: ${{ steps.convex.outputs.PREVIEW_URL }} | |
| VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} | |
| - name: Deploy to Cloudflare Pages | |
| id: deploy | |
| run: | | |
| DEPLOY_OUTPUT=$(npx wrangler pages deploy dist \ | |
| --project-name dev-yps-crispy-carnival \ | |
| --branch "pr-${{ github.event.pull_request.number }}" 2>&1) | |
| echo "$DEPLOY_OUTPUT" | |
| DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -oP 'https://[^\s]+\.pages\.dev' | tail -1) | |
| echo "DEPLOY_URL=$DEPLOY_URL" >> "$GITHUB_OUTPUT" | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Comment PR with Deploy URL | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const deployUrl = '${{ steps.deploy.outputs.DEPLOY_URL }}'; | |
| const convexUrl = '${{ steps.convex.outputs.PREVIEW_URL }}'; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `## 🚀 Preview Deploy\n\n**App:** ${deployUrl}\n**Convex:** ${convexUrl}` | |
| }); | |
| cleanup-preview: | |
| if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
| runs-on: ubuntu-latest | |
| environment: Preview | |
| steps: | |
| - name: Delete Cloudflare Pages preview | |
| run: | | |
| DEPLOYMENTS=$(curl -s \ | |
| -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ | |
| "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/dev-yps-crispy-carnival/deployments" \ | |
| | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"pr-${{ github.event.pull_request.number }}\") | .id") | |
| for ID in $DEPLOYMENTS; do | |
| echo "Deleting deployment $ID" | |
| curl -s -X DELETE \ | |
| -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ | |
| "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/dev-yps-crispy-carnival/deployments/$ID?force=true" | |
| done | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| deploy-develop: | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/develop' | |
| runs-on: ubuntu-latest | |
| environment: Preview | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup | |
| uses: ./.github/actions/setup | |
| - name: Deploy Convex | |
| run: npx convex deploy | |
| env: | |
| CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }} | |
| - name: Build | |
| run: pnpm build | |
| env: | |
| VITE_CONVEX_URL: ${{ secrets.VITE_CONVEX_URL }} | |
| VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} | |
| - name: Deploy to Cloudflare Pages | |
| run: | | |
| npx wrangler pages deploy dist \ | |
| --project-name dev-yps-crispy-carnival \ | |
| --branch main | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| deploy-production: | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| environment: Production | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup | |
| uses: ./.github/actions/setup | |
| - name: Deploy Convex | |
| run: npx convex deploy | |
| env: | |
| CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }} | |
| - name: Build | |
| run: pnpm build | |
| env: | |
| VITE_CONVEX_URL: ${{ secrets.VITE_CONVEX_URL }} | |
| VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} | |
| - name: Deploy to Cloudflare Pages | |
| run: | | |
| npx wrangler pages deploy dist \ | |
| --project-name yps-crispy-carnival \ | |
| --branch main | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |