Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include qc report in a separate step #12

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ on:
workflow_call:

concurrency:
group: check-test-${{ github.event.pull_request.number || github.ref }}
group: check-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check-test:
check:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
Expand All @@ -36,7 +38,7 @@ jobs:
- name: Check 📦
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(error_on = "error")
rcmdcheck::rcmdcheck(error_on = "error", args = "--no-tests")
shell: Rscript {0}


4 changes: 3 additions & 1 deletion .github/workflows/lintr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
Expand All @@ -41,7 +43,7 @@ jobs:

- name: Import .lintr
run: |
wget -O .lintr https://raw.githubusercontent.com/Boehringer-Ingelheim/dv.templates/main/.lintr
wget -O .lintr https://raw.githubusercontent.com/boehringer-ingelheim/dv.templates/main/.lintr

- name: Lintr 🔍
run: lintr::lint_package()
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ jobs:
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Install package dependencies 📄
uses: boehringer-ingelheim/dv.templates/.github/actions/dependencies@main
uses: boehringer-ingelheim/dv.templates/.github/actions/dependencies@main

- name: Get validation results
uses: actions/download-artifact@v4
with:
name: val_results
path: inst/validation/results

- name: Build site 🔧
run: pkgdown::build_site()
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/roxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/shared_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on:
workflow_call:

jobs:
check-test:
check:
name: Check 📦
uses: boehringer-ingelheim/dv.templates/.github/workflows/check.yml@main

test:
name: Test 📦
uses: boehringer-ingelheim/dv.templates/.github/workflows/test.yml@main

lintr:
name: Lintr 🔍
uses: boehringer-ingelheim/dv.templates/.github/workflows/lintr.yml@main
Expand All @@ -26,6 +30,7 @@ jobs:
pkgdown:
name: Pkgdown 📖
uses: boehringer-ingelheim/dv.templates/.github/workflows/pkgdown.yml@main
needs: test

styler:
name: Styler 🌐
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/styler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: Test 📦

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:

concurrency:
group: test-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Checkout Repo Templates
uses: actions/checkout@v4
with:
ref: include_qc_separate_steps
repository: boehringer-ingelheim/dv.templates
path: templates

- name: Install package dependencies 📄
uses: boehringer-ingelheim/dv.templates/.github/actions/dependencies@main

- name: Test 📦
run: Rscript templates/scripts/test.R

- name: Archive validation results
uses: actions/upload-artifact@v4
with:
name: val_results
path: inst/validation/results
126 changes: 126 additions & 0 deletions scripts/test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#! /usr/local/bin/Rscript

success <- c(
test = FALSE,
valdoc = FALSE
)

# Getting package information ----
pkg_name <- read.dcf("DESCRIPTION")[1, "Package"]
pkg_version <- read.dcf("DESCRIPTION")[1, "Version"]

# Building ----

message("############################")
message("###### INSTALLING (S) ######")
message("############################")

devtools::install(upgrade = FALSE, args = "--install-tests")

message("############################")
message("###### INSTALLING (F) ######")
message("############################")

# Testing ----

message("##########################")
message("###### TESTING (S) ######")
message("##########################")

reporter <- testthat::MultiReporter$new(
list(
testthat::ProgressReporter$new(),
testthat::SummaryReporter$new(file = file.path(getwd(), "tests", "test-out.xml"))
)
)

test_results <- tibble::as_tibble(
withr::with_envvar(
new = list(CI = TRUE, no_proxy = "127.0.0.1", NOT_CRAN = TRUE, TESTTHAT_CPUS = 1),
code = {
testthat::test_package(pkg_name, reporter, stop_on_failure = FALSE)
}
)
)

success[["test"]] <- sum(test_results[["failed"]]) == 0

message("##########################")
message("###### TESTING (F) ######")
message("##########################")

# Validation ----

message("#######################################")
message("###### RENDERING VALIDATION (S) ######")
message("#######################################")

success[["valdoc"]] <- local({
# This is evaluated inside a local because, otherwise, all the variables created in the chunks of the rendered
# document leak into the environment

validation_root <- "./inst/validation"
validation_report_rmd <- file.path(validation_root, "val_report.Rmd")
validation_report_html <- "val_report.html"
validation_results <- file.path(validation_root, "results")
val_param_rds <- file.path(validation_results, "val_param.rds")

stopifnot(dir.exists(validation_root))
stopifnot(file.exists(validation_report_rmd))

stopifnot(dir.exists(validation_results))
unlink(list.files(validation_results))

saveRDS(
list(
package = pkg_name,
tests = test_results,
version = pkg_version
),
val_param_rds
)

rmarkdown::render(
input = validation_report_rmd,
params = list(
package = pkg_name,
tests = test_results,
version = pkg_version
),
output_dir = validation_results,
output_file = validation_report_html
)

# We use one of the leaked variables, created inside the validation report to asses if the validation is succesful or not
VALIDATION_PASSED
})


message("#######################################")
message("###### RENDERING VALIDATION (F) ######")
message("#######################################")

# Exit ----
message("##############################")
message("###### BUILD RESULT (S) ######")
message("##############################")

message(paste("Was", names(success), "successful?\t", success, collapse = "\n"))

# Write GITHUB ACTIONS summary
github_summary_file <- Sys.getenv("GITHUB_STEP_SUMMARY")
summary <- "# Test Summary"
summary <- c(
summary,
purrr::imap_chr(success, ~ paste(" - ", if (.x) "\U02705" else "\U274C", "\t", .y))
)

CON <- file(github_summary_file, "a")
on.exit(close(CON))
writeLines(summary, CON)

stopifnot(all(success))

message("##############################")
message("###### BUILD RESULT (F) ######")
message("##############################")
Loading