# Publish the showcase as a static site.
#
# This is a sample, not a mandate — it is here so that "deploy the docs" is a
# switch you flip rather than a thing you research. Delete it if you host
# elsewhere.
#
# ── GitHub Pages (what this file does) ────────────────────────────────────────
#   1. Settings → Pages → Source: **GitHub Actions**.
#   2. Run this workflow once from the Actions tab.
#   3. Uncomment the `push:` trigger below to publish on every push to main.
#
#   `SHOWCASE_BASE` must match the path the site is served from. For a project
#   site that is `/<repo>/`, which is what the build step below computes. For a
#   user/org site (`<you>.github.io`) it is `/` — drop the env line.
#
# ── Vercel / Netlify / Cloudflare Pages ───────────────────────────────────────
#   No workflow needed. Point the project at this repo and set:
#     Build command    npm run showcase:build      (SHOWCASE_BASE unset → "/")
#     Output directory showcase/dist
#     Node version     20 or newer
#
# ── Anywhere else (S3, nginx, a folder on a share) ────────────────────────────
#   `SHOWCASE_BASE=/whatever/ npm run showcase:build` and copy `showcase/dist`.
#   The app routes on the hash, so the server needs **no rewrite rule** — every
#   URL is `index.html` as far as it is concerned. That is the whole reason a
#   sub-path deployment only needs `base` and nothing else.

name: Showcase

on:
  workflow_dispatch:
  # push:
  #   branches: [main]

# Least privilege: read the repo, write a Pages deployment, and nothing else.
permissions:
  contents: read
  pages: write
  id-token: write

# One deployment at a time. `cancel-in-progress: false` so a queued run waits
# for the live one rather than aborting a half-finished deploy.
concurrency:
  group: showcase-pages
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20

      # `npm install`, not `npm ci`: a scaffolded kit may have been installed
      # with pnpm, in which case there is no package-lock.json to be found.
      # Swap in `pnpm/action-setup` + `pnpm install --frozen-lockfile` if pnpm
      # is what your team uses.
      - run: npm install

      - name: Build the showcase
        env:
          SHOWCASE_BASE: /${{ github.event.repository.name }}/
        run: npm run showcase:build

      - uses: actions/configure-pages@v5
      - uses: actions/upload-pages-artifact@v3
        with:
          path: showcase/dist

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v4
