From 2047a0a67ac2dbbdc0c6057562091b10156efff3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 5 Feb 2026 13:12:33 +0000 Subject: [PATCH] Add PR preview deployments using Surge.sh - Create new pr-preview.yml workflow for PR previews - Each PR gets unique URL: pr-{number}-chrisbolin.surge.sh - Automatically comments on PR with preview link - Update deploy.yml to only deploy to production on push to master Co-authored-by: Chris Bolin --- .github/workflows/deploy.yml | 2 - .github/workflows/pr-preview.yml | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pr-preview.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2fa7f9c..55591bc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,8 +4,6 @@ name: Build and deploy on: - pull_request: - branches: [master] push: branches: [master] diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml new file mode 100644 index 0000000..ccfab7c --- /dev/null +++ b/.github/workflows/pr-preview.yml @@ -0,0 +1,85 @@ +# Deploy PR previews to Surge.sh +# Each PR gets a unique preview URL: pr-{number}-chrisbolin.surge.sh + +name: PR Preview + +on: + pull_request: + branches: [master] + types: [opened, synchronize, reopened] + +jobs: + preview: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Install Surge + run: npm install -g surge + + - name: Deploy to Surge + id: deploy + env: + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + run: | + PREVIEW_URL="pr-${{ github.event.pull_request.number }}-chrisbolin.surge.sh" + surge ./out $PREVIEW_URL + echo "preview_url=https://$PREVIEW_URL" >> $GITHUB_OUTPUT + + - name: Comment on PR with preview URL + uses: actions/github-script@v7 + with: + script: | + const previewUrl = '${{ steps.deploy.outputs.preview_url }}'; + const body = `## 🚀 Preview Deployment Ready! + + Your changes have been deployed to a preview URL: + + **Preview:** ${previewUrl} + + This preview will be updated 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: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('Preview Deployment Ready') + ); + + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: body + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: body + }); + }