diff --git a/DESCRIPTION b/DESCRIPTION index 4069a36..bc36a82 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,29 +1,29 @@ -Package: ghactions4r -Title: Use GitHub Actions Reusable Workflows for R Packages -Version: 0.2.0 -Authors@R: c( - person("Kathryn", "Doering", , "kathryn.doering@noaa.gov", role = c("aut", "cre"), - comment = c(ORCID = "0000-0002-0396-7044")), - person("Kelli", "Johnson", , "kelli.johnson@noaa.gov", role = "aut"), - person("Bai", "Li", role = "aut") - ) -Description: Provides functions to allow users to set up github action - workflows related to R packages. -License: CC0 -Imports: - cli, - usethis -Suggests: - dplyr, - knitr, - rmarkdown, - rvest, - testthat (>= 3.0.0), - visNetwork -VignetteBuilder: - knitr -Config/testthat/edition: 3 -Encoding: UTF-8 -LazyData: true -Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +Package: ghactions4r +Title: Use GitHub Actions Reusable Workflows for R Packages +Version: 0.2.0 +Authors@R: c( + person("Kathryn", "Doering", , "kathryn.doering@noaa.gov", role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-0396-7044")), + person("Kelli", "Johnson", , "kelli.johnson@noaa.gov", role = "aut"), + person("Bai", "Li", role = "aut") + ) +Description: Provides functions to allow users to set up github action + workflows related to R packages. +License: CC0 +Imports: + cli, + usethis +Suggests: + dplyr, + knitr, + rmarkdown, + rvest, + testthat (>= 3.0.0), + visNetwork +VignetteBuilder: + knitr +Config/testthat/edition: 3 +Encoding: UTF-8 +LazyData: true +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 diff --git a/R/input_checks.R b/R/input_checks.R index af96fe6..f9ee0e4 100644 --- a/R/input_checks.R +++ b/R/input_checks.R @@ -1,32 +1,32 @@ -# functions to check inputs - -#' Check the workflow name is formatted correctly -#' -#' Basically check that it is a filename that ends in .yml -#' @template workflow_name -check_workflow_name <- function(workflow_name) { - stopifnot(is.character(workflow_name)) - stopifnot(length(workflow_name) == 1) - get_ext <- grep("\\.yml$", workflow_name) - stopifnot(isTRUE(length(get_ext) == 1)) - return(invisible(workflow_name)) -} - -#' Validate additional arguments for R functions -#' -#' @inheritParams use_r_cmd_check -validate_additional_args <- function(additional_args) { - if (!is.null(additional_args)) { - if (!is.list(additional_args)) { - cli::cli_abort("{.var additional_args} must be a named list.") - } - invalid_platforms <- setdiff(names(additional_args), c("windows", "macos", "ubuntu")) - if (length(invalid_platforms) > 0 | is.null(invalid_platforms)) { - cli::cli_abort("Invalid platform in {.var additional_args}: {.val {invalid_platforms}}. - Allowed platforms are {.val windows}, {.val macos}, and {.val ubuntu}.") - } - if (!all(vapply(additional_args, is.character, logical(1)))) { - cli::cli_abort("All values in {.var additional_args} must be character vectors.") - } - } -} \ No newline at end of file +# functions to check inputs + +#' Check the workflow name is formatted correctly +#' +#' Basically check that it is a filename that ends in .yml +#' @template workflow_name +check_workflow_name <- function(workflow_name) { + stopifnot(is.character(workflow_name)) + stopifnot(length(workflow_name) == 1) + get_ext <- grep("\\.yml$", workflow_name) + stopifnot(isTRUE(length(get_ext) == 1)) + return(invisible(workflow_name)) +} + +#' Validate additional arguments for R functions +#' +#' @inheritParams use_r_cmd_check +validate_additional_args <- function(additional_args) { + if (!is.null(additional_args)) { + if (!is.list(additional_args)) { + cli::cli_abort("{.var additional_args} must be a named list.") + } + invalid_platforms <- setdiff(names(additional_args), c("windows", "macos", "ubuntu")) + if (length(invalid_platforms) > 0 | is.null(invalid_platforms)) { + cli::cli_abort("Invalid platform in {.var additional_args}: {.val {invalid_platforms}}. + Allowed platforms are {.val windows}, {.val macos}, and {.val ubuntu}.") + } + if (!all(vapply(additional_args, is.character, logical(1)))) { + cli::cli_abort("All values in {.var additional_args} must be character vectors.") + } + } +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b7e9a55..6fc9cf3 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,52 +1,58 @@ -temp_path <- file.path(tempdir(), "rcmdcheck") -dir.create(temp_path) -old_wd <- getwd() -setwd(temp_path) -on.exit(setwd(old_wd), add = TRUE) -on.exit(unlink(temp_path, recursive = TRUE), add = TRUE) -# comment out below b/c causes an error when running check on codespaces -# on.exit(usethis::proj_set("."), add = TRUE) -pkg <- usethis::create_package(".") -usethis::proj_set(".") - -test_that("add_args() works with additional_args", { - use_update_pkgdown() - workflow_name <- "call-update-pkgdown.yml" - additional_args <- list( - ubuntu = c("sudo apt-get update", - "sudo apt-get install -y libcurl4-openssl-dev"), - windows = c("tree"), - macos = c("brew install curl") - ) - - add_args(workflow_name = workflow_name, - additional_args = additional_args) - path <- file.path(".github", "workflows", workflow_name) - expect_true(file.exists(path)) - test <- readLines(path) - expect_snapshot(test) -}) - -test_that("add_args() works with txt and prev_line", { - use_update_pkgdown() - workflow_name <- "call-update-pkgdown.yml" - path <- file.path(".github", "workflows", workflow_name) - - txt <- readLines(path) - prev_line <- grep( - paste0( - "uses: nmfs-fish-tools/ghactions4r/.github/workflows/", - gsub("call-", "", workflow_name), - "@main" - ), - txt, - fixed = TRUE - ) - add_args(workflow_name = workflow_name, - additional_args = list(ubuntu = "sudo apt-get install --only-upgrade libstdc++6"), - txt = txt, - prev_line = prev_line) - expect_true(file.exists(path)) - test <- readLines(path) - expect_snapshot(test) -}) \ No newline at end of file +temp_path <- file.path(tempdir(), "rcmdcheck") +dir.create(temp_path) +old_wd <- getwd() +setwd(temp_path) +on.exit(setwd(old_wd), add = TRUE) +on.exit(unlink(temp_path, recursive = TRUE), add = TRUE) +# comment out below b/c causes an error when running check on codespaces +# on.exit(usethis::proj_set("."), add = TRUE) +pkg <- usethis::create_package(".") +usethis::proj_set(".") + +test_that("add_args() works with additional_args", { + use_update_pkgdown() + workflow_name <- "call-update-pkgdown.yml" + additional_args <- list( + ubuntu = c( + "sudo apt-get update", + "sudo apt-get install -y libcurl4-openssl-dev" + ), + windows = c("tree"), + macos = c("brew install curl") + ) + + add_args( + workflow_name = workflow_name, + additional_args = additional_args + ) + path <- file.path(".github", "workflows", workflow_name) + expect_true(file.exists(path)) + test <- readLines(path) + expect_snapshot(test) +}) + +test_that("add_args() works with txt and prev_line", { + use_update_pkgdown() + workflow_name <- "call-update-pkgdown.yml" + path <- file.path(".github", "workflows", workflow_name) + + txt <- readLines(path) + prev_line <- grep( + paste0( + "uses: nmfs-fish-tools/ghactions4r/.github/workflows/", + gsub("call-", "", workflow_name), + "@main" + ), + txt, + fixed = TRUE + ) + add_args( + workflow_name = workflow_name, + additional_args = list(ubuntu = "sudo apt-get install --only-upgrade libstdc++6"), + txt = txt, + prev_line = prev_line + ) + expect_true(file.exists(path)) + test <- readLines(path) + expect_snapshot(test) +})