Skip to content

Commit

Permalink
Add depends_on_tmb option to r cmd check. #106
Browse files Browse the repository at this point in the history
  • Loading branch information
k-doering-NOAA committed Jan 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ea16bb4 commit e9fb85c
Showing 4 changed files with 94 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/r-cmd-check.yml
Original file line number Diff line number Diff line change
@@ -11,6 +11,10 @@ on:
required: false
type: number
default: 360
depends_on_tmb:
required: false
type: boolean
default: false

name: R-CMD-check
jobs:
@@ -73,6 +77,12 @@ jobs:
extra-packages: any::rcmdcheck
needs: check

- name: If dependent on TMB, install Matrix from source for windows and mac
if: inputs.depends_on_tmb == true && runner.os != 'Linux'
run: install.packages("Matrix", type = "source")
shell: Rscript {0}


- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
24 changes: 23 additions & 1 deletion R/use_r_workflows.R
Original file line number Diff line number Diff line change
@@ -2,9 +2,14 @@
#' @template workflow_name
#' @param use_full_build_matrix Run R cmd check with two older versions of R in
#' addition to the three runs that use the release version.
#' @param depends_on_tmb An option that install Matrix from source for windows
#' and Mac builds to solved a nuanced issue for packages dependent on TMB.
#' See this [google groups thread](https://groups.google.com/g/tmb-users/c/-GhmuuDP_OQ)
#' for more information.
#' @export
use_r_cmd_check <- function(workflow_name = "call-r-cmd-check.yml",
use_full_build_matrix = FALSE) {
use_full_build_matrix = FALSE,
depends_on_tmb = FALSE) {
check_workflow_name(workflow_name)
if (use_full_build_matrix) {
url_name <- "https://raw.githubusercontent.com/nmfs-fish-tools/ghactions4r/main/inst/templates/call-r-cmd-check-full.yml"
@@ -15,6 +20,23 @@ use_r_cmd_check <- function(workflow_name = "call-r-cmd-check.yml",
save_as = workflow_name,
url = url_name
)
if(depends_on_tmb) {
path_to_yml <- file.path(".github", "workflows", workflow_name)
txt <- readLines(path_to_yml)
if(use_full_build_matrix) {
prev_line <- grep("use_full_build_matrix: true", txt, fixed = TRUE)
} else {
prev_line <- grep(
"uses: nmfs-fish-tools/ghactions4r/.github/workflows/r-cmd-check.yml@main",
txt,
fixed = TRUE)
txt <- append(txt, " with:", prev_line)
prev_line <- prev_line + 1
}
txt <- append(txt, " depends_on_tmb: true", prev_line)
writeLines(txt, path_to_yml)
}
invisible(workflow_name)
}

#' workflow for calculating code coverage
43 changes: 43 additions & 0 deletions tests/testthat/_snaps/use_r_workflows.md
Original file line number Diff line number Diff line change
@@ -38,6 +38,49 @@
[14] " with:"
[15] " use_full_build_matrix: true"

# use_r_cmd_check() works with full build option and tmb

Code
test
Output
[1] "# Run r cmd check"
[2] "name: call-r-cmd-check"
[3] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows"
[4] "on:"
[5] "# The default build trigger is to run the action on every push and pull request, for any branch"
[6] " push:"
[7] " pull_request:"
[8] " # To run the default repository branch weekly on sunday, uncomment the following 2 lines"
[9] " #schedule:"
[10] " #- cron: '0 0 * * 0'"
[11] "jobs:"
[12] " call-workflow:"
[13] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/r-cmd-check.yml@main"
[14] " with:"
[15] " use_full_build_matrix: true"
[16] " depends_on_tmb: true"

---

Code
test
Output
[1] "# Run r cmd check"
[2] "name: call-r-cmd-check"
[3] "# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows"
[4] "on:"
[5] "# The default build trigger is to run the action on every push and pull request, for any branch"
[6] " push:"
[7] " pull_request:"
[8] " # To run the default repository branch weekly on sunday, uncomment the following 2 lines"
[9] " #schedule:"
[10] " #- cron: '0 0 * * 0'"
[11] "jobs:"
[12] " call-workflow:"
[13] " uses: nmfs-fish-tools/ghactions4r/.github/workflows/r-cmd-check.yml@main"
[14] " with:"
[15] " depends_on_tmb: true"

# use_calc_coverage()) works

Code
18 changes: 18 additions & 0 deletions tests/testthat/test-use_r_workflows.R
Original file line number Diff line number Diff line change
@@ -26,6 +26,24 @@ test_that("use_r_cmd_check() works with full build option", {
expect_snapshot(test)
})

test_that("use_r_cmd_check() works with full build option and tmb", {
name <- "call-full-build-check.yml"
path <- file.path(".github", "workflows", name)
use_r_cmd_check(workflow_name = name, use_full_build_matrix = TRUE, depends_on_tmb = TRUE)
expect_true(file.exists(path))
test <- readLines(path)
expect_snapshot(test)
})

test_that("use_r_cmd_check() works with full build option and tmb", {
name <- "call-full-tmb.yml"
path <- file.path(".github", "workflows", name)
use_r_cmd_check(workflow_name = name, use_full_build_matrix = FALSE, depends_on_tmb = TRUE)
expect_true(file.exists(path))
test <- readLines(path)
expect_snapshot(test)
})

test_that("use_calc_coverage()) works", {
use_calc_coverage()
expect_true(file.exists(".github/workflows/call-calc-coverage.yml"))

0 comments on commit e9fb85c

Please sign in to comment.