diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 10e227a..ccda0f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,43 @@ jobs: inst/validation path: templates + - name: Overwrite quality control scripts with dv.templates ones ๐Ÿงน + shell: bash + run: | + TEMPLATE_DIR="templates/inst/validation" + REPO_DIR="inst/validation" + + if test ! -d "${REPO_DIR}"; then + echo "### Quality Control documentation is not present" + echo "### Include quality control documentation or skip it by creating following file 'inst/validation/skip_qc'" + exit 1 + fi + + if test -f "${REPO_DIR}/skip_qc"; then + echo "skip_qc file found skipping qc documentation" + exit 0 + fi + + # Conserve specs.R file + cp "${REPO_DIR}/specs.R" "${TEMPLATE_DIR}/specs.R" + + set +e # Disable immediate exit in conflicting parts on error for diff command + DIFF_OUTPUT=$(diff -qr "${TEMPLATE_DIR}" "${REPO_DIR}") + set -e # Enable immediate exit on error after diff command + + echo "# Quality control files" | tee -a "${GITHUB_STEP_SUMMARY}" + + if [ -n "${DIFF_OUTPUT}" ]; then + echo "Warning: The contents of the directories are different!" | tee -a "${GITHUB_STEP_SUMMARY}" + echo "Modified files:" | tee -a "${GITHUB_STEP_SUMMARY}" + echo "$DIFF_OUTPUT" | tee -a "${GITHUB_STEP_SUMMARY}" + else + echo "The directories are identical." | tee -a "${GITHUB_STEP_SUMMARY}" + fi + + rm -rf "${REPO_DIR}" + mv "${TEMPLATE_DIR}" "${REPO_DIR}" + - name: Install package dependencies ๐Ÿ“„ uses: boehringer-ingelheim/dv.templates/.github/actions/dependencies@main diff --git a/NEWS.md b/NEWS.md index 855de90..28cf50c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,4 @@ # dv.templates 0.1.0 - add release checks +- qc check is done with centralized scripts from dv.templates diff --git a/inst/validation/run_validation.R b/inst/validation/run_validation.R index e66e4c0..465c65c 100644 --- a/inst/validation/run_validation.R +++ b/inst/validation/run_validation.R @@ -1,3 +1,7 @@ +pkg_name <- read.dcf("DESCRIPTION")[, "Package"] +pkg_version <- read.dcf("DESCRIPTION")[, "Version"] +test_results <- tibble::as_tibble(devtools::test()) + local({ # This is evaluated inside a local because, otherwise, all the variables created in the chunks of the rendered # document leak into the environment diff --git a/inst/validation/utils-validation.R b/inst/validation/utils-validation.R index 5dc7360..72a1808 100644 --- a/inst/validation/utils-validation.R +++ b/inst/validation/utils-validation.R @@ -1,32 +1,18 @@ #' Setting up the validation -#' -#' 1. Add package_name -#' 2. Copy that variable and the contents of if block to tests/testthat/setup.R -#' (If you are using the template this may already be in place for you) - -package_name <- "dv.templates" -if (FALSE) { - # validation (S) - vdoc <- source( - system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE), - local = TRUE - )[["value"]] - specs <- vdoc[["specs"]] - # validation (F) -} +if (!exists("package_name")) stop("package name must be in the environment when this script is sourced") -#' 2. For those tests that cover an specific spec +#' How to link tests and specs if (FALSE) { test_that( - vdoc[["add_spec"]]("my test description", specs[["a_spec"]]), + vdoc[["add_spec"]]("my test description", specs$a_spec), { expect_true(TRUE) } ) } -#' The specs variable on the call references the one declared in point 1 +#' The specs variable on the call references the one declared in specs.R #' 3. For those tests covering more than one spec. #' NOTE: It must be c() and not list() @@ -47,7 +33,11 @@ if (FALSE) { if (FALSE) { my_spec <- specs$my$hier$spec - test_that(vdoc$parse_spec(my_spec, "my test_description"), { + test_that(vdoc[["add_spec"]]("my test_description", my_spec), { + ... + }) + + test_that(vdoc[["add_spec"]]("my test_description", specs[["my"]][["hier"]][["spec"]]), { ... }) } diff --git a/inst/validation/val_report_child.Rmd b/inst/validation/val_report_child.Rmd index 38e631f..95cb47c 100644 --- a/inst/validation/val_report_child.Rmd +++ b/inst/validation/val_report_child.Rmd @@ -14,10 +14,14 @@ ```{r setup, message = FALSE} # Import vdoc functions ---- -vdoc <- source( - system.file("validation", "utils-validation.R", package = params[["package"]], mustWork = TRUE), - local = TRUE -)[["value"]] +vdoc <- local({ + # ########## + # package_name is used # INSIDE # the sourced file below + # ########## + package_name <- params[["package"]] + utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) + source(utils_file_path, local = TRUE)[["value"]] +}) # Set required packages ---- suppressPackageStartupMessages(stopifnot(requireNamespace("DT"))) @@ -82,6 +86,7 @@ title <- paste(result_symbol, params[["package"]], params[["version"]]) ``` ## `r title` +Date: `r format(Sys.time(), "%Y-%b-%d %H:%M:%S")` The following document generates a report for R packages, to satisfy the criteria of a "Released" status under the **Non-GxP** project. The QC report contains the following information: diff --git a/inst/validation_templates/_pkgdown.yml b/inst/validation_templates/_pkgdown.yml new file mode 100644 index 0000000..bb1ae5e --- /dev/null +++ b/inst/validation_templates/_pkgdown.yml @@ -0,0 +1,18 @@ +template: + bootstrap: 5 + +navbar: + type: inverted + structure: + left: [intro, reference, articles, tutorials, news, qc] + components: + qc: + text: Quality Control + href: articles/qc.html + +articles: + +- title: Quality Control + desc: Quality Control + contents: + - qc diff --git a/inst/validation_templates/tests/testthat/setup.R b/inst/validation_templates/tests/testthat/setup.R new file mode 100644 index 0000000..01b056d --- /dev/null +++ b/inst/validation_templates/tests/testthat/setup.R @@ -0,0 +1,11 @@ +# validation (S) +vdoc <- local({ + # ########## + # package_name is used # INSIDE # the sourced file below + # ########## + package_name <- read.dcf("../../DESCRIPTION")[, "Package"] + utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) + source(utils_file_path, local = TRUE)[["value"]] +}) +specs <- vdoc[["specs"]] +# validation (F) diff --git a/inst/validation_templates/vignettes/qc.Rmd b/inst/validation_templates/vignettes/qc.Rmd new file mode 100644 index 0000000..87bb735 --- /dev/null +++ b/inst/validation_templates/vignettes/qc.Rmd @@ -0,0 +1,32 @@ +--- +title: "Quality Control" +output: + rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Quality Control} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + echo = FALSE +) +``` + +```{r, params, echo = FALSE, include = FALSE} +val_param_rds <- "../inst/validation/results/val_param.rds" +val_param_rds_exists <- file.exists(val_param_rds) +if (file.exists(val_param_rds)) params <- readRDS(val_param_rds) +``` + +```{r, results = "asis", echo = FALSE} +if (val_param_rds_exists) { + res <- knitr::knit_child("../inst/validation/val_report_child.Rmd", quiet = TRUE, envir = environment()) + cat(res, sep = "\n") +} else { + "No quality control results found" +} +``` diff --git a/scripts/test_qc_pkg.R b/scripts/test_qc_pkg.R index 517785c..b4b582d 100644 --- a/scripts/test_qc_pkg.R +++ b/scripts/test_qc_pkg.R @@ -71,6 +71,7 @@ if (!dir.exists(validation_root)) { } if (file.exists(validation_skip)) { + writeLines("", file.path(validation_results, "skipped_qc")) success[["valdoc"]] <- NA } else { @@ -127,9 +128,9 @@ summary <- c( summary, purrr::imap_chr(success, ~{ symbol <- "\U02753" - symbol <- if (isTRUE(.x)) "\U02705" - symbol <- if (isFALSE(.x)) "\U0274C" - symbol <- if (is.na(.x)) "\U02757" + if (isTRUE(.x)) symbol <- "\U02705" + if (isFALSE(.x)) symbol <- "\U0274C" + if (is.na(.x)) symbol <- "\U02757" paste(" - ", symbol, .y) }) ) @@ -138,7 +139,7 @@ CON <- file(github_summary_file, "a") on.exit(close(CON)) writeLines(summary, CON) -stopifnot(isTRUE(all(success))) +stopifnot(all(success | is.na(sucess))) message("##############################") message("###### BUILD RESULT (F) ######") diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 92d0bdb..fb131cf 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,8 +1,11 @@ -package_name <- "dv.templates" # validation (S) -vdoc <- source( - system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE), - local = TRUE -)[["value"]] +vdoc <- local({ + # ########## + # package_name is used # INSIDE # the sourced file below + # ########## + package_name <- read.dcf("../../DESCRIPTION")[, "Package"] + utils_file_path <- system.file("validation", "utils-validation.R", package = package_name, mustWork = TRUE) + source(utils_file_path, local = TRUE)[["value"]] +}) specs <- vdoc[["specs"]] # validation (F)