name: Docusaurus Tests

on:
  workflow_call:
    inputs:
      soft-fail:
        description: 'Whether to continue on test failures'
        required: false
        type: boolean
        default: false

permissions:
  contents: read

jobs:
  docusaurus:
    name: Docusaurus Unit Tests
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout code
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: '24'
          cache: npm
          cache-dependency-path: docs/docusaurus/package-lock.json

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

      - name: Run tests
        working-directory: docs/docusaurus
        run: npm test
        env:
          COLLECTIONS_DIR: ${{ github.workspace }}/collections
        continue-on-error: ${{ inputs.soft-fail }}

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

      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: docusaurus-test-results
          path: docs/docusaurus/test-results/
          retention-days: 30
          if-no-files-found: ignore
