Skip to content

Commit ed31d8b

Browse files
committed
ci(preview): branch-specific GitHub Pages preview for review app
Builds apps/review on every push to claude/** (and on manual dispatch), publishes the single-file HTML to gh-pages/branches/<slug>/. Each branch lives in its own subdir; a concurrency group cancels in-flight runs of the same ref so we don't race ourselves. The first run creates the gh-pages branch — switch Settings -> Pages -> Source to "Deploy from a branch" / gh-pages / root after this lands.
1 parent 9842f73 commit ed31d8b

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Branch Preview
2+
3+
# Builds the review-editor in demo mode and publishes a static preview
4+
# under https://<owner>.github.io/<repo>/branches/<branch-slug>/.
5+
# Triggered on pushes to claude/** branches and on manual dispatch.
6+
7+
on:
8+
push:
9+
branches:
10+
- 'claude/**'
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: write
15+
16+
concurrency:
17+
group: branch-preview-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
preview:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout source
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
27+
- name: Checkout gh-pages (if it exists)
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
ref: gh-pages
31+
path: gh-pages
32+
continue-on-error: true
33+
34+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
35+
with:
36+
bun-version: latest
37+
38+
- name: Install dependencies
39+
run: bun install
40+
41+
- name: Build review app
42+
run: bun run --cwd apps/review build
43+
44+
- name: Stage preview into gh-pages
45+
run: |
46+
BRANCH_SLUG=$(echo '${{ github.ref_name }}' | tr '/' '-')
47+
echo "BRANCH_SLUG=$BRANCH_SLUG" >> "$GITHUB_ENV"
48+
49+
mkdir -p gh-pages/branches/"$BRANCH_SLUG"
50+
cp apps/review/dist/index.html gh-pages/branches/"$BRANCH_SLUG"/index.html
51+
52+
# Friendly root landing page if one doesn't exist yet.
53+
if [ ! -f gh-pages/index.html ]; then
54+
cat > gh-pages/index.html <<'HTML'
55+
<!doctype html>
56+
<html><head><meta charset="utf-8"><title>Plannotator branch previews</title>
57+
<style>body{font:14px/1.5 system-ui;max-width:40em;margin:3em auto;padding:0 1em;color:#222}</style>
58+
</head><body><h1>Plannotator branch previews</h1>
59+
<p>Per-branch builds live under <code>/branches/&lt;branch-slug&gt;/</code>.</p>
60+
</body></html>
61+
HTML
62+
fi
63+
64+
- name: Commit & push to gh-pages
65+
run: |
66+
cd gh-pages
67+
if [ ! -d .git ]; then
68+
git init -b gh-pages
69+
fi
70+
git config user.name "github-actions[bot]"
71+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
72+
git add -A
73+
if git diff --cached --quiet; then
74+
echo "No changes to deploy"
75+
exit 0
76+
fi
77+
git commit -m "preview: ${{ github.ref_name }} (${{ github.sha }})"
78+
git push "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages
79+
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Print preview URL
83+
run: |
84+
REPO_NAME=$(echo '${{ github.repository }}' | cut -d/ -f2)
85+
URL="https://${{ github.repository_owner }}.github.io/$REPO_NAME/branches/$BRANCH_SLUG/"
86+
echo "::notice title=Preview URL::$URL"
87+
echo "Preview: $URL" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)