# SlickGrid documentation — build & deploy to GitHub Pages.
#
# PREPARED, NOT WIRED. When the docs site is relocated into the repo at <repo>/docs,
# copy this file to <repo>/.github/workflows/docs.yml. It:
#   1. regenerates the API reference from src/ (npm run api),
#   2. runs the drift gate (fails on NEW undocumented public API),
#   3. builds the VitePress site with the correct base path,
#   4. publishes it to GitHub Pages.
#
# Set the base path to match the Pages URL. For a project site served at
# https://6pac.github.io/SlickGrid/ the base is /SlickGrid/.

name: Docs
on:
  push:
    branches: [master, next-v6]
    paths:
      - 'src/**'
      - 'docs/**'
      - '.github/workflows/docs.yml'
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: docs
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - name: Regenerate API reference from source
        run: npm run api
      - name: Drift gate (fail on new undocumented public API)
        run: npm run drift -- --strict
      - name: Build site
        env:
          DOCS_BASE: /SlickGrid/
        run: npm run docs:build
      - uses: actions/upload-pages-artifact@v3
        with:
          path: docs/.vitepress/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
