Skip to content
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- Added `geom_label_aligned`, a new geom that plots text labels with non-overlapping positioning along a specified alignment axis ("horizontal" or "vertical"). It uses quadratic programming to optimize label placement and includes options for spacing (min_distance), alignment, rounded background rectangles (label_r), disabling the background rectangle (background_rect = FALSE), etc.

# Changes in version 2025.7.18 (PR#201)

- `animint2pages()` default branch is gh-pages instead of main.
- `update_gallery()` creates repos/* directories and removes errors.csv file if necessary.

# Changes in version 2025.7.10 (PR#208)

- Added Codecov integration for both R and JavaScript tests; coverage reports now available at https://app.codecov.io/github/animint/animint2
Expand Down
18 changes: 13 additions & 5 deletions R/z_pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ initial_commit <- function(local_clone, repo, viz_url, title) {
all_branches <- df_or_vec
current_master <- df_or_vec
}
# do not attempt to rename a branch to "main" when a branch with that name already exists
if (current_master != "main" && !"main" %in% all_branches) {
gert::git_branch_move(branch = current_master, new_branch = "main", repo = repo)
# do not attempt to rename a branch to "gh-pages" when a branch with that name already exists
if (current_master != "gh-pages" && !"gh-pages" %in% all_branches) {
gert::git_branch_move(branch = current_master, new_branch = "gh-pages", repo = repo)
}
gert::git_push(repo = repo, remote = "origin", set_upstream = TRUE)
}
Expand Down Expand Up @@ -209,6 +209,8 @@ update_gallery <- function(gallery_path="~/R/gallery"){
viz_owner_repo, filename)
repo.png <- file.path(
gallery_path, "repos", paste0(viz_owner_repo, ".png"))
repo.dir <- dirname(repo.png)
dir.create(repo.dir, showWarnings = FALSE)
if(!file.exists(repo.png)){
dir.create(dirname(repo.png), showWarnings=FALSE, recursive=TRUE)
download.file(viz_url("Capture.PNG"), repo.png)
Expand Down Expand Up @@ -246,9 +248,15 @@ update_gallery <- function(gallery_path="~/R/gallery"){
})
}
(meta.dt <- rbindlist(meta.dt.list))
(error.dt <- rbindlist(error.dt.list))
fwrite(meta.dt, meta.csv)
fwrite(error.dt, file.path(gallery_path, "error.csv"))
error.csv <- file.path(gallery_path, "error.csv")
if(length(error.dt.list)){
(error.dt <- rbindlist(error.dt.list))
fwrite(error.dt, error.csv)
}else{
error.dt <- NULL
if(file.exists(error.csv))file.remove(error.csv)
}
rmarkdown::render(file.path(gallery_path, "index.Rmd"))
to_add <- c(
"*.csv",
Expand Down
52 changes: 47 additions & 5 deletions tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ test_that("error for viz with no source", {
}, "plot.list does not contain option named source, which is required by animint2pages")
})

get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv"))
expect_Capture <- function(L){
expect_gt(file.size(file.path(L$local_clone,"Capture.PNG")), 0)
}
expect_no_Capture <- function(L){
expect_false(file.exists(file.path(L$local_clone,"Capture.PNG")))
}
## The test below requires a github token with repo delete
## permission. Read
## https://github.com/animint/animint2/wiki/Testing#installation to
## see how to set that up on your local computer, or on github
## actions.
test_that("animint2pages() returns list of meta-data", {
reset_test_repo <- function(){
## https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#delete-a-repository says The fine-grained token must have the following permission set: "Administration" repository permissions (write) gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/OWNER/REPO
tryCatch({
gh::gh("DELETE /repos/animint-test/animint2pages_test_repo")
Expand All @@ -38,6 +45,10 @@ test_that("animint2pages() returns list of meta-data", {
})
## https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-an-organization-repository says The fine-grained token must have the following permission set: "Administration" repository permissions (write)
gh::gh("POST /orgs/animint-test/repos", name="animint2pages_test_repo")
Sys.sleep(3)
}
test_that("animint2pages(chromote_sleep_seconds=3) creates Capture.PNG", {
reset_test_repo()
## first run of animint2pages creates new data viz.
result_list <- animint2pages(viz, "animint2pages_test_repo", owner="animint-test", chromote_sleep_seconds=3)
result_list
Expand All @@ -48,12 +59,8 @@ test_that("animint2pages() returns list of meta-data", {
README.lines <- readLines(README.md)
expected.line <- paste("##", viz$title)
expect_identical(README.lines[1], expected.line)
get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv"))
tsv_files_created <- get_tsv(result_list)
expect_equal(length(tsv_files_created), 1)
expect_Capture <- function(L){
expect_gt(file.size(file.path(L$local_clone,"Capture.PNG")), 0)
}
expect_Capture(result_list)
## second run of animint2pages updates data viz.
viz.more <- viz
Expand All @@ -67,6 +74,41 @@ test_that("animint2pages() returns list of meta-data", {
expect_Capture(update_list)
})

test_that("animint2pages(chromote_sleep_seconds=NULL) does not create Capture.PNG", {
reset_test_repo()
result_list <- animint2pages(viz, "animint2pages_test_repo", owner="animint-test", chromote_sleep_seconds=NULL)
expect_match(result_list$owner_repo, "animint2pages_test_repo")
expect_match(result_list$viz_url, "github.io/animint2pages_test_repo")
expect_match(result_list$gh_pages_url, "animint2pages_test_repo/tree/gh-pages")
README.md <- file.path(result_list$local_clone, "README.md")
README.lines <- readLines(README.md)
expected.line <- paste("##", viz$title)
expect_identical(README.lines[1], expected.line)
tsv_files_created <- get_tsv(result_list)
expect_equal(length(tsv_files_created), 1)
expect_no_Capture(result_list)
## clone and add Capture.PNG
new_clone <- tempfile()
github_url <- paste0("https://github.com/", result_list$owner_repo, ".git")
gert::git_clone(github_url, new_clone)
branch_name <- gert::git_branch(new_clone)
expect_identical(branch_name, "gh-pages")
cat("FOO", file=file.path(new_clone, "Capture.PNG"))
gert::git_add("Capture.PNG", repo=new_clone)
gert::git_commit(message="add Capture.PNG", repo=new_clone)
gert::git_push(repo=new_clone)
## second run of animint2pages updates data viz.
viz.more <- viz
viz.more$five <- ggplot()+
geom_point(aes(
x, x),
data=data.frame(x=1:5))
update_list <- animint2pages(viz.more, "animint2pages_test_repo", owner="animint-test", chromote_sleep_seconds=NULL)
tsv_files_updated <- get_tsv(update_list)
expect_equal(length(tsv_files_updated), 2)
expect_Capture(update_list)
})

# This test is skipped under covr coverage collection due to environment manipulation.
test_that("animint2pages raises an error if no GitHub token is present", {
if (identical(Sys.getenv("R_COVR"), "true")) skip("Skip on covr: environment manipulation not supported")
Expand Down