name: Docs Pages

on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - docs/**
      - .github/workflows/docs-pages.yml

permissions:
  contents: read

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Pages
        uses: actions/configure-pages@v5

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Install docs dependencies
        run: npm ci --prefix docs/website

      - name: Build docs site
        run: npm --prefix docs/website run build

      - name: Upload pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: docs/website/build

  deploy:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
