Skip to content

Commit

Permalink
New testing process in GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Feb 12, 2024
1 parent 582357c commit abc8048
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 17 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/test-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ jobs:
RSPM = "https://packagemanager.rstudio.com/all/latest",
CRAN = "https://cloud.r-project.org"
))
message("Installing ", length(toinstall)," packages")
message("Installing ", length(toinstall)," packages: ", paste0(toinstall, collapse = ","))
library(pak, lib.loc = Sys.getenv("R_LIB_FOR_PAK"))
install.packages(toinstall, dependencies = TRUE, verbose = TRUE, quiet = TRUE)
# Install packages with pak
end <- lapply(toinstall, function(x){
aa <- try(pak::pkg_install(x, upgrade = TRUE, dependencies = TRUE), silent = TRUE)
if(inherits(aa, "try-error")) return(FALSE)
return(TRUE)
})
# Update binary
# update.packages(type = "binary")
shell: Rscript {0}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_ci/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_snaps
CITATION
allpackages.csv
results.md
results.*
3 changes: 3 additions & 0 deletions tests/testthat/test_ci/test-full_cff.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ test_that("Test ALL installed packages", {
installed <- as.data.frame(installed.packages()[, c("Package", "Version")])
installed <- installed[order(installed$Package), ]

end <- match("ctv", installed$Package) + 10
installed <- installed[seq_len(end), ]

rownames(installed) <- seq_len(nrow(installed))

l <- nrow(installed)
Expand Down
114 changes: 102 additions & 12 deletions tests/testthat/test_ci/test-new.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

library(cffr)

installed <- as.data.frame(installed.packages()[, c("Package", "Version")])
installed <- installed[order(installed$Package), ]
# installed <- installed[1:50, ]


rownames(installed) <- seq_len(nrow(installed))

Expand All @@ -23,8 +21,9 @@ for (i in seq_len(nrow(installed))) {
# Display some advances
message(
"Testing ", i, "/", nrow(installed),
" (", sprintf("%05.02f", i / nrow(installed) * 100), "%) ["
,installed[i, ]$Package, "]")
" (", sprintf("%05.02f", i / nrow(installed) * 100), "%) [",
installed[i, ]$Package, "]"
)
cit_path <- file.path(find.package(installed[i, ]$Package), "CITATION")


Expand All @@ -36,14 +35,16 @@ for (i in seq_len(nrow(installed))) {

# Add cffobj
cffobj <- try(
cff_create(pkg, gh_keywords = FALSE, dependencies = FALSE), silent = TRUE)
cff_create(pkg, gh_keywords = FALSE, dependencies = FALSE),
silent = TRUE
)

if(inherits(cffobj, "cff")){
s <- try(cff_validate(cffobj, verbose = FALSE), silent = TRUE)
if(!is.logical(s)) s <- FALSE
if (inherits(cffobj, "cff")) {
s <- try(cff_validate(cffobj, verbose = FALSE), silent = TRUE)
if (!is.logical(s)) s <- FALSE

res <- c(res, s)
note <- c(note, "ok, cff")
res <- c(res, s)
note <- c(note, "")
} else {
res <- c(res, FALSE)
note <- c(note, "Other errors")
Expand All @@ -54,9 +55,98 @@ installed$with_citation <- withcit
installed$is_ok <- res
installed$note <- note

# Create report

options(cli.width = 60)
outmd <- file.path(dir_path, "results.md")
unlink(outmd)

cat("# Test all files\n\n", file = outmd)
write("## Session info\n", outmd, append = TRUE)
write("<details>", outmd, append = TRUE)
write("\n```r", outmd, append = TRUE)
conn <- file(outmd, "a")
capture.output(sessioninfo::session_info(), file = conn)
close(conn)
write("```\n", outmd, append = TRUE)
write("</details>", outmd, append = TRUE)

errors <- installed[installed$is_ok == FALSE, ]
capture.output(knitr::kable(errors), file = outmd)
errother <- errors$Package[errors$note == "Other errors"]
errcff <- setdiff(errors$Package, errother)
errother_df <- installed[installed$Package %in% errother, c(1, 2)]



write("\n## High level summary", outmd, append = TRUE)
write(paste0("\n- I checked ", nrow(installed), " packages"),
outmd,
append = TRUE
)
write(paste0("- Invalid cff in ", length(errcff), " packages"),
outmd,
append = TRUE
)
write(paste0("- I failed to generate cff in ", length(errother), " packages"),
outmd,
append = TRUE
)

okrate <- 100 * (1 - length(errcff) / (nrow(installed) - length(errother)))
write(paste0("- OK Rate: ", round(okrate, 2), "%"), outmd, append = TRUE)


if (nrow(errors) == 0) {
write("\nNo errors, hooray!", outmd, append = TRUE)
} else {
write("\nPackages with errors:", outmd, append = TRUE)
conn <- file(outmd, "a")
capture.output(knitr::kable(errors, row.names = FALSE),
file = conn
)
close(conn)


if (length(errother) > 0) {
pk <- paste0(errother, collapse = ", ")
line <- paste0("\n## Packages with errors not coming from cff")
write(line, outmd, append = TRUE)
conn <- file(outmd, "a")
capture.output(knitr::kable(errother_df, row.names = FALSE),
file = conn
)
close(conn)
}

if (length(errcff) > 0) {
write("\n## cff errors reported", outmd, append = TRUE)
# Prepare links
cfflist <- paste0("- [", errcff, "](#", tolower(errcff), ")",
collapse = "\n"
)
write(cfflist, outmd, append = TRUE)

for (j in errcff) {
write(paste0("\n### ", j, ""), outmd, append = TRUE)
write("\n#### cff object\n", outmd, append = TRUE)
write("<details>", outmd, append = TRUE)
write("\n```r", outmd, append = TRUE)
cff <- cff_create(j, gh_keywords = FALSE, dependencies = FALSE)
conn <- file(outmd, "a")
capture.output(print(cff), file = conn)
close(conn)
write("```\n", outmd, append = TRUE)
write("</details>", outmd, append = TRUE)


write("\n#### Validation results", outmd, append = TRUE)

s <- cff_validate(cff, verbose = FALSE)
df <- attr(s, "errors")
conn <- file(outmd, "a")
capture.output(knitr::kable(df, row.names = FALSE), file = conn)
close(conn)
}
}
}

Check warning on line 152 in tests/testthat/test_ci/test-new.R

View workflow job for this annotation

GitHub Actions / Run lintr scanning

file=tests/testthat/test_ci/test-new.R,line=152,col=1,[trailing_blank_lines_linter] Trailing blank lines are superfluous.

Check notice

Code scanning / lintr

Trailing blank lines are superfluous. Note test

Trailing blank lines are superfluous.

0 comments on commit abc8048

Please sign in to comment.