Skip to content

Commit 1f3675b

Browse files
petrsvihlikclaude
andcommitted
Add Surge.sh PR preview deployments
- On PR open/push: builds site, deploys to petrsvihlik-pr-{N}.surge.sh, posts (or updates) a comment on the PR with the preview URL - On PR close: tears down the Surge deployment automatically Requires SURGE_LOGIN and SURGE_TOKEN repository secrets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c5414ec commit 1f3675b

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/preview.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Preview
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
types: [opened, synchronize, reopened, closed]
7+
8+
jobs:
9+
deploy-preview:
10+
if: github.event.action != 'closed'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v6
14+
- uses: actions/setup-dotnet@v5
15+
with:
16+
dotnet-version: 10.0.x
17+
- name: Install dependencies
18+
run: dotnet restore
19+
- name: Build
20+
run: dotnet build --configuration Release --no-restore
21+
- name: Generate site
22+
run: dotnet run --configuration Release
23+
- name: Index with Pagefind
24+
run: npx pagefind --site output
25+
- name: Deploy to Surge
26+
env:
27+
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
28+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
29+
run: npx surge ./output petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh
30+
- name: Post preview URL comment
31+
uses: actions/github-script@v7
32+
with:
33+
script: |
34+
const url = 'https://petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh';
35+
const marker = '<!-- surge-preview -->';
36+
const body = `${marker}\n🚀 **Preview:** [${url}](${url})`;
37+
38+
const comments = await github.rest.issues.listComments({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
issue_number: context.issue.number,
42+
});
43+
44+
const existing = comments.data.find(c => c.body.includes(marker));
45+
if (existing) {
46+
await github.rest.issues.updateComment({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
comment_id: existing.id,
50+
body,
51+
});
52+
} else {
53+
await github.rest.issues.createComment({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
issue_number: context.issue.number,
57+
body,
58+
});
59+
}
60+
61+
teardown-preview:
62+
if: github.event.action == 'closed'
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Teardown Surge preview
66+
env:
67+
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
68+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
69+
run: npx surge teardown petrsvihlik-pr-${{ github.event.pull_request.number }}.surge.sh

0 commit comments

Comments
 (0)