From b69b2cb63bd8f39c01985295fe1e7e54e29e978c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Thu, 5 Sep 2024 12:03:43 +0200 Subject: [PATCH] setup-r-dependencies: document 'pak-version: none', add 'repo' 'repo' is a better option for environments like in #918. --- NEWS.md | 11 +++++++ setup-r-dependencies/action.yaml | 51 ++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index c78df8610..14361b73f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# development version + +* `[setup-r-dependencies]` parameter `pak-version` can now be `repo` or + `none` as well. `repo` means that the action will install pak from + the configured repositories, using `install.packages()`. `repo` is + appropriate on systems that do not have access to our pak reporitory + on GitHUb. `none` means that the action does not install pak at all. + Use this if you want to install pak yourself manually. Set the + `R_LIB_FOR_PAK` environment variable to point to the library where pak + is installed. + # `v2.10.1` (2024-08-08) * `[setup-r-dependencies]` now pins `quarto-dev/quarto-actions/setup` diff --git a/setup-r-dependencies/action.yaml b/setup-r-dependencies/action.yaml index 4189fdf10..5460845c2 100644 --- a/setup-r-dependencies/action.yaml +++ b/setup-r-dependencies/action.yaml @@ -18,7 +18,16 @@ inputs: description: 'Which package(s) to install.' default: 'deps::., any::sessioninfo' pak-version: - description: 'Which pak version to use. Possible values are "stable", "rc" and "devel".' + description: | + Which pak version to use. Possible values are "stable", "rc", + "devel", "none", "repo". The first three install pak from our + repository at GitHub Pages. + "none" will skip pak installation. Use this if you want to install + pak yourself. Set the `R_LIB_FOR_PAK` environment variable to point + to the library where pak is installed. + `repo` means that the action will install pak from the configured + repositories, using `install.packages()`. `repo` is appropriate on + systems that do not have access to our pak reporitory on GitHUb. default: 'stable' working-directory: description: 'Using the working-directory keyword, you can specify the working directory of where "pkg_deps" command searches for dependencies in the "DESCRIPTION" file.' @@ -59,20 +68,34 @@ runs: run: | # Set site library path cat("::group::Set site library path\n") + libpak <- Sys.getenv("R_LIB_FOR_PAK") + if (libpak != "") { + message("R_LIB_FOR_PAK is already set to ", libpak) + } if (Sys.getenv("RENV_PROJECT") != "") { message("renv project detected, no need to set R_LIBS_SITE") - cat(sprintf("R_LIB_FOR_PAK=%s\n", .libPaths()[1]), file = Sys.getenv("GITHUB_ENV"), append = TRUE) + if (libpak == "") { + cat(sprintf("R_LIB_FOR_PAK=%s\n", .libPaths()[1]), file = Sys.getenv("GITHUB_ENV"), append = TRUE) + message("Setting R_LIB_FOR_PAK to ", .libPaths()[1]) + } q("no") } lib <- Sys.getenv("R_LIBS_SITE") if (lib == "") { lib <- file.path(dirname(.Library), "site-library") cat(sprintf("R_LIBS_SITE=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE) - cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE) message("Setting R_LIBS_SITE to ", lib) + if (libpak == "") { + cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE) + message("Setting R_LIB_FOR_PAK to ", lib) + } } else { message("R_LIBS_SITE is already set to ", lib) - cat(sprintf("R_LIB_FOR_PAK=%s\n", strsplit(lib, .Platform$path.sep)[[1]][[1]]), file = Sys.getenv("GITHUB_ENV"), append = TRUE) + if (libpak == "") { + plib <- strsplit(lib, .Platform$path.sep)[[1]][[1]] + cat(sprintf("R_LIB_FOR_PAK=%s\n", plib), file = Sys.getenv("GITHUB_ENV"), append = TRUE) + message("Setting R_LIB_FOR_PAK to ", plib) + } } if (nchar("${{ env.R_LIBS_USER && 'ok' || '' }}") == 0) { message("R_LIBS_USER GH env var is unset, setting now: ", Sys.getenv("R_LIBS_USER")) @@ -90,13 +113,17 @@ runs: cat("::group::Install pak\n") lib <- Sys.getenv("R_LIB_FOR_PAK") dir.create(lib, showWarnings = FALSE, recursive = TRUE) - install.packages("pak", lib = lib, repos = sprintf( - "https://r-lib.github.io/p/pak/%s/%s/%s/%s", - "${{ inputs.pak-version }}", - .Platform$pkgType, - R.Version()$os, - R.Version()$arch - )) + if ("${{ inputs.pak-version }}" == "repo") { + install.packages("pak", lib = lib) + } else { + install.packages("pak", lib = lib, repos = sprintf( + "https://r-lib.github.io/p/pak/%s/%s/%s/%s", + "${{ inputs.pak-version }}", + .Platform$pkgType, + R.Version()$os, + R.Version()$arch + )) + } cat("::endgroup::\n") shell: Rscript {0} @@ -107,7 +134,7 @@ runs: 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", "${{ inputs.pak-version }}", .Platform$pkgType, R.Version()$os, R.Version()$arch))' + $SUDO R -q -e 'if ("${{ inputs.pak-version }}" == "repo") { install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK")) } else { install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK"), repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "${{ inputs.pak-version }}", .Platform$pkgType, R.Version()$os, R.Version()$arch)) }' echo "::endgroup::" shell: bash