# Docusaurus documentation site deployment
# Prerequisite: Enable GitHub Pages in repo Settings → Pages → Source: GitHub Actions
# and allow the target branch in Settings → Environments → github-pages → Deployment branches

name: Deploy Documentation Site

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

concurrency:
  group: pages-deploy-${{ github.ref }}
  cancel-in-progress: false

permissions:
  contents: read

jobs:
  test:
    name: Docusaurus Tests
    uses: ./.github/workflows/docusaurus-tests.yml
    permissions:
      contents: read
    with:
      soft-fail: false

  build:
    name: Build Docusaurus
    needs: test
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pages: write
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
        with:
          node-version: 20
          cache: npm
          cache-dependency-path: docs/docusaurus/package-lock.json

      - name: Install dependencies
        working-directory: docs/docusaurus
        run: npm ci

      - name: Build site
        working-directory: docs/docusaurus
        run: npm run build

      - name: Configure Pages
        uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0

      - name: Upload artifact
        uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
        with:
          path: docs/docusaurus/build

  deploy:
    name: Deploy to GitHub Pages
    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@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
