-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from nmfs-fish-tools/style-doc-code
Style code and document
- Loading branch information
Showing
3 changed files
with
119 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0002-0396-7044")), | ||
person("Kelli", "Johnson", , "[email protected]", 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", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0002-0396-7044")), | ||
person("Kelli", "Johnson", , "[email protected]", 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
} | ||
} | ||
} | ||
# 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.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
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) | ||
}) |