# 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@6044e13b5dc448c55e2357c09f80417699197238 # v4.1.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@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
        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
