diff --git a/.github/workflows/r-cmd-check.yml b/.github/workflows/r-cmd-check.yml index 41a88b2..1da7e1b 100644 --- a/.github/workflows/r-cmd-check.yml +++ b/.github/workflows/r-cmd-check.yml @@ -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 diff --git a/R/use_r_workflows.R b/R/use_r_workflows.R index 1060883..717bc17 100644 --- a/R/use_r_workflows.R +++ b/R/use_r_workflows.R @@ -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 diff --git a/tests/testthat/_snaps/use_r_workflows.md b/tests/testthat/_snaps/use_r_workflows.md index 177b50d..f7b8fbc 100644 --- a/tests/testthat/_snaps/use_r_workflows.md +++ b/tests/testthat/_snaps/use_r_workflows.md @@ -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 diff --git a/tests/testthat/test-use_r_workflows.R b/tests/testthat/test-use_r_workflows.R index 83791ee..f0e4656 100644 --- a/tests/testthat/test-use_r_workflows.R +++ b/tests/testthat/test-use_r_workflows.R @@ -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"))