Skip to content

Commit

Permalink
attempt to resolve windows CI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Sep 13, 2023
1 parent cb3f273 commit 595a1f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
5 changes: 5 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# global variables
the <- new.env(parent = emptyenv())

# detect if we're running on CI
ci <- function() {
!is.na(Sys.getenv("CI", unset = NA))
}

# detect if we're running within R CMD build
building <- function() {
nzchar(Sys.getenv("R_CMD")) &&
Expand Down
7 changes: 6 additions & 1 deletion R/cleanse.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ cleanse <- function() {
renv_cleanse_sandbox(path = renv_paths_sandbox())

# remove empty directories in the root directory
renv_cleanse_empty(path = renv_paths_root())
# we can't do this on Windows, as some empty directories
# might also be broken junctions, and we want to keep
# those around so we can inform the user that they need
# to repair that
if (!renv_platform_windows())
renv_cleanse_empty(path = renv_paths_root())

invisible(TRUE)

Expand Down
23 changes: 15 additions & 8 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
renv_watchdog_unload()

# do some extra cleanup when running R CMD check
dirty <-
checking() &&
renv_platform_unix() &&
is.na(Sys.getenv("CI", unset = NA))

if (dirty)
if (renv_platform_unix() && checking() && !ci())
cleanse()

# flush the help db to avoid errors on reload
Expand Down Expand Up @@ -50,9 +45,21 @@ renv_zzz_load <- function() {
# make sure renv (and packages using renv!!!) use tempdir for storage
# when running tests, or R CMD check
if (checking() || testing()) {
Sys.setenv(RENV_PATHS_ROOT = Sys.getenv("RENV_PATHS_ROOT", unset = tempfile("renv-root-")))
Sys.setenv(RENV_PATHS_SANDBOX = Sys.getenv("RENV_PATHS_SANDBOX", unset = tempfile("renv-sandbox-")))

# set root directory
root <- Sys.getenv("RENV_PATHS_ROOT", unset = tempfile("renv-root-"))
Sys.setenv(RENV_PATHS_ROOT = root)

# set up sandbox -- only done on non-Windows due to strange intermittent
# test failures that seemed to occur there?
if (renv_platform_unix()) {
sandbox <- Sys.getenv("RENV_PATHS_SANDBOX", unset = tempfile("renv-sandbox-"))
Sys.setenv(RENV_PATHS_SANDBOX = sandbox)
}

# don't lock sandbox while testing / checking
options(renv.sandbox.locking_enabled = FALSE)

}

renv_metadata_init()
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-restore.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,24 @@ test_that("restore() restores packages with broken symlinks", {
renv_tests_scope("breakfast")
init()

# check it's installed
pkgpath <- renv_package_find("breakfast")
expect_true(renv_file_exists(pkgpath))

# break the cache
record <- list(Package = "breakfast", Version = "1.0.0")
cachepath <- renv_cache_find(record)
unlink(cachepath, recursive = TRUE)

# check that it's broken
expect_true(renv_file_broken(pkgpath))

# try to restore
restore()

# check that we're happy again
expect_false(renv_file_broken(pkgpath))
expect_true(renv_file_exists(pkgpath))
expect_true(renv_package_installed("breakfast"))

})
Expand Down

0 comments on commit 595a1f4

Please sign in to comment.