Skip to content

Commit 32d9bef

Browse files
Add PR preview workflow for GitHub Pages
- Deploy PR previews to /pr-preview/pr-{number}/ subdirectory - Automatic cleanup when PR is closed - Uses rossjrw/pr-preview-action for deployment - Builds with correct base path for preview URL
1 parent 29fd906 commit 32d9bef

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

.github/workflows/pr-preview.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
concurrency: preview-${{ github.ref }}
12+
13+
jobs:
14+
build-preview:
15+
if: github.event.action != 'closed'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
lfs: true
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'npm'
28+
cache-dependency-path: frontend/package-lock.json
29+
30+
- name: Install dependencies
31+
working-directory: frontend
32+
run: npm ci
33+
34+
- name: Copy static assets
35+
working-directory: frontend
36+
run: |
37+
mkdir -p public/thumbnails public/downsampled public/annotations/nsd
38+
cp -r ../data/thumbnails/* public/thumbnails/ 2>/dev/null || echo "No thumbnails to copy"
39+
cp -r ../images/downsampled/* public/downsampled/ 2>/dev/null || echo "No images to copy"
40+
cp -r ../annotations/nsd/*.json public/annotations/nsd/ 2>/dev/null || echo "No annotations to copy"
41+
42+
- name: Build Next.js site
43+
working-directory: frontend
44+
env:
45+
# Set base path for PR preview subdirectory
46+
NEXT_PUBLIC_BASE_PATH: /image-annotation/pr-preview/pr-${{ github.event.number }}
47+
run: |
48+
# Update next.config.js base path for preview
49+
sed -i "s|'/image-annotation'|'/image-annotation/pr-preview/pr-${{ github.event.number }}'|g" next.config.js
50+
npm run build
51+
52+
- name: Deploy PR Preview
53+
uses: rossjrw/pr-preview-action@v1
54+
with:
55+
source-dir: frontend/out
56+
preview-branch: gh-pages
57+
umbrella-dir: pr-preview
58+
action: auto
59+
60+
cleanup:
61+
if: github.event.action == 'closed'
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout repository
65+
uses: actions/checkout@v4
66+
67+
- name: Cleanup PR Preview
68+
uses: rossjrw/pr-preview-action@v1
69+
with:
70+
source-dir: frontend/out
71+
preview-branch: gh-pages
72+
umbrella-dir: pr-preview
73+
action: remove

0 commit comments

Comments
 (0)