diff --git a/R/accept_snaps.R b/R/accept_snaps.R index 9aedc0dd5e..0350535afb 100644 --- a/R/accept_snaps.R +++ b/R/accept_snaps.R @@ -5,7 +5,7 @@ #' @inheritParams fix_snaps #' @export accept_snaps <- function( - repo_dir = "." + repo_dir = rprojroot::find_package_root_file() ) { app_paths <- repo_apps_paths(repo_dir) @@ -32,7 +32,7 @@ accept_snaps <- function( # Removes all snaps that are below the minimum R version -remove_snaps_cruft <- function(repo_dir = ".", min_r_version = "3.6") { +remove_snaps_cruft <- function(repo_dir = rprojroot::find_package_root_file(), min_r_version = "3.6") { app_paths <- repo_apps_paths(repo_dir) pb <- progress_bar( diff --git a/R/apps.R b/R/apps.R index a1fce9b4b6..6eae5c7c74 100644 --- a/R/apps.R +++ b/R/apps.R @@ -46,16 +46,16 @@ is_manual_app <- function(app_dir) { ### Start GHA -apps_with_tests <- function(repo_dir = ".") { +apps_with_tests <- function(repo_dir = rprojroot::find_package_root_file()) { basename(Filter(x = repo_apps_paths(repo_dir), has_tests_folder)) } -repo_apps_path <- function(repo_dir = ".") { +repo_apps_path <- function(repo_dir = rprojroot::find_package_root_file()) { file.path(repo_dir, "inst", "apps") } -repo_apps_paths <- function(repo_dir = ".") { +repo_apps_paths <- function(repo_dir = rprojroot::find_package_root_file()) { dir(repo_apps_path(repo_dir), pattern = "^\\d\\d\\d-", full.names = TRUE) } -repo_app_path <- function(app_name, repo_dir = ".") { +repo_app_path <- function(app_name, repo_dir = rprojroot::find_package_root_file()) { file.path(repo_apps_path(repo_dir), app_name) } diff --git a/R/fix_snaps.R b/R/fix_snaps.R index b8682265ff..6c0fd3fcf1 100644 --- a/R/fix_snaps.R +++ b/R/fix_snaps.R @@ -29,7 +29,7 @@ fix_snaps <- function( ask_apps = FALSE, ask_branches = TRUE, ask_if_not_main = TRUE, - repo_dir = "." + repo_dir = rprojroot::find_package_root_file() ) { original_sys_call <- sys.call() ask_apps <- as.logical(ask_apps) @@ -38,6 +38,9 @@ fix_snaps <- function( # validate_core_pkgs() apps_folder <- file.path(repo_dir, "inst", "apps") + if (!dir.exists(apps_folder)) { + stop("Apps folder does not exist: ", apps_folder) + } verify_if_not_main_branch(ask_if_not_main, repo_dir = repo_dir) verify_no_git_changes(repo_dir = repo_dir, apps_folder = apps_folder) @@ -275,7 +278,7 @@ fix_snaps <- function( f = function(app_name) { pb$tick(tokens = list(name = app_name)) # Use `.` as `git_cmd_` runs within `repo_dir` - app_path <- repo_app_path(repo_dir = ".", app_name = app_name) + app_path <- repo_app_path(repo_dir = rprojroot::find_package_root_file(), app_name = app_name) git_cmd_("git checkout -- ", app_path) git_cmd_("git clean -df -- ", app_path) } @@ -291,7 +294,7 @@ fix_snaps <- function( # Note: Logic should be duplicated in pre-check GHA workflow -verify_no_new_snaps <- function(repo_dir = ".", folder = "inst/apps") { +verify_no_new_snaps <- function(repo_dir = rprojroot::find_package_root_file(), folder = "inst/apps") { new_snaps <- dir(file.path(repo_dir, folder), pattern = "\\.new", recursive = TRUE, include.dirs = FALSE) if (length(new_snaps) > 0) { message("There should be no `.new` _snaps in `", folder, "`. Found: \n", paste0("* ", new_snaps, collapse = "\n")) diff --git a/R/save-test-results.R b/R/save-test-results.R index 85b4179b35..eae0d01336 100644 --- a/R/save-test-results.R +++ b/R/save-test-results.R @@ -10,7 +10,7 @@ #' @inheritParams test_in_local #' @rdname test-results #' @export -save_test_results <- function(output, gha_branch_name, pr_number, username, repo_dir = ".") { +save_test_results <- function(output, gha_branch_name, pr_number, username, repo_dir = rprojroot::find_package_root_file()) { if (!inherits(output, "shinycoreci_test_output")) { stop("`output` must be an object returned by test_in_local()", call. = FALSE) } diff --git a/R/test-in-local.R b/R/test-in-local.R index 608f200942..f8662be20e 100644 --- a/R/test-in-local.R +++ b/R/test-in-local.R @@ -23,7 +23,7 @@ test_in_local <- function( assert = TRUE, timeout = 10 * 60, retries = 2, - repo_dir = "." + repo_dir = rprojroot::find_package_root_file() ) { retries <- as.numeric(retries) repo_dir <- normalizePath(repo_dir, mustWork = TRUE) diff --git a/R/view-test-images.R b/R/view-test-images.R index 41641f0be2..348ead28f1 100644 --- a/R/view-test-images.R +++ b/R/view-test-images.R @@ -2,7 +2,7 @@ #' #' @param repo_dir directory to the shinycoreci repo #' @export -view_test_images <- function(repo_dir = ".") { +view_test_images <- function(repo_dir = rprojroot::find_package_root_file()) { app_folders <- Filter(repo_apps_paths(repo_dir), f = function(app_folder) { dir.exists(file.path(app_folder, "tests/testthat/_snaps")) }) diff --git a/man/accept_snaps.Rd b/man/accept_snaps.Rd index 4c41633ddd..609535fe9b 100644 --- a/man/accept_snaps.Rd +++ b/man/accept_snaps.Rd @@ -4,7 +4,7 @@ \alias{accept_snaps} \title{Accept all snapshot changes} \usage{ -accept_snaps(repo_dir = ".") +accept_snaps(repo_dir = rprojroot::find_package_root_file()) } \arguments{ \item{repo_dir}{Root repo folder path} diff --git a/man/fix_snaps.Rd b/man/fix_snaps.Rd index b8db9fc93b..a480ac6fab 100644 --- a/man/fix_snaps.Rd +++ b/man/fix_snaps.Rd @@ -10,7 +10,7 @@ fix_snaps( ask_apps = FALSE, ask_branches = TRUE, ask_if_not_main = TRUE, - repo_dir = "." + repo_dir = rprojroot::find_package_root_file() ) } \arguments{ diff --git a/man/test-results.Rd b/man/test-results.Rd index 8d380e307f..20f2e36a02 100644 --- a/man/test-results.Rd +++ b/man/test-results.Rd @@ -4,7 +4,13 @@ \alias{save_test_results} \title{View (and save) \code{test_in_local()} output} \usage{ -save_test_results(output, gha_branch_name, pr_number, username, repo_dir = ".") +save_test_results( + output, + gha_branch_name, + pr_number, + username, + repo_dir = rprojroot::find_package_root_file() +) } \arguments{ \item{output}{output from \code{test_in_local()}.} diff --git a/man/test_in_local.Rd b/man/test_in_local.Rd index 30bba3efd7..204f9c2f44 100644 --- a/man/test_in_local.Rd +++ b/man/test_in_local.Rd @@ -11,7 +11,7 @@ test_in_local( assert = TRUE, timeout = 10 * 60, retries = 2, - repo_dir = "." + repo_dir = rprojroot::find_package_root_file() ) } \arguments{ diff --git a/man/view_test_images.Rd b/man/view_test_images.Rd index 19c9c221e7..de84808be2 100644 --- a/man/view_test_images.Rd +++ b/man/view_test_images.Rd @@ -4,7 +4,7 @@ \alias{view_test_images} \title{View Shinytest Images} \usage{ -view_test_images(repo_dir = ".") +view_test_images(repo_dir = rprojroot::find_package_root_file()) } \arguments{ \item{repo_dir}{directory to the shinycoreci repo}