
name: Documentation Build Test

on:
  push:
    branches:
      - '**'
    tags:
      - '*'
  pull_request:
  release:
    types: [published]

jobs:
  build-docs:
    runs-on: ubuntu-latest
    name: Build Documentation

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y doxygen

    - name: Install Python dependencies
      run: |
        pip install -r docs/requirements.txt

    - name: Build documentation
      working-directory: docs
      run: |
        make html

    - name: Upload artifact for GitHub Pages
      if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'release'
      uses: actions/upload-pages-artifact@v3
      with:
        path: docs/_build/html

  deploy-docs:
    if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'release'
    needs: build-docs
    runs-on: ubuntu-latest
    permissions:
      pages: write
      id-token: write

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

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