name: Build documentation

on:
  push:
    branches:
      - "main"

env:
  PYTHON_VERSION: 3.9

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

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

jobs:
    build-docs:
        runs-on: ubuntu-latest
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}

        steps:
            - id: checkout
              uses: actions/checkout@v3
            - id: setup-python
              uses: actions/setup-python@v4
              with:
                python-version: ${{ env.PYTHON_VERSION }}

            - id: install-deps-and-build
              name: Install dependencies and test
              run: |
                pip install -e .
                pip install -e .[doc]
                mkdocs build --site-dir build

            - name: Setup Pages
              id: configure-pages
              uses: actions/configure-pages@v3

            - name: Upload artifact
              id: upload-artifact
              uses: actions/upload-pages-artifact@v1
              with:
                # Upload entire repository
                path: './build'

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

            - name: Upload PDF
              id: upload-pdf
              uses: actions/upload-artifact@v3
              with:
                name: document.pdf
                path: site/pdf/document.pdf
