name: R-CMD-check

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  R-CMD-check:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: macos-latest,   r: 'release'}
          - {os: windows-latest, r: 'release'}
          - {os: ubuntu-latest,   r: 'devel', http-user-agent: 'release'}
          - {os: ubuntu-latest,   r: 'release'}
          - {os: ubuntu-latest,   r: 'oldrel-1'}

    env:
      R_KEEP_PKG_SOURCE: yes

    steps:
      # Checkout repository
      - uses: actions/checkout@v3

      # Set up pandoc
      - uses: r-lib/actions/setup-pandoc@v2

      # Set up R environment
      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      # Automatically install dependencies from DESCRIPTION
      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
           extra-packages: >-
            any::rcmdcheck

      # Manually install Bioconductor and other missing dependencies
      - name: Install dependencies
        run: |
          Rscript -e "if (!requireNamespace('BiocManager', quietly = TRUE)) install.packages('BiocManager')"
          Rscript -e "BiocManager::install()"
          Rscript -e "if (!requireNamespace('remotes', quietly = TRUE)) install.packages('remotes')"
          Rscript -e "remotes::install_deps(dependencies = TRUE)"

      # Run R CMD check
      - uses: r-lib/actions/check-r-package@v2
        with:
          upload-snapshots: true
