name: Docs

on:
  pull_request:
  push:
    branches:
      - nightly
      - main
      - release/*
  workflow_dispatch:

jobs:
  build:
    uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
    with:
      repository: pytorch/vision
      script: |
        set -euo pipefail

        export PYTHON_VERSION=3.8
        export GPU_ARCH_TYPE=cpu
        export GPU_ARCH_VERSION=''
        ./.github/scripts/setup-env.sh
        
        # Prepare conda
        CONDA_PATH=$(which conda)
        eval "$(${CONDA_PATH} shell.bash hook)"
        conda activate ci
        # FIXME: not sure why we need this. `ldd torchvision/video_reader.so` shows that it
        #  already links against the one pulled from conda. However, at runtime it pulls from
        #  /lib64
        # Should we maybe always do this in `./.github/scripts/setup-env.sh` so that we don't
        # have to pay attention in all other workflows?
        export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"
        
        cd docs
        
        echo '::group::Install doc requirements'
        pip install --progress-bar=off -r requirements.txt
        echo '::endgroup::'
        
        # The runner does not have sufficient memory to run with as many processes as there are
        # cores (`-j auto`). Thus, we limit to a single process (`-j 1`) here.
        sed -i -e 's/-j auto/-j 1/' Makefile
        make html
        
        mv build/html/* "${RUNNER_DOCS_DIR}"
