Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
name: Build and deploy

on:
pull_request:
branches: [master]
push:
branches: [master]

Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -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
});
}