From 2ad047dfbac610e5e2fa890123964a3644cfcff7 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 6 Jun 2025 10:52:06 +0200 Subject: [PATCH 1/5] create dir, remove err file --- R/z_pages.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 965573e22..813d91998 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -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)){ download.file(viz_url("Capture.PNG"), repo.png) } @@ -245,9 +247,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", From c84c2541036dd8a20f1b76c47023573dcd0917f5 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 6 Jun 2025 13:39:17 +0200 Subject: [PATCH 2/5] test add Capture.PNG then update viz --- R/z_pages.R | 6 ++-- tests/testthat/test-compiler-ghpages.R | 49 +++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 813d91998..d8828610f 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -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) } diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 2b11a4819..0a9867db5 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -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", { +test_that("animint2pages(chromote_sleep_seconds=3) creates Capture.PNG", { ## 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 gh::gh("DELETE /repos/animint-test/animint2pages_test_repo") ## 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) @@ -42,12 +49,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 @@ -61,6 +64,42 @@ test_that("animint2pages() returns list of meta-data", { expect_Capture(update_list) }) +test_that("animint2pages(chromote_sleep_seconds=NULL) does not create Capture.PNG", { + gh::gh("DELETE /repos/animint-test/animint2pages_test_repo") + gh::gh("POST /orgs/animint-test/repos", name="animint2pages_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("git@github.com:", result_list$owner_repo) + 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) +}) + test_that("animint2pages raises an error if no GitHub token is present", { env.names <- c("GITHUB_PAT", "GITHUB_PAT_GITHUB_COM") env.old <- Sys.getenv(env.names) From 8ba53a62aace0ebed15d5be360647cd73e660971 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 6 Jun 2025 13:56:08 +0200 Subject: [PATCH 3/5] version++ --- DESCRIPTION | 2 +- NEWS.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f2dba5747..df9ab99fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: animint2 Title: Animated Interactive Grammar of Graphics -Version: 2025.1.28 +Version: 2025.6.6 URL: https://animint.github.io/animint2/ BugReports: https://github.com/animint/animint2/issues Authors@R: c( diff --git a/NEWS.md b/NEWS.md index a4478e27b..3be61af63 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# Changes in version 2025.6.6 + +## 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.1.28 ## PR#185 From 443008cd510f450c6c97d0e72c55a6b0143a72a2 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 6 Jun 2025 14:20:01 +0200 Subject: [PATCH 4/5] https url --- tests/testthat/test-compiler-ghpages.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 0a9867db5..4f2c87521 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -80,7 +80,7 @@ test_that("animint2pages(chromote_sleep_seconds=NULL) does not create Capture.PN expect_no_Capture(result_list) ## clone and add Capture.PNG new_clone <- tempfile() - github_url <- paste0("git@github.com:", result_list$owner_repo) + 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") From 852c318952611b7414956619f06f581ded2b9cb6 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 6 Jun 2025 15:02:08 +0200 Subject: [PATCH 5/5] reset_test_repo waits 3 seconds too --- tests/testthat/test-compiler-ghpages.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 4f2c87521..765ca72e0 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -34,11 +34,15 @@ expect_no_Capture <- function(L){ ## 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(chromote_sleep_seconds=3) creates Capture.PNG", { +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 gh::gh("DELETE /repos/animint-test/animint2pages_test_repo") ## 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 @@ -65,8 +69,7 @@ test_that("animint2pages(chromote_sleep_seconds=3) creates Capture.PNG", { }) test_that("animint2pages(chromote_sleep_seconds=NULL) does not create Capture.PNG", { - gh::gh("DELETE /repos/animint-test/animint2pages_test_repo") - gh::gh("POST /orgs/animint-test/repos", name="animint2pages_test_repo") + 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")