# IMPORTANT: Verify that all paths below match your project structure.
# The DOCS_PATH variable should point to your documentation directory.

name: Deploy to GitHub Pages

# Environment variable for the documentation path
# Change this if your documentation is in a different location
env:
  DOCS_PATH: <%= directoryName %>

on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - '<%= directoryName %>/**'

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build:
    name: Build Docusaurus
    runs-on: ubuntu-latest
    environment: github-pages
    defaults:
      run:
        working-directory: ./${{ env.DOCS_PATH }}
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'
          cache: 'npm'
          cache-dependency-path: './${{ env.DOCS_PATH }}/package-lock.json'

      - name: Install dependencies
        run: npm ci

      - name: Build website
        run: npm run build

      - name: Upload Build Artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: ./${{ env.DOCS_PATH }}/build

  deploy:
    name: Deploy to GitHub Pages
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    permissions:
      pages: write # to deploy to Pages
      id-token: write # to authenticate with GitHub Pages

    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4