name: Sphinx documentation

on: [push]

env:
  R-VERSION: "release"

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.10"
    - name: Set up R
      uses: r-lib/actions/setup-r@v2
      with:
        r-version: ${{ env.R-VERSION }}
    - name: Cache R packages
      uses: actions/cache@v4
      env:
        cache-name: cache-R-packages
      with:
        path: /opt/R/**/lib/R/library
        key: ${{ runner.os }}-R${{ env.R-VERSION }}-build-${{ env.cache-name }}
        restore-keys: |
          ${{ runner.os }}-${{ env.R_VERSION }}-build-
    - name: Set RSPM
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        echo "RSPM=\"https://packagemanager.rstudio.com/cran/__linux__/$(lsb_release -sc)/latest\"" >> $GITHUB_ENV
    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install pandoc graphviz libgraphviz-dev
        python -m pip install --upgrade pip
        pip install 'rpy2-rinterface/[doc]'
        pip install 'rpy2-robjects/[doc]'
        sudo Rscript ./install_r_packages.r BiocManager dbplyr dplyr ggplot2 hexbin lazyeval RSQLite tidyr viridis
        sudo Rscript -e 'BiocManager::install("Biobase")'
    - name: Build HTML doc
      run: |
        export LD_LIBRARY_PATH=$(python -m rpy2.situation LD_LIBRARY_PATH):${LD_LIBRARY_PATH}
        python -m rpy2.situation
        cd doc
        make notebooks
        make html
    - name: Archive documentation
      uses: actions/upload-artifact@v4
      with:
        name: html-doc
        path: doc/_build/html
