ci: render catalog previews on PR (#262)

## What

CI workflow that auto-renders preview thumbnails for new/changed registry blocks and components on pull requests.

**New files:**
- `scripts/generate-catalog-previews.ts` — catalog preview renderer supporting all three registry item types
- `.github/workflows/catalog-previews.yml` — GitHub Actions workflow triggered on PRs touching `registry/blocks/` or `registry/components/`

## Why

Phase B of the catalog plan (PR 8). After this lands, future block/component PRs don't need to manually generate preview images — CI handles it automatically.

## How

The preview script discovers items from the registry directory structure:
- **Examples**: renders `index.html` (same as the existing `generate-template-previews.ts`)
- **Blocks**: renders the block's standalone HTML file directly (e.g., `data-chart.html`)
- **Components**: renders the component's `demo.html` (the demo.html convention from PR 7)

The CI workflow:
1. Detects which blocks/components changed in the PR via `git diff`
2. Renders thumbnails for only the changed items (not the full catalog)
3. Uploads preview PNGs as artifacts

Output goes to `docs/images/catalog/<type>/<name>.{png,mp4}` (separate from the existing `docs/images/templates/` directory).

Supports CLI flags: `--only <name>`, `--type <example|block|component>`, `--skip-video`.

## Test plan

- [x] Script compiles and passes typecheck (`lefthook pre-commit` ran lint + typecheck + format)
- [x] Workflow YAML is valid (standard GitHub Actions syntax, follows existing ci.yml patterns)
- [ ] Full end-to-end test requires Chrome + FFmpeg (runs in CI, not testable locally without producer deps)
This commit is contained in:
James Russo
2026-04-14 16:21:23 -07:00
committed by GitHub
parent b0f754a7f7
commit ea6f949922
2 changed files with 318 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
name: Catalog Previews
on:
pull_request:
paths:
- "registry/blocks/**"
- "registry/components/**"
- "scripts/generate-catalog-previews.ts"
concurrency:
group: catalog-previews-${{ github.ref }}
cancel-in-progress: true
jobs:
render-previews:
name: Render catalog previews
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: 22
- run: bun install --frozen-lockfile
- run: bun run build
# Chrome headless shell for rendering
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
# FFmpeg for video encoding
- uses: FedericoCarboni/setup-ffmpeg@v3
- name: Render changed block/component previews
continue-on-error: true
run: |
# Find which blocks/components changed in this PR
CHANGED_ITEMS=$(git diff --name-only origin/main...HEAD -- registry/blocks/ registry/components/ \
| grep -oP '(?<=registry/(blocks|components)/)[^/]+' \
| sort -u)
if [ -z "$CHANGED_ITEMS" ]; then
echo "No block/component changes detected."
exit 0
fi
echo "Changed items: $CHANGED_ITEMS"
FAILED=0
for item in $CHANGED_ITEMS; do
echo "Rendering preview for: $item"
if ! npx tsx scripts/generate-catalog-previews.ts --only "$item" --skip-video; then
echo "::warning::Failed to render preview for $item"
FAILED=$((FAILED + 1))
fi
done
if [ "$FAILED" -gt 0 ]; then
echo "::warning::$FAILED item(s) failed to render"
exit 1
fi
- name: Upload preview artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: catalog-previews
path: docs/images/catalog/
if-no-files-found: ignore
retention-days: 30