Skip to content

ci(preview): branch-specific GitHub Pages preview for review app #1

ci(preview): branch-specific GitHub Pages preview for review app

ci(preview): branch-specific GitHub Pages preview for review app #1

name: Branch Preview
# Builds the review-editor in demo mode and publishes a static preview
# under https://<owner>.github.io/<repo>/branches/<branch-slug>/.
# Triggered on pushes to claude/** branches and on manual dispatch.
on:
push:
branches:
- 'claude/**'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: branch-preview-${{ github.ref }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Checkout gh-pages (if it exists)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
path: gh-pages
continue-on-error: true
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build review app
run: bun run --cwd apps/review build
- name: Stage preview into gh-pages
run: |
BRANCH_SLUG=$(echo '${{ github.ref_name }}' | tr '/' '-')
echo "BRANCH_SLUG=$BRANCH_SLUG" >> "$GITHUB_ENV"
mkdir -p gh-pages/branches/"$BRANCH_SLUG"
cp apps/review/dist/index.html gh-pages/branches/"$BRANCH_SLUG"/index.html
# Friendly root landing page if one doesn't exist yet.
if [ ! -f gh-pages/index.html ]; then
cat > gh-pages/index.html <<'HTML'
<!doctype html>
<html><head><meta charset="utf-8"><title>Plannotator branch previews</title>
<style>body{font:14px/1.5 system-ui;max-width:40em;margin:3em auto;padding:0 1em;color:#222}</style>
</head><body><h1>Plannotator branch previews</h1>
<p>Per-branch builds live under <code>/branches/&lt;branch-slug&gt;/</code>.</p>
</body></html>
HTML
fi
- name: Commit & push to gh-pages
run: |
cd gh-pages
if [ ! -d .git ]; then
git init -b gh-pages
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to deploy"
exit 0
fi
git commit -m "preview: ${{ github.ref_name }} (${{ github.sha }})"
git push "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print preview URL
run: |
REPO_NAME=$(echo '${{ github.repository }}' | cut -d/ -f2)
URL="https://${{ github.repository_owner }}.github.io/$REPO_NAME/branches/$BRANCH_SLUG/"
echo "::notice title=Preview URL::$URL"
echo "Preview: $URL" >> "$GITHUB_STEP_SUMMARY"