Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup-r-dependencies: document 'pak-version: none', add 'repo' #919

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +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.

* `[setup-r]` now has a `working-directory` parameter, to be able to
specify the location of the `renv.lock` file (#922, @calderonsamuel).

Expand Down
51 changes: 39 additions & 12 deletions setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
gaborcsardi marked this conversation as resolved.
Show resolved Hide resolved
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.'
Expand Down Expand Up @@ -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"))
Expand All @@ -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}

Expand All @@ -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

Expand Down
Loading