|
| 1 | +name: Deploy to Cloudflare Pages |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [develop] |
| 6 | + push: |
| 7 | + branches: [develop] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy-preview: |
| 15 | + if: github.event_name == 'pull_request' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + environment: Preview |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v6 |
| 20 | + - name: Setup |
| 21 | + uses: ./.github/actions/setup |
| 22 | + - name: Deploy Convex Preview |
| 23 | + id: convex |
| 24 | + run: | |
| 25 | + PREVIEW_NAME="pr-${{ github.event.pull_request.number }}" |
| 26 | + npx convex deploy --preview-create "$PREVIEW_NAME" \ |
| 27 | + --cmd 'echo "PREVIEW_URL=$CONVEX_URL" >> "$GITHUB_OUTPUT"' \ |
| 28 | + --cmd-url-env-var-name CONVEX_URL |
| 29 | + env: |
| 30 | + CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }} |
| 31 | + - name: Build |
| 32 | + run: pnpm build |
| 33 | + env: |
| 34 | + VITE_CONVEX_URL: ${{ steps.convex.outputs.PREVIEW_URL }} |
| 35 | + VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} |
| 36 | + - name: Deploy to Cloudflare Pages |
| 37 | + id: deploy |
| 38 | + run: | |
| 39 | + DEPLOY_OUTPUT=$(npx wrangler pages deploy dist \ |
| 40 | + --project-name yps-crispy-carnival \ |
| 41 | + --branch "pr-${{ github.event.pull_request.number }}" 2>&1) |
| 42 | + echo "$DEPLOY_OUTPUT" |
| 43 | + DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -oP 'https://[^\s]+\.pages\.dev' | tail -1) |
| 44 | + echo "DEPLOY_URL=$DEPLOY_URL" >> "$GITHUB_OUTPUT" |
| 45 | + env: |
| 46 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 47 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 48 | + - name: Comment PR with Deploy URL |
| 49 | + uses: actions/github-script@v8 |
| 50 | + with: |
| 51 | + script: | |
| 52 | + const deployUrl = '${{ steps.deploy.outputs.DEPLOY_URL }}'; |
| 53 | + const convexUrl = '${{ steps.convex.outputs.PREVIEW_URL }}'; |
| 54 | + await github.rest.issues.createComment({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: context.issue.number, |
| 58 | + body: `## 🚀 Preview Deploy\n\n**App:** ${deployUrl}\n**Convex:** ${convexUrl}` |
| 59 | + }); |
| 60 | +
|
| 61 | + deploy-production: |
| 62 | + if: github.event_name == 'push' |
| 63 | + runs-on: ubuntu-latest |
| 64 | + environment: Production |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v6 |
| 67 | + - name: Setup |
| 68 | + uses: ./.github/actions/setup |
| 69 | + - name: Build |
| 70 | + run: pnpm build |
| 71 | + env: |
| 72 | + VITE_CONVEX_URL: ${{ secrets.VITE_CONVEX_URL }} |
| 73 | + VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} |
| 74 | + - name: Deploy to Cloudflare Pages |
| 75 | + run: | |
| 76 | + npx wrangler pages deploy dist \ |
| 77 | + --project-name yps-crispy-carnival \ |
| 78 | + --branch main |
| 79 | + env: |
| 80 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 81 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
0 commit comments