name: docs

on:
  push:
    branches: [main, master]
  pull_request:
  workflow_dispatch:

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

concurrency:
  group: pages
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install docs extra
        run: pip install -e ".[docs]"
      - name: Build MkDocs
        run: mkdocs build --strict
      - uses: actions/upload-pages-artifact@v3
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
        with:
          path: site

  deploy:
    if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v4
