r-lib / actions

GitHub Actions for the R community
Creative Commons Zero v1.0 Universal
962 stars 208 forks source link

setup-r-dependencies - Why not leverage de repo options ? It fails if we want to use this action in a Github Enterprise with our own repository mirroring #918

Open marandet opened 1 week ago

marandet commented 1 week ago

Describe the bug

I am using these actions in a on-premise Github Enterprise installation. We are using our own package-manager that is configured to mirror several kind of repositories (from Docker artefacts and OS-Distributions to languages-specific libraries, including CRAN). The point is that all of this is within our internal network so that we do not allow our github runner to have access to the internet.

I successfully run the setup-r action, leveraging the RSPM environment variable and the extra-repositories option in order to point to our Artifactory. I also add a step in order to write the options.repos value within the Rprofile configuration file.

But the installation of the pak package still fails.

A clear and concise description of what the bug is.

To Reproduce

Here is an example of my use-case :

      - uses: r-lib/actions/setup-r@v2
        env:
          RENV_CONFIG_REPOS_OVERRIDE: https://artifactory-URL/ubuntu/dists/jammy/
          RSPM: https://artifactory-URL/ubuntu/dists/jammy/
        with:
          r-version: 'release'
          http-user-agent: 'release'
          use-public-rspm: false
          extra-repositories: 'https://artifactory-URL/R-all https://artifactory-URL/remote-cran'

      - name: Set Artifactory repo
        run: |
          cat("\noptions(repos = c(CRAN = 'https://artifactory-URL/remote-cran'), download.file.method = 'libcurl')\n", file = "~/.Rprofile", append = TRUE)
        shell: Rscript {0}

      - uses: r-lib/actions/setup-r-dependencies@v2
        env:
          RENV_CONFIG_REPOS_OVERRIDE: https://artifactory-URL/ubuntu/dists/jammy/
          RSPM: https://artifactory-URL/ubuntu/dists/jammy/
        with:
          extra-packages: any::rcmdcheck
          needs: check

And the following error occurs in the Run r-lib/actions/setup-r-dependencies@v2 step, in the Run # Install pak substep.

Run # Install pak
  # Install pak
  echo "::group::Install pak"
  if which sudo >/dev/null; then SUDO="sudo -E --preserve-env=PATH env"; else SUDO=""; fi
  $SUDO R -q -e 'dir.create(Sys.getenv("R_LIB_FOR_PAK"), recursive = TRUE, showWarnings = FALSE)'
  $SUDO R -q -e 'install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK"), repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "stable", .Platform$pkgType, R.Version()$os, R.Version()$arch))'
  echo "::endgroup::"
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    GITHUB_PAT: ***
    R_KEEP_PKG_SOURCE: yes
    R_LIBS_USER: /home/runner/_work/_temp/Library
    TZ: UTC
    _R_CHECK_SYSTEM_CLOCK_: FALSE
    NOT_CRAN: true
    RSPM: https://artifactory-URL/ubuntu/dists/jammy/
    RENV_CONFIG_REPOS_OVERRIDE: https://artifactory-URL/ubuntu/dists/jammy/
    R_LIB_FOR_PAK: /opt/R/4.4.1/lib/R/site-library
Install pak
  > dir.create(Sys.getenv("R_LIB_FOR_PAK"), recursive = TRUE, showWarnings = FALSE)
  > 
  > 
  > install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK"), repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "stable", .Platform$pkgType, R.Version()$os, R.Version()$arch))
  Warning: Warning: unable to access index for repository https://r-lib.github.io/p/pak/stable/source/linux-gnu/x86_[64](https://github-on-prem-URL/MyORG/MyREPO/actions/runs/7782/job/13135#step:6:67)/src/contrib:
    cannot open URL 'https://r-lib.github.io/p/pak/stable/source/linux-gnu/x86_64/src/contrib/PACKAGES'
  Warning message:
  package 'pak' is not available for this version of R

  A version of this package for your version of R might be available elsewhere,
  see the ideas at
  https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages 
  > 
  >

Expected behavior

The installation of every package should leverage the options.repos configuration.

Additional context

I guess that the problem is in this specific line of code

https://github.com/r-lib/actions/blob/e6be4b3706e0f39bc7a4cf4496a5f2c4cb840040/setup-r-dependencies/action.yaml#L110

gaborcsardi commented 1 week ago

This is not a bug, it is a requirement. setup-r-dependencies requires access to GitHub Pages currently.

A workaround is to do these before using setup-r-dependencies:

It is best to install pak into a different library than the one you use for your regular packages, in case some of those also required pak and need a different version.