Skip to content

Commit

Permalink
Install pak into the site library (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Oct 20, 2022
1 parent f0c19f4 commit 299ee23
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,54 @@ inputs:
runs:
using: "composite"
steps:
- name: Installing pak querying dependencies
- name: Set site library path
run: |
# Set site library path
cat("::group::Set site library path\n")
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)
message("Setting R_LIBS_SITE to ", lib)
} else {
message("R_LIBS_SITE is already set to ", lib)
}
cat("::endgroup::\n")
shell: Rscript {0}

- name: Install pak (Windows)
if: runner.os == 'Windows'
run: |
# Install pak
cat("::group::Install pak\n")
dir.create(Sys.getenv("R_LIBS_SITE"), showWarnings = FALSE, recursive = TRUE)
install.packages("pak", repos = "https://r-lib.github.io/p/pak/${{ inputs.pak-version }}/", lib = Sys.getenv("R_LIBS_SITE"))

This comment has been minimized.

Copy link
@krlmlr

krlmlr Oct 27, 2022

Member

In our runs, we have:

  R_LIBS_SITE is already set to /usr/local/lib/R/site-library/:/usr/lib/R/site-library:/usr/lib/R/library

I believe creating the directory should be the responsibility of the previous step, and this step should install into .Library.site ?

This is with install-r: false, for performance reasons.

Example: https://github.com/cynkra/dm/actions/runs/3331327794/jobs/5510934525#step:6:351

This comment has been minimized.

Copy link
@krlmlr

krlmlr Oct 27, 2022

Member

This does not occur with install-r: true, because there the site library consists of one single path. See https://github.com/cynkra/dm/actions/runs/3334237471/jobs/5516989529#step:6:1426.

This comment has been minimized.

Copy link
@gaborcsardi

gaborcsardi Oct 27, 2022

Author Member

I am sorry, I don't understand what the problem is.

cat("::endgroup::\n")
shell: Rscript {0}

- name: Install pak (Unix)
if: runner.os != 'Windows'
run: |
# Install pak
echo "::group::Install pak"
sudo -E R -q -e 'dir.create(Sys.getenv("R_LIBS_SITE"), recursive = TRUE, showWarnings = FALSE)'
sudo -E R -q -e 'install.packages("pak", repos = "https://r-lib.github.io/p/pak/${{ inputs.pak-version }}/", lib = Sys.getenv("R_LIBS_SITE"))'

This comment has been minimized.

Copy link
@krlmlr

krlmlr Oct 27, 2022

Member

Of course, this affects Linux. Took me a bit of time to understand the difference between the two steps. Can we do shell: sudo -E Rscript {0} ?

This comment has been minimized.

Copy link
@gaborcsardi

gaborcsardi Oct 27, 2022

Author Member

What is wrong with this one?

echo "::endgroup::"
shell: bash

- name: Query dependencies
id: install
run: |
## Installing pak
cat("::group::Installing pak\n")
# Dependency resolution
cat("::group::Dependency resolution\n")
cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("r-version=", if (grepl("development", rv <- R.Version()$version.string)) as.character(getRversion()) else rv, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
install.packages("pak", repos = "https://r-lib.github.io/p/pak/${{ inputs.pak-version }}/")
cat("::endgroup::\n")
cat("::group::Dependency resolution\n")
needs <- sprintf("Config/Needs/%s", strsplit("${{ inputs.needs }}", "[[:space:],]+")[[1]])
deps <- strsplit("${{ inputs.packages }}", "[[:space:],]+")[[1]]
extra_deps <- strsplit("${{ inputs.extra-packages }}", "[[:space:],]+")[[1]]
dir.create(".github", showWarnings=FALSE)
Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
library(pak, lib.loc = .Library.site)
pak::lockfile_create(
c(deps, extra_deps),
lockfile = ".github/pkg.lock",
Expand All @@ -68,11 +101,20 @@ runs:

- name: Install dependencies
run: |
## Installing/Updating packages
cat("::group::Installing/updating packages\n")
# Install/Update packages
cat("::group::Install/update packages\n")
Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
library(pak, lib.loc = .Library.site)
pak::lockfile_install(".github/pkg.lock")
## Clean up lock file
unlink(".github/pkg.lock")
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}

- name: Session info
run: |
# Session info
cat("::group::Session info\n")
if (requireNamespace("sessioninfo", quietly = TRUE)) {
if (packageVersion("sessioninfo") >= "1.2.1") {
Expand All @@ -84,8 +126,6 @@ runs:
} else {
sessionInfo()
}
## Clean up lock file
unlink(".github/pkg.lock")
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
Expand Down

0 comments on commit 299ee23

Please sign in to comment.