name: build-sveltekit

on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Restore npm cache
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-npm-

      - name: Install dependencies
        run: npm install --frozen-lockfile

      - name: Build Docusaurus site
        run: npm run build

      - name: capture build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: docusaurus-build-artifacts
          path: build

      - name: Save npm cache
        if: ${{ github.ref_name == github.event.repository.default_branch }}
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
