diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 0000000..cbb7c3a --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,48 @@ +name: Deploy Preview + +on: + pull_request: + types: [opened, synchronize] + push: + branches: [main] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '18' + + - run: npm ci + - run: npm run build + + - name: Deploy PR Preview + if: github.event_name == 'pull_request' + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: versions upload --preview-alias pr-${{ github.event.number }} + + - name: Deploy Production + if: github.event_name == 'push' + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + + - name: Comment PR with preview URL + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '🚀 Preview: https://pr-${{ github.event.number }}-vezza-dev.workers.dev' + })