name: Deploy Documentation

on:
  push:
    branches: [main]
  workflow_dispatch:

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

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

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

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "{{ project.python_version }}"

{% if documentation.tool == "mkdocs" %}
      - name: Install dependencies
        run: pip install mkdocs-material mkdocstrings[python]

      - name: Build docs
        run: mkdocs build --site-dir _site
{% elif documentation.tool == "sphinx" %}
      - name: Install dependencies
        run: pip install sphinx sphinx-rtd-theme

      - name: Build docs
        run: sphinx-build docs _site
{% endif %}

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: _site

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: {% raw %}${{ steps.deployment.outputs.page_url }}{% endraw %}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
