name: Release Docs

on:
  push:
    tags:
      - "v*"
  # See https://docs.github.com/fr/webhooks/webhook-events-and-payloads#workflow_dispatch
  # Can be used to update doc with latest tag
  workflow_dispatch:

permissions: {}

jobs:
  release_docs:
    permissions:
      contents: write  #  for mike to push

    name: Release Docs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0

      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
        with:
          python-version: "3.12"
          cache: "pip"
          cache-dependency-path: "./docs/scripts/requirements.txt"

      - run: |
          pip install -r docs/scripts/requirements.txt

      - 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
        run: |
          VERSION="${{ github.ref_name }}"
          if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
            VERSION="latest"
          fi
          mike deploy $VERSION --push --update-aliases
          mike set-default --push latest
