From d96bd9cd48b8c3c60bae2a3210ecbcc3ad055fb3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 14:53:50 +0000 Subject: [PATCH 1/3] Add GitHub workflow for PR preview deployments - Deploy preview on PR open/update to sids-in-pr- - Post/update comment on PR with preview URL - Use wrangler deployment URL output for accurate link --- .github/workflows/pr-preview.yml | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/pr-preview.yml diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml new file mode 100644 index 0000000..46f094e --- /dev/null +++ b/.github/workflows/pr-preview.yml @@ -0,0 +1,80 @@ +name: PR Preview + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + deploy-preview: + runs-on: ubuntu-latest + name: Deploy PR Preview + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Build + run: bun run build + + - name: Deploy to Cloudflare + id: deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy --name sids-in-pr-${{ github.event.pull_request.number }} + + - name: Comment PR + uses: actions/github-script@v7 + env: + DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} + with: + script: | + const prNumber = context.payload.pull_request.number; + const deploymentUrl = process.env.DEPLOYMENT_URL; + + const comment = `## 🚀 Preview Deployment + + Your preview is ready! + + **Preview URL:** ${deploymentUrl} + + This preview will update automatically when you push new commits to this PR.`; + + // Check if we already commented + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('Preview Deployment') + ); + + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: comment + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: comment + }); + } From 5c638a37cbb087368554f4a5fad0db8ff2bda3f3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 14:58:46 +0000 Subject: [PATCH 2/3] Add cleanup job to delete PR preview on close - Trigger workflow on PR closed event - Add cleanup-preview job that deletes the worker - Prevents accumulation of orphaned preview deployments --- .github/workflows/pr-preview.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 46f094e..cb11763 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -2,10 +2,11 @@ name: PR Preview on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, closed] jobs: deploy-preview: + if: github.event.action != 'closed' runs-on: ubuntu-latest name: Deploy PR Preview permissions: @@ -78,3 +79,17 @@ jobs: body: comment }); } + + cleanup-preview: + if: github.event.action == 'closed' + runs-on: ubuntu-latest + name: Cleanup PR Preview + steps: + - uses: actions/checkout@v4 + + - name: Delete Cloudflare Worker + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: delete --name sids-in-pr-${{ github.event.pull_request.number }} From b44e77bf39ae89d8f38edbc170616e050bed246f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 16:42:50 +0000 Subject: [PATCH 3/3] Remove GitHub Actions workflows for Cloudflare deployment Switching to native Cloudflare Workers GitHub integration which provides: - Automatic per-branch preview deployments - Built-in PR comments with preview URLs - Native build and deployment management - Automatic cleanup when branches are deleted Setup: Connect Worker to GitHub via Dashboard > Settings > Builds > Connect --- .github/workflows/deploy.yml | 29 ---------- .github/workflows/pr-preview.yml | 95 -------------------------------- 2 files changed, 124 deletions(-) delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/pr-preview.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 0307c85..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Deploy - -on: - push: - branches: - - main - -jobs: - deploy: - runs-on: ubuntu-latest - name: Deploy to Cloudflare - steps: - - uses: actions/checkout@v4 - - - uses: oven-sh/setup-bun@v2 - with: - bun-version: latest - - - name: Install dependencies - run: bun install --frozen-lockfile - - - name: Build - run: bun run build - - - name: Deploy - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml deleted file mode 100644 index cb11763..0000000 --- a/.github/workflows/pr-preview.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: PR Preview - -on: - pull_request: - types: [opened, synchronize, reopened, closed] - -jobs: - deploy-preview: - if: github.event.action != 'closed' - runs-on: ubuntu-latest - name: Deploy PR Preview - permissions: - contents: read - pull-requests: write - steps: - - uses: actions/checkout@v4 - - - uses: oven-sh/setup-bun@v2 - with: - bun-version: latest - - - name: Install dependencies - run: bun install --frozen-lockfile - - - name: Build - run: bun run build - - - name: Deploy to Cloudflare - id: deploy - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: deploy --name sids-in-pr-${{ github.event.pull_request.number }} - - - name: Comment PR - uses: actions/github-script@v7 - env: - DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} - with: - script: | - const prNumber = context.payload.pull_request.number; - const deploymentUrl = process.env.DEPLOYMENT_URL; - - const comment = `## 🚀 Preview Deployment - - Your preview is ready! - - **Preview URL:** ${deploymentUrl} - - This preview will update automatically when you push new commits to this PR.`; - - // Check if we already commented - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - }); - - const botComment = comments.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('Preview Deployment') - ); - - if (botComment) { - // Update existing comment - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: comment - }); - } else { - // Create new comment - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: comment - }); - } - - cleanup-preview: - if: github.event.action == 'closed' - runs-on: ubuntu-latest - name: Cleanup PR Preview - steps: - - uses: actions/checkout@v4 - - - name: Delete Cloudflare Worker - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: delete --name sids-in-pr-${{ github.event.pull_request.number }}