name: Build Documentation

on:
  push:
    branches:
      - develop
  release:
    types: [published]


# disable permissions for all of the available permissions
permissions: {}

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  build-docs:
    permissions:
      contents: write  #  for mike to push
    name: Deploy Docs through mike
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: true

      - name: Install uv and Python 🐍
        uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
        with:
          activate-environment: true
          python-version: '3.13'
          enable-cache: false

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

      - name: Fetch gh-pages branch
        run: |
          git fetch origin gh-pages --depth=1

      - name: Configure Git user
        run: |
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"

      - name: Build and push Mike
        if: ${{ github.event_name == 'push' }}
        run: |
          mike deploy ${REF_NAME} latest --push --update-aliases
        env:
          REF_NAME: ${{ github.ref_name }}

      - name: Build and push Mike - Release
        if: ${{ github.event_name == 'release' }}
        run: |
          mike deploy ${REF_NAME} stable --push --update-aliases
        env:
          REF_NAME: ${{ github.ref_name }}

      - name: Show mike versions
        run: |
          mike list