name: sphinx
 
on:
  push:
    branches: [master]
    paths:
      - 'agentle/**'
      - 'docs/**'
  workflow_dispatch:

permissions:
  pages: write
  id-token: write
  contents: write

jobs:
  build-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python 3.13
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"

      - name: Install PIP
        run: pip install --root-user-action=ignore --upgrade pip

      - name: Install project dependencies for docs using pip
        run: |
          pip install -e .
          pip install sphinx furo snowballstemmer sphinx-rtd-theme aiohttp

      - name: Build Sphinx Documentation
        run: |
          cd docs
          make html
          touch build/html/.nojekyll  # Add .nojekyll file to disable Jekyll processing

      - name: Prepare Deployment Directory
        run: |
          # Create necessary directories
          mkdir -p deploy_output/build/html
          
          # Copy the logo, nojekyll, and index.html
          cp -r docs/logo.png deploy_output/
          touch deploy_output/.nojekyll  # Add .nojekyll in the root
          cp docs/index.html deploy_output/index.html
          
          # Copy the built documentation
          cp -r docs/build/html/* deploy_output/build/html/

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        if: github.ref == 'refs/heads/master'
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./deploy_output
          enable_jekyll: false
