Skip to content

Commit 63757ec

Browse files
authored
Should stop execution if it can't find .inst/apps (#235)
1 parent 35f8b59 commit 63757ec

File tree

12 files changed

+28
-17
lines changed

12 files changed

+28
-17
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Imports:
1616
progress,
1717
callr,
1818
sessioninfo,
19+
rprojroot,
1920
rstudioapi (>= 0.11),
2021
cli
2122
Suggests:

R/accept_snaps.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @inheritParams fix_snaps
66
#' @export
77
accept_snaps <- function(
8-
repo_dir = "."
8+
repo_dir = rprojroot::find_package_root_file()
99
) {
1010

1111
app_paths <- repo_apps_paths(repo_dir)
@@ -32,7 +32,7 @@ accept_snaps <- function(
3232

3333

3434
# Removes all snaps that are below the minimum R version
35-
remove_snaps_cruft <- function(repo_dir = ".", min_r_version = "3.6") {
35+
remove_snaps_cruft <- function(repo_dir = rprojroot::find_package_root_file(), min_r_version = "3.6") {
3636
app_paths <- repo_apps_paths(repo_dir)
3737

3838
pb <- progress_bar(

R/apps.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ is_manual_app <- function(app_dir) {
4646

4747

4848
### Start GHA
49-
apps_with_tests <- function(repo_dir = ".") {
49+
apps_with_tests <- function(repo_dir = rprojroot::find_package_root_file()) {
5050
basename(Filter(x = repo_apps_paths(repo_dir), has_tests_folder))
5151
}
52-
repo_apps_path <- function(repo_dir = ".") {
52+
repo_apps_path <- function(repo_dir = rprojroot::find_package_root_file()) {
5353
file.path(repo_dir, "inst", "apps")
5454
}
55-
repo_apps_paths <- function(repo_dir = ".") {
55+
repo_apps_paths <- function(repo_dir = rprojroot::find_package_root_file()) {
5656
dir(repo_apps_path(repo_dir), pattern = "^\\d\\d\\d-", full.names = TRUE)
5757
}
58-
repo_app_path <- function(app_name, repo_dir = ".") {
58+
repo_app_path <- function(app_name, repo_dir = rprojroot::find_package_root_file()) {
5959
file.path(repo_apps_path(repo_dir), app_name)
6060
}
6161

R/fix_snaps.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fix_snaps <- function(
2929
ask_apps = FALSE,
3030
ask_branches = TRUE,
3131
ask_if_not_main = TRUE,
32-
repo_dir = "."
32+
repo_dir = rprojroot::find_package_root_file()
3333
) {
3434
original_sys_call <- sys.call()
3535
ask_apps <- as.logical(ask_apps)
@@ -39,6 +39,10 @@ fix_snaps <- function(
3939

4040
apps_folder <- file.path(repo_dir, "inst", "apps")
4141

42+
if (!dir.exists(apps_folder)) {
43+
stop("Apps folder does not exist: ", apps_folder)
44+
}
45+
4246
verify_if_not_main_branch(ask_if_not_main, repo_dir = repo_dir)
4347
verify_no_git_changes(repo_dir = repo_dir, apps_folder = apps_folder)
4448
verify_no_untracked_files(repo_dir = repo_dir, apps_folder = apps_folder)
@@ -275,7 +279,7 @@ fix_snaps <- function(
275279
f = function(app_name) {
276280
pb$tick(tokens = list(name = app_name))
277281
# Use `.` as `git_cmd_` runs within `repo_dir`
278-
app_path <- repo_app_path(repo_dir = ".", app_name = app_name)
282+
app_path <- repo_app_path(repo_dir = rprojroot::find_package_root_file(), app_name = app_name)
279283
git_cmd_("git checkout -- ", app_path)
280284
git_cmd_("git clean -df -- ", app_path)
281285
}
@@ -291,7 +295,7 @@ fix_snaps <- function(
291295

292296

293297
# Note: Logic should be duplicated in pre-check GHA workflow
294-
verify_no_new_snaps <- function(repo_dir = ".", folder = "inst/apps") {
298+
verify_no_new_snaps <- function(repo_dir = rprojroot::find_package_root_file(), folder = "inst/apps") {
295299
new_snaps <- dir(file.path(repo_dir, folder), pattern = "\\.new", recursive = TRUE, include.dirs = FALSE)
296300
if (length(new_snaps) > 0) {
297301
message("There should be no `.new` _snaps in `", folder, "`. Found: \n", paste0("* ", new_snaps, collapse = "\n"))

R/save-test-results.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @inheritParams test_in_local
1111
#' @rdname test-results
1212
#' @export
13-
save_test_results <- function(output, gha_branch_name, pr_number, username, repo_dir = ".") {
13+
save_test_results <- function(output, gha_branch_name, pr_number, username, repo_dir = rprojroot::find_package_root_file()) {
1414
if (!inherits(output, "shinycoreci_test_output")) {
1515
stop("`output` must be an object returned by test_in_local()", call. = FALSE)
1616
}

R/test-in-local.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_in_local <- function(
2323
assert = TRUE,
2424
timeout = 10 * 60,
2525
retries = 2,
26-
repo_dir = "."
26+
repo_dir = rprojroot::find_package_root_file()
2727
) {
2828
retries <- as.numeric(retries)
2929
repo_dir <- normalizePath(repo_dir, mustWork = TRUE)

R/view-test-images.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' @param repo_dir directory to the shinycoreci repo
44
#' @export
5-
view_test_images <- function(repo_dir = ".") {
5+
view_test_images <- function(repo_dir = rprojroot::find_package_root_file()) {
66
app_folders <- Filter(repo_apps_paths(repo_dir), f = function(app_folder) {
77
dir.exists(file.path(app_folder, "tests/testthat/_snaps"))
88
})

man/accept_snaps.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fix_snaps.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/test-results.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)