name: Docs Build Check

on:
  push:
    branches-ignore:
      - 'build'
    paths:
      - 'docs/**'
      - 'src/**'
      - 'package.json'
      - 'package-lock.json'
      - 'tsconfig*.json'
      - '.github/workflows/docs-build-check.yml'
  pull_request:

jobs:
  build-docs:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

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

      - name: Cache Root Node Modules
        id: cache-root-modules
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-root-${{ hashFiles('package-lock.json') }}

      - name: Install dependencies
        if: steps.cache-root-modules.outputs.cache-hit != 'true'
        run: npm ci

      - name: Cache Docs Node Modules
        id: cache-docs-modules
        uses: actions/cache@v5
        with:
          path: docs/node_modules
          key: ${{ runner.os }}-node-docs-${{ hashFiles('docs/package-lock.json') }}

      - name: Install docs dependencies
        if: steps.cache-docs-modules.outputs.cache-hit != 'true'
        run: npm ci
        working-directory: ./docs

      - name: Build docs
        run: npm run build
        working-directory: ./docs
