name: build-docusaurus

on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: docker
    steps:
      - name: checkout repository
        uses: https://code.forgejo.org/actions/checkout@v4

      - name: Debug workspace
        run: |
          pwd
          ls -la

      - name: setup node
        uses: https://github.com/actions/setup-node@v4
        with:
          node-version: 20

      - name: restore cached dependencies
        uses: https://code.forgejo.org/actions/cache/restore@v4
        with:
          path: |
            ~/.npm
            docusaurus/node_modules
          key: ${{ runner.os }}-Docusaurus

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

      - name: build project
        run: npm run build

      - name: Debug2
        run: |
          echo "Listing build directory"
          ls -l build

      - name: Capture entire build folder
        uses: https://code.forgejo.org/forgejo/upload-artifact@v3
        with:
          name: build-artifacts
          path: build
          if-no-files-found: error

      - name: cache downloaded dependencies
        if: ${{ github.ref_name == github.event.repository.default_branch }}
        uses: https://code.forgejo.org/actions/cache/save@v4
        with:
          path: |
            ~/.npm
            docusaurus/node_modules
          key: ${{ runner.os }}-Docusaurus
