---
name: Pages Deploy

on:
  workflow_dispatch:
  release:
    types: [published]

env:
  MAIN_PY_VER: "3.13"

jobs:
  deploy-pages:
    runs-on: ubuntu-latest
    environment: github-pages
    name: Build documentation site and deploy to GH-Pages
    steps:
      - name: Checkout sources
        uses: actions/checkout@v5
        with:
          ref: ${{ github.ref }}

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: ${{ env.MAIN_PY_VER }}

      - name: Cache pip repository
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ env.MAIN_PY_VER }}

      - name: Prepare python environment
        run: |
          pip install -r requirements.txt
          poetry config virtualenvs.create true
          poetry config virtualenvs.in-project true

      - name: Cache poetry virtual environment
        uses: actions/cache@v4
        with:
          path: .venv
          key: ${{ runner.os }}-poetry-${{ hashFiles('**/pyproject.toml') }}-${{ env.MAIN_PY_VER }}

      - name: Build documentation site
        run: |
          poetry lock
          poetry install --no-interaction
          poetry run poe docs_build

      - name: Deploy to GH-Pages
        uses: peaceiris/actions-gh-pages@v4.0.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./site
          cname: aioswitcher.figenblat.com
          commit_message: 'docs: deployed documentation site '
