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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        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
