name: Build documentation

on:
  push:
    branches:
      - main

jobs:
  build-docs:
    runs-on: ubuntu-latest
    name: Build documentation

    # https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
    defaults:
      run:
        shell: bash -l {0}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      # See: https://github.com/marketplace/actions/setup-miniconda
      - name: Setup miniconda
        uses: conda-incubator/setup-miniconda@v2
        with:
          auto-update-conda: true
          miniforge-variant: Mambaforge
          channels: conda-forge
          activate-environment: {{ project_name }}
          environment-file: environment.yml
          use-mamba: true

      - name: Build docs
        run: |
          conda activate {{ project_name }}
          python -m ipykernel install --user --name {{ project_name }}
          pip install -e .
          typer {{ project_name }}.cli utils docs --name {{ project_name }} --output docs/cli.md
          mkdocs build --site-dir /tmp/docs

      - name: Deploy website
        uses: peaceiris/actions-gh-pages@v3
        with:
          # https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-set-personal-access-token-personal_token
          {% raw %}
          personal_token: ${{ secrets.GITHUB_TOKEN }}
          {% endraw %}
          publish_dir: /tmp/docs
          publish_branch: gh-pages
          allow_empty_commit: false
          keep_files: false
          force_orphan: true
          enable_jekyll: false
