name: docs-deploy

on:
  push:
    tags:
      - "*"
  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

      - uses: actions/setup-python@v5
        with:
          python-version: "3.x"

      - name: Create Build Environment
        run: |
          python -m pip install --upgrade pip
          python -m pip install -r ${GITHUB_WORKSPACE}/doc/requirements.txt
          mkdir -p ${{runner.workspace}}/build

      - name: Build documentation
        run: |
          sphinx-build -T -E -b html \
            "${GITHUB_WORKSPACE}/doc" \
            "${{runner.workspace}}/build"

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: ${{runner.workspace}}/build

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

    runs-on: ubuntu-latest
    needs: build

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