From 3a056aea4b9ddc10c99933d3a3df0693c860ffd9 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 7 Feb 2022 20:22:07 -0500 Subject: [PATCH 01/47] Neatening up and trying to control gha triggers --- .github/triggers.yml | 82 ++++++++++++++++++ .github/workflows/check-quizzes.yml | 10 +-- .github/workflows/render-bookdown.yml | 1 + .github/workflows/render-leanpub.yml | 20 ++--- .github/workflows/url-checker.yml | 4 +- config_automation.yml | 16 ++++ index.Rmd | 7 -- packages.bib | 85 ------------------- resources/{Dockerfile => TEMPLATE_Dockerfile} | 0 resources/image_to_slide_key.tsv | 3 - scripts/employ-gha-switches.R | 30 +++++++ scripts/store-triggers.R | 23 +++++ 12 files changed, 167 insertions(+), 114 deletions(-) create mode 100644 .github/triggers.yml create mode 100644 config_automation.yml delete mode 100644 packages.bib rename resources/{Dockerfile => TEMPLATE_Dockerfile} (100%) delete mode 100644 resources/image_to_slide_key.tsv create mode 100644 scripts/employ-gha-switches.R create mode 100644 scripts/store-triggers.R diff --git a/.github/triggers.yml b/.github/triggers.yml new file mode 100644 index 00000000..d71924c2 --- /dev/null +++ b/.github/triggers.yml @@ -0,0 +1,82 @@ +check-quizzes.yml: + workflow_dispatch: + pull_request: + branches: + - main + - staging + paths: quizzes/* +delete-preview.yml: + pull_request: + types: closed +docker-build-test.yml: + release: + types: created + pull_request: + branches: main + paths: + - docker/Dockerfile + - docker/github_package_list.tsv + workflow_dispatch: + inputs: + dockerhubpush: + description: Push to Dockerhub? + required: yes + default: 'false' +release-notes.yml: + pull_request: + branches: main + types: opened +render-bookdown.yml: + workflow_dispatch: ~ + push: + branches: main + paths: + - '**.Rmd' + - docker/* + - assets/* +render-leanpub.yml: + workflow_dispatch: + workflows: Render Bookdown and Coursera + branches: main + types: completed + paths: + - '**.Rmd' + - docker/* + - assets/* + - quizzes/* +render-preview.yml: + pull_request: + branches: main +send-updates.yml: + release: + types: published + workflow_dispatch: + inputs: + prtag: + description: Tag to use? + required: yes + default: 'null' +starting-course.yml: + push: + branches: main + workflow_dispatch: ~ +style-and-sp-check.yml: + pull_request: + branches: main +test-send-updates.yml: + workflow_dispatch: + inputs: + repo: + description: What repo to test on e.g. jhudsl/OTTR_Template_Test + required: yes + default: jhudsl/OTTR_Template_Test +transfer-rendered-files.yml: + workflow_dispatch: ~ + workflow_run: + workflows: Render Bookdown and Coursera + branches: main + types: completed +url-checker.yml: + workflow_dispatch: ~ + pull_request: + branches: main diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 6e6e7d88..809a595e 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -5,12 +5,10 @@ name: Check Leanpub Quizzes on: workflow_dispatch: -### UNCOMMENT THIS SECTION IF YOU WISH PREPARE YOUR COURSE QUIZZES FOR LEANPUB AUTOMATICALLY -# pull_request: -# branches: [ main, staging] -# paths: -# - 'quizzes/*' -######### END OF SECTION ######### + pull_request: + branches: [ main, staging] + paths: + - 'quizzes/*' jobs: check-quizzes: diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index e13c8cf5..f0ed6294 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -17,6 +17,7 @@ on: - '**.Rmd' - docker/* - assets/* + jobs: # This workflow contains a single job called "build-all" render-main: diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 9b8059a8..a92b2def 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -5,17 +5,15 @@ name: Render and publish Leanpub on: workflow_dispatch: -### UNCOMMENT THIS SECTION IF YOU WISH PREPARE YOUR COURSE FOR LEANPUB AUTOMATICALLY - # workflows: [ "Render Bookdown and Coursera" ] - # branches: [ main ] - # types: - # - completed - # paths: - # - '**.Rmd' - # - docker/* - # - assets/* - # - quizzes/* -######### END OF SECTION ######### + workflows: [ "Render Bookdown and Coursera" ] + branches: [ main ] + types: + - completed + paths: + - '**.Rmd' + - docker/* + - assets/* + - quizzes/* jobs: # This workflow contains a single job called "build-all" diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index fd3efdf6..913a6b47 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -6,8 +6,8 @@ name: Check URLs # This will be run upon PRs to main on: workflow_dispatch: - pull_request: - branches: [ main ] + pull_request: + branches: [ main ] # Here's the main action of checking URLs jobs: diff --git a/config_automation.yml b/config_automation.yml new file mode 100644 index 00000000..9cc97232 --- /dev/null +++ b/config_automation.yml @@ -0,0 +1,16 @@ +# PR Checks +check-quizzes: yes +url-checker: yes +render-preview: yes +style-and-sp-check: yes + +# Docker specific + docker-build-test: no + +# Rendering +render-bookdown: yes +render-leanpub: no + +# Don't need to touch these +transfer-rendered-files: yes +delete-preview: yes diff --git a/index.Rmd b/index.Rmd index feec81f7..6020c4d1 100644 --- a/index.Rmd +++ b/index.Rmd @@ -13,11 +13,4 @@ output: toc: true --- -```{r include=FALSE} -# automatically create a bib database for R packages -knitr::write_bib(c( - .packages(), "bookdown", "knitr", "rmarkdown" -), "packages.bib") -``` - # About this Course {-} diff --git a/packages.bib b/packages.bib deleted file mode 100644 index 5120648d..00000000 --- a/packages.bib +++ /dev/null @@ -1,85 +0,0 @@ -@Manual{R-base, - title = {R: A Language and Environment for Statistical Computing}, - author = {{R Core Team}}, - organization = {R Foundation for Statistical Computing}, - address = {Vienna, Austria}, - year = {2021}, - url = {https://www.R-project.org/}, -} - -@Manual{R-bookdown, - title = {bookdown: Authoring Books and Technical Documents with R Markdown}, - author = {Yihui Xie}, - year = {2021}, - note = {R package version 0.24}, - url = {https://CRAN.R-project.org/package=bookdown}, -} - -@Manual{R-knitr, - title = {knitr: A General-Purpose Package for Dynamic Report Generation in R}, - author = {Yihui Xie}, - year = {2021}, - note = {R package version 1.37}, - url = {https://yihui.org/knitr/}, -} - -@Manual{R-rmarkdown, - title = {rmarkdown: Dynamic Documents for R}, - author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone}, - year = {2021}, - note = {R package version 2.11}, - url = {https://CRAN.R-project.org/package=rmarkdown}, -} - -@Book{bookdown2016, - title = {bookdown: Authoring Books and Technical Documents with {R} Markdown}, - author = {Yihui Xie}, - publisher = {Chapman and Hall/CRC}, - address = {Boca Raton, Florida}, - year = {2016}, - note = {ISBN 978-1138700109}, - url = {https://bookdown.org/yihui/bookdown}, -} - -@Book{knitr2015, - title = {Dynamic Documents with {R} and knitr}, - author = {Yihui Xie}, - publisher = {Chapman and Hall/CRC}, - address = {Boca Raton, Florida}, - year = {2015}, - edition = {2nd}, - note = {ISBN 978-1498716963}, - url = {https://yihui.org/knitr/}, -} - -@InCollection{knitr2014, - booktitle = {Implementing Reproducible Computational Research}, - editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng}, - title = {knitr: A Comprehensive Tool for Reproducible Research in {R}}, - author = {Yihui Xie}, - publisher = {Chapman and Hall/CRC}, - year = {2014}, - note = {ISBN 978-1466561595}, - url = {http://www.crcpress.com/product/isbn/9781466561595}, -} - -@Book{rmarkdown2018, - title = {R Markdown: The Definitive Guide}, - author = {Yihui Xie and J.J. Allaire and Garrett Grolemund}, - publisher = {Chapman and Hall/CRC}, - address = {Boca Raton, Florida}, - year = {2018}, - note = {ISBN 9781138359338}, - url = {https://bookdown.org/yihui/rmarkdown}, -} - -@Book{rmarkdown2020, - title = {R Markdown Cookbook}, - author = {Yihui Xie and Christophe Dervieux and Emily Riederer}, - publisher = {Chapman and Hall/CRC}, - address = {Boca Raton, Florida}, - year = {2020}, - note = {ISBN 9780367563837}, - url = {https://bookdown.org/yihui/rmarkdown-cookbook}, -} - diff --git a/resources/Dockerfile b/resources/TEMPLATE_Dockerfile similarity index 100% rename from resources/Dockerfile rename to resources/TEMPLATE_Dockerfile diff --git a/resources/image_to_slide_key.tsv b/resources/image_to_slide_key.tsv deleted file mode 100644 index 1cf33393..00000000 --- a/resources/image_to_slide_key.tsv +++ /dev/null @@ -1,3 +0,0 @@ -image_url page_id image_id -https://raw.githubusercontent.com/jhudsl/OTTR_Template/main/_bookdown_files/02-chapter_of_course_files/figure-html/unnamed-chunk-2-1.png SLIDES_API1620647862_0 SLIDES_API1831894727_0 -https://raw.githubusercontent.com/jhudsl/OTTR_Template/main/_bookdown_files/02-chapter_of_course_files/figure-html/unnamed-chunk-3-1.png SLIDES_API133532727_0 SLIDES_API739649856_0 diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R new file mode 100644 index 00000000..7ce153ee --- /dev/null +++ b/scripts/employ-gha-switches.R @@ -0,0 +1,30 @@ +#!/usr/bin/env Rscript + + +# Find .git root directory +root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) + +# Get github actions directory +github_actions_dir <- file.path(root_dir, ".github", "workflows") + +# Get list of github actions files +github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", + full.names = TRUE) + + +# Read in all files +all_gha <- lapply(github_actions_files, yaml::yaml.load_file) +names(all_gha) <- basename(github_actions_files) + +# Extract trigger criteria +gha_triggers <- lapply(1:length(all_gha), function(gha) purrr::pluck(all_gha, gha, "TRUE")) +names(gha_triggers) <- basename(github_actions_files) + + +yaml::write_yaml(gha_triggers, file.path(root_dir, ".github", "gha-triggers.yml")) + +# Switch out repo +yaml_contents$group$repos <- opt$repo + +yaml::write_yaml(yaml_contents, sync_file_path) + diff --git a/scripts/store-triggers.R b/scripts/store-triggers.R new file mode 100644 index 00000000..bf36ed84 --- /dev/null +++ b/scripts/store-triggers.R @@ -0,0 +1,23 @@ +# Write on-trigger yaml +# This script stores what the 'on' triggers look like for each github action + +# Find .git root directory +root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) + +# Get github actions directory +github_actions_dir <- file.path(root_dir, ".github", "workflows") + +# Get list of github actions files +github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", + full.names = TRUE) + +# Read in all files +all_gha <- lapply(github_actions_files, yaml::yaml.load_file) +names(all_gha) <- basename(github_actions_files) + +# Extract trigger criteria +gha_triggers <- lapply(1:length(all_gha), function(gha) purrr::pluck(all_gha, gha, "TRUE")) +names(gha_triggers) <- basename(github_actions_files) + + +yaml::write_yaml(gha_triggers, file.path(root_dir, ".github", "gha-triggers.yml")) \ No newline at end of file From 9d154da75f19205ca3465bd5b31caa4be6cc10e4 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 7 Feb 2022 20:48:30 -0500 Subject: [PATCH 02/47] Add some config mechs --- scripts/employ-gha-switches.R | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 7ce153ee..05b51cee 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -1,9 +1,13 @@ #!/usr/bin/env Rscript +library(magrittr) # Find .git root directory root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) +# Load in what the on trigger criteria is +on_triggers <- yaml::yaml.load_file(file.path(root_dir, ".github", "triggers.yml")) + # Get github actions directory github_actions_dir <- file.path(root_dir, ".github", "workflows") @@ -11,20 +15,23 @@ github_actions_dir <- file.path(root_dir, ".github", "workflows") github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", full.names = TRUE) +config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% + data.frame() %>% + t() %>% + data.frame() %>% + tibble::rownames_to_column("gha_file") -# Read in all files -all_gha <- lapply(github_actions_files, yaml::yaml.load_file) -names(all_gha) <- basename(github_actions_files) - -# Extract trigger criteria -gha_triggers <- lapply(1:length(all_gha), function(gha) purrr::pluck(all_gha, gha, "TRUE")) -names(gha_triggers) <- basename(github_actions_files) - +colnames(config_yaml)[2] <- "on_or_off" -yaml::write_yaml(gha_triggers, file.path(root_dir, ".github", "gha-triggers.yml")) - -# Switch out repo -yaml_contents$group$repos <- opt$repo - -yaml::write_yaml(yaml_contents, sync_file_path) +gha_file <- github_actions_files[1] +# Read in all files +all_gha <- lapply(github_actions_files, function(gha_file) { + yaml_contents <- yaml::yaml.load_file(gha_file) + + yaml_contents$ + if () + yaml_contents$`TRUE` <- on_triggers[[basename(gha_file)]] + + yaml::write_yaml(yaml_contents, sync_file_path) +}) From 964e16d4543f8d80ac4e8159f09886750f72b738 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 08:18:22 -0500 Subject: [PATCH 03/47] One strategy for yamls --- .github/workflows/render-leanpub.yml | 2 +- scripts/employ-gha-switches.R | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index a92b2def..5552d8eb 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -5,7 +5,7 @@ name: Render and publish Leanpub on: workflow_dispatch: - workflows: [ "Render Bookdown and Coursera" ] + workflows: [ "Render Bookdown and Coursera" ] branches: [ main ] types: - completed diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 05b51cee..719b029b 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -5,9 +5,13 @@ library(magrittr) # Find .git root directory root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) -# Load in what the on trigger criteria is +### Load in what the on trigger criteria is on_triggers <- yaml::yaml.load_file(file.path(root_dir, ".github", "triggers.yml")) +### + +off_triggers <- + # Get github actions directory github_actions_dir <- file.path(root_dir, ".github", "workflows") @@ -19,7 +23,8 @@ config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% data.frame() %>% t() %>% data.frame() %>% - tibble::rownames_to_column("gha_file") + tibble::rownames_to_column("gha_files") %>% + dplyr::mutate(gha_files = paste0(gsub("\\.", "-", gha_files), ".yml")) colnames(config_yaml)[2] <- "on_or_off" @@ -28,10 +33,17 @@ gha_file <- github_actions_files[1] # Read in all files all_gha <- lapply(github_actions_files, function(gha_file) { yaml_contents <- yaml::yaml.load_file(gha_file) - - yaml_contents$ - if () - yaml_contents$`TRUE` <- on_triggers[[basename(gha_file)]] - yaml::write_yaml(yaml_contents, sync_file_path) + status <- config_yaml %>% + dplyr::filter(basename(gha_file) == gha_files) %>% + dplyr::pull("on_or_off") + + if (status) { + yaml_contents$`TRUE` <- on_triggers[[basename(gha_file)]] + names(yaml_contents)[2] <- yaml::as.yaml("on") + } else { + yaml_contents$`TRUE` <- "workflow_dispatch:" + names(yaml_contents)[2] <- yaml::as.yaml("on") + } + yaml::write_yaml(yaml_contents, "testing.yml") }) From bdf4d658e110d079f26db62c47437a54d39d0af3 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 08:24:27 -0500 Subject: [PATCH 04/47] Fix trigger syntax --- .github/workflows/render-leanpub.yml | 1 + scripts/employ-gha-switches.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 5552d8eb..8af71ad1 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -5,6 +5,7 @@ name: Render and publish Leanpub on: workflow_dispatch: + workflow_run: workflows: [ "Render Bookdown and Coursera" ] branches: [ main ] types: diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 719b029b..4e9c625d 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -32,7 +32,7 @@ gha_file <- github_actions_files[1] # Read in all files all_gha <- lapply(github_actions_files, function(gha_file) { - yaml_contents <- yaml::yaml.load_file(gha_file) + yaml_contents <- yaml::yaml.load(gha_file, eval.expr = FALSE) status <- config_yaml %>% dplyr::filter(basename(gha_file) == gha_files) %>% From a853cf7d1252c809265320ff3de0d57b292d4838 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 08:25:43 -0500 Subject: [PATCH 05/47] Try to fix syntax part 2 --- .github/workflows/render-leanpub.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 8af71ad1..37ee78b9 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -6,15 +6,15 @@ name: Render and publish Leanpub on: workflow_dispatch: workflow_run: - workflows: [ "Render Bookdown and Coursera" ] - branches: [ main ] - types: - - completed - paths: - - '**.Rmd' - - docker/* - - assets/* - - quizzes/* + workflows: [ "Render Bookdown and Coursera" ] + branches: [ main ] + types: + - completed + paths: + - '**.Rmd' + - docker/* + - assets/* + - quizzes/* jobs: # This workflow contains a single job called "build-all" From 0d84ced2f54f09ecd257e56306cb073f6e286088 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 08:27:39 -0500 Subject: [PATCH 06/47] Fix syntax part 3 --- .github/workflows/render-leanpub.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 37ee78b9..56159e2f 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -7,14 +7,14 @@ on: workflow_dispatch: workflow_run: workflows: [ "Render Bookdown and Coursera" ] - branches: [ main ] - types: - - completed - paths: - - '**.Rmd' - - docker/* - - assets/* - - quizzes/* + branches: [ main ] + types: + - completed + paths: + - '**.Rmd' + - docker/* + - assets/* + - quizzes/* jobs: # This workflow contains a single job called "build-all" From 43266db6d000fb56741ee513d2e2bc11be44e7ac Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 08:34:09 -0500 Subject: [PATCH 07/47] Add TRIGGER-START --- .github/workflows/check-quizzes.yml | 2 + .github/workflows/delete-preview.yml | 2 + .github/workflows/docker-build-test.yml | 14 +-- .github/workflows/release-notes.yml | 2 + .github/workflows/render-bookdown.yml | 12 +- .github/workflows/render-leanpub.yml | 2 + .github/workflows/render-preview.yml | 3 +- .github/workflows/send-updates.yml | 2 + .github/workflows/starting-course.yml | 4 + .github/workflows/style-and-sp-check.yml | 5 +- .github/workflows/test-send-updates.yml | 3 +- .github/workflows/transfer-rendered-files.yml | 3 +- .github/workflows/url-checker.yml | 4 +- testing.yml | 109 ++++++++++++++++++ 14 files changed, 140 insertions(+), 27 deletions(-) create mode 100644 testing.yml diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 809a595e..76907f04 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -3,12 +3,14 @@ name: Check Leanpub Quizzes +#---TRIGGER-START---# on: workflow_dispatch: pull_request: branches: [ main, staging] paths: - 'quizzes/*' +#---TRIGGER-END----# jobs: check-quizzes: diff --git a/.github/workflows/delete-preview.yml b/.github/workflows/delete-preview.yml index b910ad45..780c2a76 100644 --- a/.github/workflows/delete-preview.yml +++ b/.github/workflows/delete-preview.yml @@ -2,9 +2,11 @@ name: Delete Preview +#---TRIGGER-START---# on: pull_request: types: [closed] +#---TRIGGER-END---# jobs: build-all: diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index 7d572233..e4f837c3 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -1,13 +1,8 @@ -# This code was originally written by Josh Shapiro -# for the Childhood Cancer Data Lab, an initiative of Alexs Lemonade Stand Foundation. -# https://github.com/AlexsLemonade/refinebio-examples/blob/33cdeff66d57f9fe8ee4fcb5156aea4ac2dce07f/.github/workflows/style-and-sp-check.yml#L1 - -# Adapted for this jhudsl repository by Candace Savonen Apr 2021 +# Candace Savonen Apr 2021 name: Test build of Dockerfile -# Controls when the action will run. Triggers the workflow for a pull request for -# master +#---TRIGGER-START---# on: release: types: @@ -22,15 +17,12 @@ on: description: 'Push to Dockerhub?' required: true default: 'false' +#---TRIGGER-END----# -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: checkout repo uses: actions/checkout@v2 diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index f962271c..2c797a03 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -2,10 +2,12 @@ name: Release note PR comment +#---TRIGGER-START---# on: pull_request: branches: [ main ] types: [ opened ] +#---TRIGGER-END----# jobs: pr-comment: diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index f0ed6294..8a2c07f7 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -1,14 +1,9 @@ -# This code was originally written by Josh Shapiro and Candace Savonen -# for the Childhood Cancer Data Lab, an initiative of Alexs Lemonade Stand Foundation. -# https://github.com/AlexsLemonade/refinebio-examples/blob/33cdeff66d57f9fe8ee4fcb5156aea4ac2dce07f/.github/workflows/style-and-sp-check.yml#L1 - -# Adapted for this jhudsl repository by Candace Savonen Apr 2021 +# Candace Savonen Apr 2021 name: Render Bookdown and Coursera -# Controls when the action will run. Triggers the workflow on push -# events only for the master branch +#---TRIGGER-START---# on: workflow_dispatch: push: @@ -17,7 +12,8 @@ on: - '**.Rmd' - docker/* - assets/* - +#---TRIGGER-END----# + jobs: # This workflow contains a single job called "build-all" render-main: diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 56159e2f..7493ff96 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -3,6 +3,7 @@ name: Render and publish Leanpub +#---TRIGGER-START---# on: workflow_dispatch: workflow_run: @@ -15,6 +16,7 @@ on: - docker/* - assets/* - quizzes/* +#---TRIGGER-END----# jobs: # This workflow contains a single job called "build-all" diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index c0786b32..e9b368c6 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -2,10 +2,11 @@ name: Render Preview -# Controls when the action will run. Triggers the workflow on pull request to main branch +#---TRIGGER-START---# on: pull_request: branches: [ main ] +#---TRIGGER-END----# permissions: write-all diff --git a/.github/workflows/send-updates.yml b/.github/workflows/send-updates.yml index b00f77b3..fe309b82 100644 --- a/.github/workflows/send-updates.yml +++ b/.github/workflows/send-updates.yml @@ -2,6 +2,7 @@ name: Sync Files +#---TRIGGER-START---# on: release: types: @@ -12,6 +13,7 @@ on: description: 'Tag to use?' required: true default: 'null' +#---TRIGGER-END----# jobs: sync: diff --git a/.github/workflows/starting-course.yml b/.github/workflows/starting-course.yml index 9a5dcd02..b439ff25 100644 --- a/.github/workflows/starting-course.yml +++ b/.github/workflows/starting-course.yml @@ -2,11 +2,15 @@ # by Candace Savonen for this repository. name: Starting a new course + + +#---TRIGGER-START---# on: push: branches: - main workflow_dispatch: +#---TRIGGER-END---# jobs: # Run cleaning process only if workflow is triggered by not being in the Bookdown template anymore diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 9c7898e0..9eccf760 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -2,13 +2,12 @@ name: Style and spell check R markdowns -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the main branch +#---TRIGGER-START---# on: pull_request: branches: [ main ] +#---TRIGGER-END---# -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "style and check" style-n-check: diff --git a/.github/workflows/test-send-updates.yml b/.github/workflows/test-send-updates.yml index e810a6ea..fbba9207 100644 --- a/.github/workflows/test-send-updates.yml +++ b/.github/workflows/test-send-updates.yml @@ -2,6 +2,7 @@ name: Test Sync Files +#---TRIGGER-START---# on: workflow_dispatch: inputs: @@ -9,7 +10,7 @@ on: description: 'What repo to test on e.g. jhudsl/OTTR_Template_Test' required: true default: 'jhudsl/OTTR_Template_Test' - +#---TRIGGER-END----# jobs: test-sync: runs-on: ubuntu-latest diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index 2d27ddf1..a8354637 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -7,7 +7,7 @@ name: Bookdown to Leanpub repo copy over # Copy rendered notebooks to Leanpub repo -# This workflow will run when there are changes to docs/ files in THIS repo +#---TRIGGER-START---# on: workflow_dispatch: # Only run after the render finishes running @@ -16,6 +16,7 @@ on: branches: [ main ] types: - completed +#---TRIGGER-END----# jobs: file-bookdown-pr: diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index 913a6b47..ead2ea27 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -3,13 +3,13 @@ # This github actions tests URLs in the Rmd files, README, and CONTRIBUTING.md name: Check URLs -# This will be run upon PRs to main +#---TRIGGER-START---# on: workflow_dispatch: pull_request: branches: [ main ] +#---TRIGGER-END----# -# Here's the main action of checking URLs jobs: build: runs-on: ubuntu-latest diff --git a/testing.yml b/testing.yml new file mode 100644 index 00000000..4ed80633 --- /dev/null +++ b/testing.yml @@ -0,0 +1,109 @@ +name: Check Leanpub Quizzes +? | + 'on' +: workflow_dispatch: + pull_request: + branches: + - main + - staging + paths: quizzes/* +jobs: + check-quizzes: + runs-on: ubuntu-latest + container: + image: jhudsl/course_template + steps: + - name: Checkout files + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Configure git + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + branch_name='check-${{ github.event.pull_request.number }}' + exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs) + if [[ $exists == 0 ]];then + echo branch doesnt exist + git checkout -b $branch_name + git push --set-upstream origin $branch_name + else + echo branch does exist + git fetch --all + git checkout $branch_name + git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} + fi + shell: bash + - name: Run quiz check + id: quiz_check_run + run: | + Rscript -e "ottr::check_quizzes(quiz_dir = 'quizzes', write_report = TRUE, verbose = TRUE)" + results=0 + if -f "question_error_report.tsv"; then + results=$(wc -l < question_error_report.tsv >/dev/null) + fi + echo ::set-output name=quiz_chk_results::$results + - name: Commit quiz check errors + run: | + branch_name='check-${{ github.event.pull_request.number }}' + git diff --name-only origin/main -- question_error_report.tsv >/dev/null && changes=true || changes=false + echo $changes + if $changes == true; then + git diff --name-only origin/$branch_name question_error_report.tsv >/dev/null && changes=true || changes=false + echo $changes + if $changes == true; then + git add --force question_error_report.tsv + git diff-index --quiet HEAD || git commit -m 'Add question error report file' + git pull --set-upstream origin $branch_name --allow-unrelated-histories + git push origin $branch_name + fi + fi + - name: Build components of the quiz check comment + id: build-components + env: + GH_PAT: ${{ secrets.GH_PAT }} + run: | + branch_name='check-${{ github.event.pull_request.number }}' + quiz_error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/question_error_report.tsv + echo ::set-output name=time::$(date +'%Y-%m-%d') + echo ::set-output name=commit_id::$GITHUB_SHA + echo ::set-output name=quiz_error_url::$quiz_error_url + - name: Find Comment + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: github-actions[bot] + body-includes: quiz errors + - name: Quiz errors! + if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }} + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + :warning: There are quiz errors that need to be addressed. [Read this guide for more info](https://github.com/jhudsl/OTTR_Template/wiki/Publishing-on-Leanpub#setting-up-quizzes). + [Download the errors here.](${{ steps.build-components.outputs.quiz_error_url }}) + _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + edit-mode: replace + - name: Check quiz check results - fail if too many errors + if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }} + run: exit 1 + - name: No quiz errors + if: ${{ steps.quiz_check_run.outputs.quiz_chk_results < 2 }} + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + No quiz errors detected! :tada: + _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + edit-mode: replace +'TRUE': + workflow_dispatch: + pull_request: + branches: + - main + - staging + paths: quizzes/* From 996e502bce84f35c4f1f3da531ecb76ce8c8cf8b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:05:51 -0500 Subject: [PATCH 08/47] This is mostly working --- .github/on-triggers.rds | Bin 0 -> 3477 bytes .github/triggers.yml | 82 ---------------------------------- scripts/employ-gha-switches.R | 49 +++++++++++++++----- scripts/store-triggers.R | 16 ++++--- 4 files changed, 48 insertions(+), 99 deletions(-) create mode 100644 .github/on-triggers.rds delete mode 100644 .github/triggers.yml diff --git a/.github/on-triggers.rds b/.github/on-triggers.rds new file mode 100644 index 0000000000000000000000000000000000000000..2db8e017b7a85b38a173a0ff00d72b90de0612cd GIT binary patch literal 3477 zcmd55oUu zu6G@mBqk9BVJWdQv!3TSk9^s59B0{CU0QaQSJYz_zqasG!Oufy)!D#%?TAv^YQDR? zylB!-t=G*K{ys9yl{h*xkNboSW8UwE@v!X$B4N_?EpM0Lm84Ykd~q7cy&07 zTpz?4`AP;Xh)#%*tQSPRZ$|jz>>LX9g?+b{(FmdB_&N=4Z$X^akF7ODt1mvBqs?e^ z=GmG#Gp}bm(`~OR{c@COv)wQj;8}C4liIEF%7V%_3E>a|6JY&Diq&gmp@Hh6#O1&w zcw_Rkm~W}GdBn}xZAH|fRPnb_e5Ghv&@nS!?Dm15p6gpT2;sz%dV%!QPCH?4pY@;} z20}KZxFI$kW!QM6bOce7$~?1pTwR$y6r7|Yhtl(mhg=XY4-y$51j+G7JVInlGUM=_ zm)3^^`+|aAz`;8slBZz&ermZMbXgio6xC&+0Q>g-WF~VQJuou<5J%d;JRhb4^3Z9N zTa=MFfe5^uS!Uhlg4UJgXkAsnI0xkxYkc0R)Jhg)tkZhE(HwX-xH;V*t8Prr=}ZWa zSk;DJ=I-`Ax{LLcw=$mQ9qxs4!!mTQI&4DZ0Vi+bxbMZoh_J{bZ{w5;;OsC@(;V^2 zGHiU%?NZlsJV-(qSM=WtZLTu!q;tglo*HR+c*>Igc)_I4-ApOsy@PGc&zoskc}!_x zc3^RwW43W0j(bh9b+uSeb*@yvoIUHwSdQ&k5zbayRb>HNUoc?56#mrFVO*tpa$D4l z3uR&%C>f6b1W+aVHx>-ff}qeiQS&^BEhgTNb6Ld1XP-%ZP9a0$!bIYTK%>_n-~H4R z;ptVY)oix_+XD`Kd=S#6UsscoI(6QijP+UU{8nNapzd?ZGzd8&S5Y`3*mMc&O6;uC z2XsU?*=`W2f)t7y;cjSh_1`w@val_>I+Ouz=5lRzo0+S{3dAO=dpb3YY0EPulEgSK)lLnzj6`~8wU9;iRC`L|!QO#0M zJ7&HXSbK(rt1<45ohh72BPs%sMAO8>nz^F}|7~!IkfN@h-34I>LXJY9IM=C2sP?% data.frame() %>% t() %>% @@ -28,22 +44,31 @@ config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% colnames(config_yaml)[2] <- "on_or_off" -gha_file <- github_actions_files[1] - # Read in all files all_gha <- lapply(github_actions_files, function(gha_file) { - yaml_contents <- yaml::yaml.load(gha_file, eval.expr = FALSE) + # Read in yaml + yaml_contents <- readLines(gha_file) + + # Get trigger indices + trigger_indices <- extract_trigger(yaml_contents) + + # Should this be on or off? status <- config_yaml %>% dplyr::filter(basename(gha_file) == gha_files) %>% dplyr::pull("on_or_off") if (status) { - yaml_contents$`TRUE` <- on_triggers[[basename(gha_file)]] - names(yaml_contents)[2] <- yaml::as.yaml("on") + trigger <- on_triggers[[basename(gha_file)]] } else { - yaml_contents$`TRUE` <- "workflow_dispatch:" - names(yaml_contents)[2] <- yaml::as.yaml("on") + trigger <- off_trigger } - yaml::write_yaml(yaml_contents, "testing.yml") + + # Remove current trigger + yaml_contents <- yaml_contents[-trigger_indices] + + # Put new trigger in + yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1]) + + writeLines(yaml_contents, gha_file) }) diff --git a/scripts/store-triggers.R b/scripts/store-triggers.R index bf36ed84..3e7005cd 100644 --- a/scripts/store-triggers.R +++ b/scripts/store-triggers.R @@ -12,12 +12,18 @@ github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", full.names = TRUE) # Read in all files -all_gha <- lapply(github_actions_files, yaml::yaml.load_file) +all_gha <- lapply(github_actions_files, readLines) names(all_gha) <- basename(github_actions_files) -# Extract trigger criteria -gha_triggers <- lapply(1:length(all_gha), function(gha) purrr::pluck(all_gha, gha, "TRUE")) -names(gha_triggers) <- basename(github_actions_files) +# Make extract trigger function +extract_trigger <- function(gha_contents) { + # Extract trigger criteria + trigger_start <- grep("TRIGGER-START", gha_contents) + trigger_end <- grep("TRIGGER-END", gha_contents) + return(gha_contents[trigger_start:trigger_end]) +} -yaml::write_yaml(gha_triggers, file.path(root_dir, ".github", "gha-triggers.yml")) \ No newline at end of file +on_triggers <- lapply(all_gha, extract_trigger) + +readr::write_rds(on_triggers, file.path(root_dir, ".github", "on-triggers.rds")) From a85d3fd7868aefbc3546e0462e78d6b551d3dfe2 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:22:28 -0500 Subject: [PATCH 09/47] Set up gha --- scripts/employ-gha-switches.R | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index a9d239b8..d755b034 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -58,11 +58,13 @@ all_gha <- lapply(github_actions_files, function(gha_file) { dplyr::filter(basename(gha_file) == gha_files) %>% dplyr::pull("on_or_off") - if (status) { - trigger <- on_triggers[[basename(gha_file)]] - } else { - trigger <- off_trigger - } + if (length(status) == 1) { + message(paste("Turning trigger on:", status, "for", basename(gha_file))) + if (status) { + trigger <- on_triggers[[basename(gha_file)]] + } else { + trigger <- off_trigger + } # Remove current trigger yaml_contents <- yaml_contents[-trigger_indices] @@ -71,4 +73,5 @@ all_gha <- lapply(github_actions_files, function(gha_file) { yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1]) writeLines(yaml_contents, gha_file) + } }) From 579c801de7ac6e766fcb5f6720b8f7028753fc6b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:27:12 -0500 Subject: [PATCH 10/47] This seems to work --- .github/workflows/check-quizzes.yml | 2 +- .github/workflows/delete-preview.yml | 2 +- .github/workflows/docker-build-test.yml | 14 +------------- .github/workflows/render-bookdown.yml | 2 +- .github/workflows/render-leanpub.yml | 12 +----------- .github/workflows/render-preview.yml | 2 +- .github/workflows/style-and-sp-check.yml | 2 +- .github/workflows/transfer-rendered-files.yml | 2 +- .github/workflows/url-checker.yml | 2 +- 9 files changed, 9 insertions(+), 31 deletions(-) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 76907f04..e61914c9 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -3,6 +3,7 @@ name: Check Leanpub Quizzes + #---TRIGGER-START---# on: workflow_dispatch: @@ -11,7 +12,6 @@ on: paths: - 'quizzes/*' #---TRIGGER-END----# - jobs: check-quizzes: runs-on: ubuntu-latest diff --git a/.github/workflows/delete-preview.yml b/.github/workflows/delete-preview.yml index 780c2a76..0bc39162 100644 --- a/.github/workflows/delete-preview.yml +++ b/.github/workflows/delete-preview.yml @@ -2,12 +2,12 @@ name: Delete Preview + #---TRIGGER-START---# on: pull_request: types: [closed] #---TRIGGER-END---# - jobs: build-all: runs-on: ubuntu-latest diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index e4f837c3..147a228a 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -2,23 +2,11 @@ name: Test build of Dockerfile + #---TRIGGER-START---# on: - release: - types: - - created - pull_request: - branches: - - 'main' - paths: [ docker/Dockerfile, docker/github_package_list.tsv ] workflow_dispatch: - inputs: - dockerhubpush: - description: 'Push to Dockerhub?' - required: true - default: 'false' #---TRIGGER-END----# - jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index 8a2c07f7..92d468aa 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -3,6 +3,7 @@ name: Render Bookdown and Coursera + #---TRIGGER-START---# on: workflow_dispatch: @@ -13,7 +14,6 @@ on: - docker/* - assets/* #---TRIGGER-END----# - jobs: # This workflow contains a single job called "build-all" render-main: diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 7493ff96..9930be76 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -3,21 +3,11 @@ name: Render and publish Leanpub + #---TRIGGER-START---# on: workflow_dispatch: - workflow_run: - workflows: [ "Render Bookdown and Coursera" ] - branches: [ main ] - types: - - completed - paths: - - '**.Rmd' - - docker/* - - assets/* - - quizzes/* #---TRIGGER-END----# - jobs: # This workflow contains a single job called "build-all" render-main: diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index e9b368c6..e323c404 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -2,12 +2,12 @@ name: Render Preview + #---TRIGGER-START---# on: pull_request: branches: [ main ] #---TRIGGER-END----# - permissions: write-all jobs: diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 9eccf760..1f9b4814 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -2,12 +2,12 @@ name: Style and spell check R markdowns + #---TRIGGER-START---# on: pull_request: branches: [ main ] #---TRIGGER-END---# - jobs: # This workflow contains a single job called "style and check" style-n-check: diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index a8354637..07e05d2c 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -7,6 +7,7 @@ name: Bookdown to Leanpub repo copy over # Copy rendered notebooks to Leanpub repo + #---TRIGGER-START---# on: workflow_dispatch: @@ -17,7 +18,6 @@ on: types: - completed #---TRIGGER-END----# - jobs: file-bookdown-pr: # The type of runner that the job will run on diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index ead2ea27..d645a1a8 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -3,13 +3,13 @@ # This github actions tests URLs in the Rmd files, README, and CONTRIBUTING.md name: Check URLs + #---TRIGGER-START---# on: workflow_dispatch: pull_request: branches: [ main ] #---TRIGGER-END----# - jobs: build: runs-on: ubuntu-latest From a56d5ba516bf61086f98d2aff3136245437d3601 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:29:08 -0500 Subject: [PATCH 11/47] Updates to script --- scripts/employ-gha-switches.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index d755b034..9c69792a 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -23,7 +23,8 @@ on_triggers <- readr::read_rds(file.path(root_dir, ".github", "on-triggers.rds") off_trigger <- c("#---TRIGGER-START---#", "on:", " workflow_dispatch:", - "#---TRIGGER-END----#") + "#---TRIGGER-END----#", + " ") ### Read in and set up config automation yaml From 6d6ca3b7855323b5b9edb99abaaae306f378575b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:29:18 -0500 Subject: [PATCH 12/47] Updates to script 2 --- scripts/employ-gha-switches.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 9c69792a..89739468 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -20,11 +20,12 @@ root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) on_triggers <- readr::read_rds(file.path(root_dir, ".github", "on-triggers.rds")) # Same off trigger for all -off_trigger <- c("#---TRIGGER-START---#", +off_trigger <- c("", + "#---TRIGGER-START---#", "on:", " workflow_dispatch:", "#---TRIGGER-END----#", - " ") + "") ### Read in and set up config automation yaml @@ -68,7 +69,7 @@ all_gha <- lapply(github_actions_files, function(gha_file) { } # Remove current trigger - yaml_contents <- yaml_contents[-trigger_indices] + yaml_contents <- yaml_contents[-trigger_indices[2:length(trigger_indices)]] # Put new trigger in yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1]) From 975148f2833c63f5d93ae1f8043e61586150a9c1 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:30:02 -0500 Subject: [PATCH 13/47] Nope --- scripts/employ-gha-switches.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 89739468..a7fcd093 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -69,7 +69,7 @@ all_gha <- lapply(github_actions_files, function(gha_file) { } # Remove current trigger - yaml_contents <- yaml_contents[-trigger_indices[2:length(trigger_indices)]] + yaml_contents <- yaml_contents[-trigger_indices] # Put new trigger in yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1]) From 35e1d60bf7f154d28264482cbd9d4ff53e1a1cc5 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:30:57 -0500 Subject: [PATCH 14/47] Don't delete last line --- scripts/employ-gha-switches.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index a7fcd093..df67c47c 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -6,7 +6,7 @@ library(magrittr) extract_trigger <- function(gha_contents) { # Extract trigger criteria trigger_start <- grep("TRIGGER-START", gha_contents) - trigger_end <- grep("TRIGGER-END", gha_contents) + trigger_end <- grep("TRIGGER-END", gha_contents) - 1 return(trigger_start:trigger_end) } From a0d2c029dce7310343ca40c929fb47970b80bb72 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:32:43 -0500 Subject: [PATCH 15/47] script edit --- scripts/employ-gha-switches.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index df67c47c..6beea3a1 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -6,7 +6,7 @@ library(magrittr) extract_trigger <- function(gha_contents) { # Extract trigger criteria trigger_start <- grep("TRIGGER-START", gha_contents) - trigger_end <- grep("TRIGGER-END", gha_contents) - 1 + trigger_end <- grep("TRIGGER-END", gha_contents) return(trigger_start:trigger_end) } @@ -72,7 +72,7 @@ all_gha <- lapply(github_actions_files, function(gha_file) { yaml_contents <- yaml_contents[-trigger_indices] # Put new trigger in - yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1]) + yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1] - 1) writeLines(yaml_contents, gha_file) } From 6d36644123a7c214ab5bc5aabffebb24756c0979 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:33:27 -0500 Subject: [PATCH 16/47] Added some extra lines --- .github/workflows/docker-build-test.yml | 2 ++ .github/workflows/render-leanpub.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index 147a228a..c01b396a 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -3,10 +3,12 @@ name: Test build of Dockerfile + #---TRIGGER-START---# on: workflow_dispatch: #---TRIGGER-END----# + jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 9930be76..ee27fa5f 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -4,10 +4,12 @@ name: Render and publish Leanpub + #---TRIGGER-START---# on: workflow_dispatch: #---TRIGGER-END----# + jobs: # This workflow contains a single job called "build-all" render-main: From b2007414195e4715a9eb6b73f3ef4b8b5ae58b34 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:34:11 -0500 Subject: [PATCH 17/47] Don't add extra spaces --- scripts/employ-gha-switches.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 6beea3a1..7e096cbf 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -20,12 +20,10 @@ root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) on_triggers <- readr::read_rds(file.path(root_dir, ".github", "on-triggers.rds")) # Same off trigger for all -off_trigger <- c("", - "#---TRIGGER-START---#", +off_trigger <- c("#---TRIGGER-START---#", "on:", " workflow_dispatch:", - "#---TRIGGER-END----#", - "") + "#---TRIGGER-END----#") ### Read in and set up config automation yaml From e3e658cf055ef322854960df0010ffed8e46948b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:48:34 -0500 Subject: [PATCH 18/47] Get rid of packages.bib --- _bookdown.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_bookdown.yml b/_bookdown.yml index 6558fad5..d5416098 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -7,7 +7,7 @@ rmd_files: ["index.Rmd", "About.Rmd", "References.Rmd"] new_session: yes -bibliography: [book.bib, packages.bib] +bibliography: book.bib delete_merged_file: true language: ui: From a2f97a61087d17681d5c9702d8ba46e36b832fd8 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 09:51:30 -0500 Subject: [PATCH 19/47] No packages.bib --- index.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.Rmd b/index.Rmd index 6020c4d1..a6140640 100644 --- a/index.Rmd +++ b/index.Rmd @@ -1,9 +1,9 @@ --- -title: "Course Name " +title: "Course Name" date: "`r format(Sys.time(), '%B, %Y')`" site: bookdown::bookdown_site documentclass: book -bibliography: [book.bib, packages.bib] +bibliography: book.bib biblio-style: apalike link-citations: yes description: "Description about Course/Book." From fa7b618819a65a784ace2ec02e87d802cfe3c3c6 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 12:11:04 -0500 Subject: [PATCH 20/47] Add OTTR Website --- .github/sync.yml | 13 +++++ config_automation.yml | 4 -- testing.yml | 109 ------------------------------------------ 3 files changed, 13 insertions(+), 113 deletions(-) delete mode 100644 testing.yml diff --git a/.github/sync.yml b/.github/sync.yml index f037ada4..a982e460 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -60,6 +60,19 @@ group: - source: style-sets dest: style-sets + repos: | + jhudsl/OTTR_Template_Website + - source: .github/workflows/style-and-sp-check.yml + dest: .github/workflows/style-and-sp-check.yml + - source: .github/workflows/url-checker.yml + dest: .github/workflows/url-checker.yml + - source: scripts/spell-check.R + dest: scripts/spell-check.R + - source: scripts/get_spell_errors.R + dest: scripts/get_spell_errors.R + - source: scripts/git_repo_check.R + dest: scripts/git_repo_check.R + ###### TO ADD NEW REPOSITORY USE THIS FORMAT; Feel free to add/drop files that # you specifically would like synced (or not). # diff --git a/config_automation.yml b/config_automation.yml index 9cc97232..01bacff1 100644 --- a/config_automation.yml +++ b/config_automation.yml @@ -10,7 +10,3 @@ style-and-sp-check: yes # Rendering render-bookdown: yes render-leanpub: no - -# Don't need to touch these -transfer-rendered-files: yes -delete-preview: yes diff --git a/testing.yml b/testing.yml deleted file mode 100644 index 4ed80633..00000000 --- a/testing.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Check Leanpub Quizzes -? | - 'on' -: workflow_dispatch: - pull_request: - branches: - - main - - staging - paths: quizzes/* -jobs: - check-quizzes: - runs-on: ubuntu-latest - container: - image: jhudsl/course_template - steps: - - name: Checkout files - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Configure git - run: | - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" - - branch_name='check-${{ github.event.pull_request.number }}' - exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs) - if [[ $exists == 0 ]];then - echo branch doesnt exist - git checkout -b $branch_name - git push --set-upstream origin $branch_name - else - echo branch does exist - git fetch --all - git checkout $branch_name - git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} - fi - shell: bash - - name: Run quiz check - id: quiz_check_run - run: | - Rscript -e "ottr::check_quizzes(quiz_dir = 'quizzes', write_report = TRUE, verbose = TRUE)" - results=0 - if -f "question_error_report.tsv"; then - results=$(wc -l < question_error_report.tsv >/dev/null) - fi - echo ::set-output name=quiz_chk_results::$results - - name: Commit quiz check errors - run: | - branch_name='check-${{ github.event.pull_request.number }}' - git diff --name-only origin/main -- question_error_report.tsv >/dev/null && changes=true || changes=false - echo $changes - if $changes == true; then - git diff --name-only origin/$branch_name question_error_report.tsv >/dev/null && changes=true || changes=false - echo $changes - if $changes == true; then - git add --force question_error_report.tsv - git diff-index --quiet HEAD || git commit -m 'Add question error report file' - git pull --set-upstream origin $branch_name --allow-unrelated-histories - git push origin $branch_name - fi - fi - - name: Build components of the quiz check comment - id: build-components - env: - GH_PAT: ${{ secrets.GH_PAT }} - run: | - branch_name='check-${{ github.event.pull_request.number }}' - quiz_error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/question_error_report.tsv - echo ::set-output name=time::$(date +'%Y-%m-%d') - echo ::set-output name=commit_id::$GITHUB_SHA - echo ::set-output name=quiz_error_url::$quiz_error_url - - name: Find Comment - uses: peter-evans/find-comment@v1 - id: fc - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: github-actions[bot] - body-includes: quiz errors - - name: Quiz errors! - if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }} - uses: peter-evans/create-or-update-comment@v1 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - :warning: There are quiz errors that need to be addressed. [Read this guide for more info](https://github.com/jhudsl/OTTR_Template/wiki/Publishing-on-Leanpub#setting-up-quizzes). - [Download the errors here.](${{ steps.build-components.outputs.quiz_error_url }}) - _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ - edit-mode: replace - - name: Check quiz check results - fail if too many errors - if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }} - run: exit 1 - - name: No quiz errors - if: ${{ steps.quiz_check_run.outputs.quiz_chk_results < 2 }} - uses: peter-evans/create-or-update-comment@v1 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - No quiz errors detected! :tada: - _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ - edit-mode: replace -'TRUE': - workflow_dispatch: - pull_request: - branches: - - main - - staging - paths: quizzes/* From a398c8138a9d5d73bb835aac2c2940327ccbf474 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 13:39:16 -0500 Subject: [PATCH 21/47] Update sync --- .github/sync.yml | 2 -- .github/workflows/render-preview.yml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index a982e460..e71fe121 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -68,8 +68,6 @@ group: dest: .github/workflows/url-checker.yml - source: scripts/spell-check.R dest: scripts/spell-check.R - - source: scripts/get_spell_errors.R - dest: scripts/get_spell_errors.R - source: scripts/git_repo_check.R dest: scripts/git_repo_check.R diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index e323c404..77c62eec 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -73,11 +73,11 @@ jobs: id: commit run: | branch_name='preview-${{ github.event.pull_request.number }}' - git diff --name-only origin/main -- docs >/dev/null && changes=true || changes=false + git diff origin/main -- docs >/dev/null && changes=true || changes=false echo $changes if $changes == true; then echo ::set-output name=changes::$(echo 'changes') - git diff --name-only origin/$branch_name -- docs/ >/dev/null && changes=true || changes=false + git diff origin/$branch_name -- docs/ >/dev/null && changes=true || changes=false echo $changes if $changes == true; then git add . --force From cc6c6e41d5fab811087b74750cd468b1e45a2126 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 13:42:37 -0500 Subject: [PATCH 22/47] Get rid of git_repo_check.R too --- .github/sync.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index e71fe121..078e09b6 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -68,8 +68,6 @@ group: dest: .github/workflows/url-checker.yml - source: scripts/spell-check.R dest: scripts/spell-check.R - - source: scripts/git_repo_check.R - dest: scripts/git_repo_check.R ###### TO ADD NEW REPOSITORY USE THIS FORMAT; Feel free to add/drop files that # you specifically would like synced (or not). From 9c1382c450e0db73773164b4da0512f6759601ef Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 13:48:03 -0500 Subject: [PATCH 23/47] Make sure ulrs are running on pull request --- .github/on-triggers.rds | Bin 3477 -> 2850 bytes .github/workflows/url-checker.yml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/on-triggers.rds b/.github/on-triggers.rds index 2db8e017b7a85b38a173a0ff00d72b90de0612cd..6883fc996f154f13332c670e8a0f5397a0275545 100644 GIT binary patch delta 56 zcmbO#y+~|B2_qxRWJfmriM}$E)wyIg+cWo~i8!#eu})TJ6rXItBDeWJ_cTTTwgwM) delta 286 zcmZ1^HdT5<2_vJxL^=J*O)Q$+3JSUk$wjG&C8;Ts6&U3vA7T{^=TiU!T?O^r#LPT( z1{MZR1_lNPkYGV#Nk*}iLbO6kesXqdk-iI#RLO@A_^t>3J~LgN+v6^ zs!K>f^eHH$q^2d7=9E||sHY|76sJz!z^=0S4r4DPBi}?h@5x~tGbev$iV_lpDA!de tEX}N{N-fscn!J%+dE$5X$$6Znlh3oWZVqB$Wu2HQ$qY1jb3W&0MgTs4R7wB< diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index d645a1a8..7dd7ffe0 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -7,8 +7,8 @@ name: Check URLs #---TRIGGER-START---# on: workflow_dispatch: - pull_request: - branches: [ main ] + pull_request: + branches: [ main ] #---TRIGGER-END----# jobs: build: From ccee843c3a3da174449de93a546dba5e62d5d510 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 14:08:07 -0500 Subject: [PATCH 24/47] Update all --- .github/on-triggers.rds | Bin 2850 -> 3540 bytes .github/workflows/check-quizzes.yml | 3 +- .github/workflows/delete-preview.yml | 2 +- .github/workflows/docker-build-test.yml | 13 ++++++- .github/workflows/manage-gha.yml | 33 ++++++++++++++++++ .github/workflows/render-bookdown.yml | 1 + .github/workflows/render-leanpub.yml | 7 ++-- .github/workflows/render-preview.yml | 1 + .github/workflows/style-and-sp-check.yml | 1 + .github/workflows/test-send-updates.yml | 1 + .github/workflows/transfer-rendered-files.yml | 1 + config_automation.yml | 4 +-- 12 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/manage-gha.yml diff --git a/.github/on-triggers.rds b/.github/on-triggers.rds index 6883fc996f154f13332c670e8a0f5397a0275545..9bec8110625acfaf753a599033f648ab2954c123 100644 GIT binary patch delta 314 zcmZ1^c13!EC?nrQu^dH31u#e|O3X{nNG-Nfh*ro=%*@kKC@x7%&&*3#n7HT?qrgNt z{mD%%n%oKsx(dlfsfi`2DU%f#({%EAcGk^7EZMA#e3SQahI8}f SCguU1rJJ6SxS5Mff)M~e+h0Qf delta 104 zcmca2y+~|=C?_ui1A_n%b4)Je@}8I}sQ?8@MTvRI8L7oq3egI=iJ5si3dJRf>6v-y s6Bl1%WC1CjtidBbc@ekiW`34fMugDj47QJ~jJ%Vhc)~Xy=iy}p0I4}000000 diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index e61914c9..f4df5694 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -8,10 +8,11 @@ name: Check Leanpub Quizzes on: workflow_dispatch: pull_request: - branches: [ main, staging] + branches: [ main, staging ] paths: - 'quizzes/*' #---TRIGGER-END----# + jobs: check-quizzes: runs-on: ubuntu-latest diff --git a/.github/workflows/delete-preview.yml b/.github/workflows/delete-preview.yml index 0bc39162..780c2a76 100644 --- a/.github/workflows/delete-preview.yml +++ b/.github/workflows/delete-preview.yml @@ -2,12 +2,12 @@ name: Delete Preview - #---TRIGGER-START---# on: pull_request: types: [closed] #---TRIGGER-END---# + jobs: build-all: runs-on: ubuntu-latest diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index c01b396a..4b9e87a3 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -3,10 +3,21 @@ name: Test build of Dockerfile - #---TRIGGER-START---# on: + release: + types: + - created + pull_request: + branches: + - 'main' + paths: [ docker/Dockerfile, docker/github_package_list.tsv ] workflow_dispatch: + inputs: + dockerhubpush: + description: 'Push to Dockerhub?' + required: true + default: 'false' #---TRIGGER-END----# jobs: diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml new file mode 100644 index 00000000..55ee7e76 --- /dev/null +++ b/.github/workflows/manage-gha.yml @@ -0,0 +1,33 @@ +# Candace Savonen Feb 2022 + +name: Update Github Actions Switches + +on: + push: + path: + - config_automation.yml + +jobs: + update-triggers: + name: Manage GHA + runs-on: ubuntu-latest + steps: + - name: checkout repo + uses: actions/checkout@v2 + + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + # Cleanup Template-specific bits + - name: Cleanup + run: Rscript --vanilla scripts/employ-gha-switches + + # Commit modified files + - name: Commit updated workflows to current branch + id: commit_it + run: | + git add .github/workflows + git commit -m "Update GitHub Actions" + git push || echo no changes to push diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index 92d468aa..bf6162a5 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -14,6 +14,7 @@ on: - docker/* - assets/* #---TRIGGER-END----# + jobs: # This workflow contains a single job called "build-all" render-main: diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index ee27fa5f..4bb82afa 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -3,11 +3,14 @@ name: Render and publish Leanpub - - #---TRIGGER-START---# on: workflow_dispatch: + workflow_run: + workflows: [ "Render Bookdown and Coursera" ] + branches: [ main ] + types: + - completed #---TRIGGER-END----# jobs: diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index 77c62eec..f462ba9f 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -8,6 +8,7 @@ on: pull_request: branches: [ main ] #---TRIGGER-END----# + permissions: write-all jobs: diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 1f9b4814..d6b977d4 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -8,6 +8,7 @@ on: pull_request: branches: [ main ] #---TRIGGER-END---# + jobs: # This workflow contains a single job called "style and check" style-n-check: diff --git a/.github/workflows/test-send-updates.yml b/.github/workflows/test-send-updates.yml index fbba9207..76dfaa02 100644 --- a/.github/workflows/test-send-updates.yml +++ b/.github/workflows/test-send-updates.yml @@ -11,6 +11,7 @@ on: required: true default: 'jhudsl/OTTR_Template_Test' #---TRIGGER-END----# + jobs: test-sync: runs-on: ubuntu-latest diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index 07e05d2c..5a30b8bd 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -18,6 +18,7 @@ on: types: - completed #---TRIGGER-END----# + jobs: file-bookdown-pr: # The type of runner that the job will run on diff --git a/config_automation.yml b/config_automation.yml index 01bacff1..7dfed671 100644 --- a/config_automation.yml +++ b/config_automation.yml @@ -5,8 +5,8 @@ render-preview: yes style-and-sp-check: yes # Docker specific - docker-build-test: no + docker-build-test: yes # Rendering render-bookdown: yes -render-leanpub: no +render-leanpub: yes From 01cba8a7c3b7a9b5b6e88895fdd97d54ba862e70 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 14:09:14 -0500 Subject: [PATCH 25/47] Fix manage-gha --- .github/workflows/manage-gha.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 55ee7e76..ee161274 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -20,11 +20,9 @@ jobs: git config --local user.email "itcrtrainingnetwork@gmail.com" git config --local user.name "jhudsl-robot" - # Cleanup Template-specific bits - - name: Cleanup - run: Rscript --vanilla scripts/employ-gha-switches + - name: Run GHA switches script + run: Rscript --vanilla scripts/employ-gha-switches.R - # Commit modified files - name: Commit updated workflows to current branch id: commit_it run: | From c192dddf6361bdc1c89074c8f5acd18bf663c275 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 14:11:45 -0500 Subject: [PATCH 26/47] Switch what image we use --- .github/workflows/manage-gha.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index ee161274..1f65c588 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -11,6 +11,9 @@ jobs: update-triggers: name: Manage GHA runs-on: ubuntu-latest + container: + image: jhudsl/course_template + steps: - name: checkout repo uses: actions/checkout@v2 From f69702ab9b08f115e85dbeee954b913736db9058 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 14:14:12 -0500 Subject: [PATCH 27/47] Put extract indices after the file is found --- scripts/employ-gha-switches.R | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index 7e096cbf..aee08a3d 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -1,28 +1,28 @@ #!/usr/bin/env Rscript -library(magrittr) +library(magrittr) # Make extract trigger function extract_trigger <- function(gha_contents) { # Extract trigger criteria trigger_start <- grep("TRIGGER-START", gha_contents) trigger_end <- grep("TRIGGER-END", gha_contents) - + return(trigger_start:trigger_end) } # Find .git root directory root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) -### Load in "on" triggers +### Load in "on" triggers # Each github action has its own on_triggers <- readr::read_rds(file.path(root_dir, ".github", "on-triggers.rds")) # Same off trigger for all -off_trigger <- c("#---TRIGGER-START---#", - "on:", - " workflow_dispatch:", +off_trigger <- c("#---TRIGGER-START---#", + "on:", + " workflow_dispatch:", "#---TRIGGER-END----#") ### Read in and set up config automation yaml @@ -31,47 +31,47 @@ off_trigger <- c("#---TRIGGER-START---#", github_actions_dir <- file.path(root_dir, ".github", "workflows") # Get list of github actions files -github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", +github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", full.names = TRUE) # Set up the list of the gha -config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% - data.frame() %>% - t() %>% +config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% + data.frame() %>% + t() %>% data.frame() %>% - tibble::rownames_to_column("gha_files") %>% + tibble::rownames_to_column("gha_files") %>% dplyr::mutate(gha_files = paste0(gsub("\\.", "-", gha_files), ".yml")) colnames(config_yaml)[2] <- "on_or_off" # Read in all files all_gha <- lapply(github_actions_files, function(gha_file) { - + # Read in yaml yaml_contents <- readLines(gha_file) - - # Get trigger indices - trigger_indices <- extract_trigger(yaml_contents) - - # Should this be on or off? - status <- config_yaml %>% - dplyr::filter(basename(gha_file) == gha_files) %>% + + # Should this be on or off? + status <- config_yaml %>% + dplyr::filter(basename(gha_file) == gha_files) %>% dplyr::pull("on_or_off") - + if (length(status) == 1) { message(paste("Turning trigger on:", status, "for", basename(gha_file))) + # Get trigger indices + trigger_indices <- extract_trigger(yaml_contents) + if (status) { trigger <- on_triggers[[basename(gha_file)]] } else { trigger <- off_trigger } - + # Remove current trigger yaml_contents <- yaml_contents[-trigger_indices] - + # Put new trigger in yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1] - 1) - + writeLines(yaml_contents, gha_file) } }) From ce90b944005a866c7759d1ac5284412c0551c079 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 8 Feb 2022 14:16:46 -0500 Subject: [PATCH 28/47] If push fails echo --- .github/workflows/manage-gha.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 1f65c588..7541a686 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest container: image: jhudsl/course_template - + steps: - name: checkout repo uses: actions/checkout@v2 @@ -31,4 +31,4 @@ jobs: run: | git add .github/workflows git commit -m "Update GitHub Actions" - git push || echo no changes to push + git push origin || echo "No changes to commit" From 4ecf6448f4fddbfa6d71a54f093f22b368cd5558 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Tue, 8 Feb 2022 14:39:30 -0500 Subject: [PATCH 29/47] Add docker tester to the file of what's deleted --- .github/workflows/starting-course.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/starting-course.yml b/.github/workflows/starting-course.yml index b439ff25..6112504d 100644 --- a/.github/workflows/starting-course.yml +++ b/.github/workflows/starting-course.yml @@ -39,6 +39,8 @@ jobs: .github/sync.yml \ .github/test-sync.yml \ .github/workflows/starting-course.yml \ + # For now, getting rid of this since it adds more confusion than helpfulness + .github/workflows/docker-build-test.yml \ .github/ISSUE_TEMPLATE/course-template-problem-report.md \ .github/ISSUE_TEMPLATE/course-template-feature-request.md \ resources/code_output \ @@ -55,6 +57,7 @@ jobs: docs/*.md \ manuscript/* + # Commit modified files - name: Commit deleted files id: commit_it From 4433b36b9b9187b3f318a4b82a8aa47e96b7c749 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Tue, 8 Feb 2022 14:57:33 -0500 Subject: [PATCH 30/47] Make render coursera its own thing --- .github/on-triggers.rds | Bin 3540 -> 3659 bytes .github/workflows/docker-build-test.yml | 3 +- .github/workflows/release-notes.yml | 2 +- .github/workflows/render-bookdown.yml | 58 ++---------------- .github/workflows/render-coursera.yml | 56 +++++++++++++++++ .github/workflows/render-leanpub.yml | 10 +-- .github/workflows/render-preview.yml | 2 +- .github/workflows/starting-course.yml | 3 +- .github/workflows/style-and-sp-check.yml | 2 +- .github/workflows/transfer-rendered-files.yml | 2 +- .github/workflows/url-checker.yml | 2 +- config_automation.yml | 7 ++- scripts/store-triggers.R | 3 + 13 files changed, 77 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/render-coursera.yml diff --git a/.github/on-triggers.rds b/.github/on-triggers.rds index 9bec8110625acfaf753a599033f648ab2954c123..6b7bf6686cb217c814bfaea99b19cb034e598547 100644 GIT binary patch delta 243 zcmca2eOhKiDI+8QWJhNG$#U$Plg}|~GRjYERokq@B*!>;Ik&-Neim`C$Yd85%gH&c zK9f(f@IwT?u^3NwWbI>AnS6m&ky}Y2mVt$VlYxN&q<`{uMxn_TY^FdR$zTPN!p`}n zMa8K_iC7iZK#bJj5#Rih%?x650W;L1EGC)BN0_B2@8fWXCtb47YXDI=r662!#K rRh$}3P{R*!Z-%la@=W69%T3HnOi$HK&q$ms!D~OchnHh=74Jm=s docker/git_token.txt - # - # # Build docker image - # - name: Build Docker image - # uses: docker/build-push-action@v2 - # with: - # push: false - # load: true - # context: docker - # file: docker/Dockerfile - # tags: jhudsl/course_template - # - # # Push the Docker image - # - name: Push Docker image - # run: docker push jhudsl/course_template - -###### END OF DOCKER UPDATE CHUNK ############################################## - # We want a fresh run of the renders each time - name: Delete old docs/* run: rm -r docs/* @@ -80,26 +44,12 @@ jobs: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all'); file.copy(from = 'assets', to = 'docs/assets', overwrite = TRUE)" -##### If you do not wish to host your course on Coursera, you can delete this section ##### - # Run Coursera version - - name: Run Coursera version of render - id: coursera - run: | - docker run \ - --mount type=bind,target=/home/rstudio,source=$PWD \ - --user "$(id -u):$(id -g)" \ - jhudsl/course_template \ - Rscript -e "ottr::render_coursera()" - -##### End of Coursera rendering section ######################################## - # This checks on the steps before it and makes sure that they completed. # If the renders didn't complete we don't want to commit the file changes - - name: Check on render steps - if: steps.bookdown.outcome != 'success' || steps.coursera.outcome != 'success' + - name: Check on render step + if: steps.bookdown.outcome != 'success' run: | echo Bookdown status ${{steps.bookdown.outcome}} - echo Coursera status ${{steps.coursera.outcome}} exit 1 # Commit the rendered bookdown files diff --git a/.github/workflows/render-coursera.yml b/.github/workflows/render-coursera.yml new file mode 100644 index 00000000..81e7ccc1 --- /dev/null +++ b/.github/workflows/render-coursera.yml @@ -0,0 +1,56 @@ + +# Candace Savonen Apr 2021 + +name: Render Coursera + +#---TRIGGER-START---# +on: + workflow_dispatch: + workflow_run: + workflows: [ "Render Bookdown" ] + branches: [ main, staging ] + types: + - completed +#---TRIGGER-END----# + +jobs: + render-main: + runs-on: ubuntu-latest + + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.GH_PAT }} + + # Run Coursera version + - name: Run Coursera version of render + id: coursera + run: | + docker run \ + --mount type=bind,target=/home/rstudio,source=$PWD \ + --user "$(id -u):$(id -g)" \ + jhudsl/course_template \ + Rscript -e "ottr::render_coursera()" + + # Convert quizzes to Coursera format + - name: Convert quizzes to coursera + run: Rscript -e "ottr::render_coursera(convert_quizzes = TRUE)" + + # This checks on the steps before it and makes sure that they completed. + # If the renders didn't complete we don't want to commit the file changes + - name: Check on render steps + if: steps.coursera.outcome != 'success' + run: | + echo Coursera status ${{steps.coursera.outcome}} + exit 1 + + # Commit the rendered bookdown files + - name: Commit rendered Coursera files + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git add --force docs/coursera/* + git commit -m 'Render Coursera' || echo "No changes to commit" + git push origin main || echo "No changes to push" diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 4bb82afa..9090226b 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -1,14 +1,14 @@ # Jan 2022 Candace Savonen -name: Render and publish Leanpub +name: Render Leanpub #---TRIGGER-START---# on: workflow_dispatch: workflow_run: - workflows: [ "Render Bookdown and Coursera" ] - branches: [ main ] + workflows: [ "Render Coursera" ] + branches: [ main, staging ] types: - completed #---TRIGGER-END----# @@ -46,10 +46,6 @@ jobs: chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \ make_book_txt = TRUE)" - # Convert quizzes to Coursera format - - name: Convert quizzes to coursera - run: Rscript -e "ottr::render_coursera(convert_quizzes = TRUE)" - # Commit the rendered leanpub files - name: Commit rendered leanpub files run: | diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index f462ba9f..72dad9b3 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -6,7 +6,7 @@ name: Render Preview #---TRIGGER-START---# on: pull_request: - branches: [ main ] + branches: [ main, staging ] #---TRIGGER-END----# permissions: write-all diff --git a/.github/workflows/starting-course.yml b/.github/workflows/starting-course.yml index 6112504d..0c8ee7cd 100644 --- a/.github/workflows/starting-course.yml +++ b/.github/workflows/starting-course.yml @@ -7,8 +7,7 @@ name: Starting a new course #---TRIGGER-START---# on: push: - branches: - - main + branches: [ main, staging ] workflow_dispatch: #---TRIGGER-END---# diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index d6b977d4..f4b2551c 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -6,7 +6,7 @@ name: Style and spell check R markdowns #---TRIGGER-START---# on: pull_request: - branches: [ main ] + branches: [ main, staging ] #---TRIGGER-END---# jobs: diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index 5a30b8bd..986ecd88 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -14,7 +14,7 @@ on: # Only run after the render finishes running workflow_run: workflows: [ "Render Bookdown and Coursera" ] - branches: [ main ] + branches: [ main, staging ] types: - completed #---TRIGGER-END----# diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index 7dd7ffe0..7ed2bcbc 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -8,7 +8,7 @@ name: Check URLs on: workflow_dispatch: pull_request: - branches: [ main ] + branches: [ main, staging ] #---TRIGGER-END----# jobs: build: diff --git a/config_automation.yml b/config_automation.yml index 7dfed671..1a01216a 100644 --- a/config_automation.yml +++ b/config_automation.yml @@ -4,9 +4,10 @@ url-checker: yes render-preview: yes style-and-sp-check: yes -# Docker specific - docker-build-test: yes - # Rendering render-bookdown: yes render-leanpub: yes +render-coursera: yes + +# Docker specific +docker-build-test: yes diff --git a/scripts/store-triggers.R b/scripts/store-triggers.R index 3e7005cd..9d1b988d 100644 --- a/scripts/store-triggers.R +++ b/scripts/store-triggers.R @@ -11,6 +11,9 @@ github_actions_dir <- file.path(root_dir, ".github", "workflows") github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", full.names = TRUE) +# Don't manage the manager +github_actions_files <- grep("manage-gha.yml", github_actions_files, value = TRUE, invert = TRUE) + # Read in all files all_gha <- lapply(github_actions_files, readLines) names(all_gha) <- basename(github_actions_files) From aae872e60d2abdc8a358e595e6824f648b78ac95 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Tue, 8 Feb 2022 15:05:14 -0500 Subject: [PATCH 31/47] Add blank lines --- .github/workflows/check-quizzes.yml | 2 -- .github/workflows/manage-gha.yml | 10 +++++++--- .github/workflows/render-preview.yml | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index f4df5694..189ae4d8 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -1,9 +1,7 @@ - # Candace Savonen Jan 2022 name: Check Leanpub Quizzes - #---TRIGGER-START---# on: workflow_dispatch: diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 7541a686..e582e4d4 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -29,6 +29,10 @@ jobs: - name: Commit updated workflows to current branch id: commit_it run: | - git add .github/workflows - git commit -m "Update GitHub Actions" - git push origin || echo "No changes to commit" + git diff origin/${{ github.head_ref }} -- .github/workflows >/dev/null && changes=true || changes=false + if $changes == true; then + git add . --force + git commit -m 'Update GHA switches' + git pull --set-upstream origin ${{ github.head_ref }} --allow-unrelated-histories + git push + fi diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index 72dad9b3..c3c56767 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -2,7 +2,6 @@ name: Render Preview - #---TRIGGER-START---# on: pull_request: From ef0d1e6c88dc0002ff2d01396ef31f0a65cf2f5b Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Tue, 8 Feb 2022 19:16:59 -0500 Subject: [PATCH 32/47] Add render-coursera.yml to sync.yml --- .github/sync.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index 078e09b6..bb381017 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -27,10 +27,12 @@ group: files: - source: .github/workflows/render-bookdown.yml dest: .github/workflows/render-bookdown.yml - - source: .github/workflows/render-preview.yml - dest: .github/workflows/render-preview.yml + - source: .github/workflows/render-coursera.yml + dest: .github/workflows/render-coursera.yml - source: .github/workflows/render-leanpub.yml dest: .github/workflows/render-leanpub.yml + - source: .github/workflows/render-preview.yml + dest: .github/workflows/render-preview.yml - source: .github/workflows/docker-build-test.yml dest: .github/workflows/docker-build-test.yml - source: .github/workflows/transfer-rendered-files.yml From 955b491376e44b7e8129f5a300682afed0b9aa3b Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 9 Feb 2022 08:43:19 -0500 Subject: [PATCH 33/47] Polishing --- .github/workflows/render-bookdown.yml | 13 +-- .github/workflows/render-coursera.yml | 13 +-- .github/workflows/render-leanpub.yml | 14 ++- scripts/get_spell_errors.R | 77 ---------------- scripts/get_the_gist.R | 126 -------------------------- 5 files changed, 12 insertions(+), 231 deletions(-) delete mode 100644 scripts/get_spell_errors.R delete mode 100644 scripts/get_the_gist.R diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index 02f18efe..297604bd 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -14,19 +14,16 @@ on: #---TRIGGER-END----# jobs: - # This workflow contains a single job called "build-all" - render-main: + render-bookdown: runs-on: ubuntu-latest + container: + image: jhudsl/course_template - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout uses: actions/checkout@v2 with: - # get the full repo fetch-depth: 0 - # use github PAT token: ${{ secrets.GH_PAT }} # We want a fresh run of the renders each time @@ -37,10 +34,6 @@ jobs: - name: Run bookdown render id: bookdown run: | - docker run \ - --mount type=bind,target=/home/rstudio,source=$PWD \ - --user "$(id -u):$(id -g)" \ - jhudsl/course_template \ Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all'); file.copy(from = 'assets', to = 'docs/assets', overwrite = TRUE)" diff --git a/.github/workflows/render-coursera.yml b/.github/workflows/render-coursera.yml index 81e7ccc1..df8d5e33 100644 --- a/.github/workflows/render-coursera.yml +++ b/.github/workflows/render-coursera.yml @@ -14,8 +14,10 @@ on: #---TRIGGER-END----# jobs: - render-main: + render-coursera: runs-on: ubuntu-latest + container: + image: jhudsl/course_template steps: - name: checkout @@ -27,15 +29,6 @@ jobs: # Run Coursera version - name: Run Coursera version of render id: coursera - run: | - docker run \ - --mount type=bind,target=/home/rstudio,source=$PWD \ - --user "$(id -u):$(id -g)" \ - jhudsl/course_template \ - Rscript -e "ottr::render_coursera()" - - # Convert quizzes to Coursera format - - name: Convert quizzes to coursera run: Rscript -e "ottr::render_coursera(convert_quizzes = TRUE)" # This checks on the steps before it and makes sure that they completed. diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 9090226b..46336a9c 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -14,34 +14,32 @@ on: #---TRIGGER-END----# jobs: - # This workflow contains a single job called "build-all" - render-main: + render-leanpub: runs-on: ubuntu-latest container: image: jhudsl/ottr - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout uses: actions/checkout@v2 with: - # get the full repo fetch-depth: 0 - # use github PAT token: ${{ secrets.GH_PAT }} - # Run leanpub rendering + # Create screenshots - name: Run the screenshot creation run: | chapt_urls=$(Rscript --vanilla scripts/make_screenshots.R \ --git_pat ${{ secrets.GH_PAT }} \ --repo $GITHUB_REPOSITORY) + # We want a fresh run of the renders each time + - name: Delete old manuscript/ + run: rm -rf manuscript/ + # Run Leanpub rendering - name: Run ottr::bookdown_to_embed_leanpub run: | - rm -rf manuscript Rscript -e "ottr::bookdown_to_embed_leanpub( \ chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \ make_book_txt = TRUE)" diff --git a/scripts/get_spell_errors.R b/scripts/get_spell_errors.R deleted file mode 100644 index 82e7cb6b..00000000 --- a/scripts/get_spell_errors.R +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env Rscript - -# Written by Candace Savonen Dec 2021 - -# Ran by GitHub actions, given a repository name and a GitHub PAT, get the most recent spell check results. - -library(magrittr) -library(optparse) - -option_list <- list( - optparse::make_option( - c("--repo"), - type = "character", - default = NULL, - help = "GitHub repository name, e.g. jhudsl/OTTR_Template", - ), - optparse::make_option( - c("--git_pat"), - type = "character", - default = NULL, - help = "GitHub personal access token", - ) -) - -# Read the arguments passed -opt_parser <- optparse::OptionParser(option_list = option_list) -opt <- optparse::parse_args(opt_parser) - -repo_name <- opt$repo -git_pat <- opt$git_pat - -if (!is.character(repo_name)) { - repo_name <- as.character(repo_name) -} - -if (!is.character(git_pat)) { - git_pat <- as.character(git_pat) -} - -# Declare URL -url <- paste0("https://api.github.com/repos/", repo_name, "/actions/artifacts") - -# Github api get -response <- httr::GET( - url, - httr::add_headers(Authorization = paste0("token ", git_pat)), - httr::accept_json() -) - -if (httr::http_error(response)) { - warning(paste0("url: ", url, " failed")) -} - -# Get content as JSON -artifacts <- httr::content(response, as = "parsed")$artifacts - -if (length(artifacts) < 1) { - warning("No results") -} - -# Make it a data frame -artifacts_df <- do.call(rbind.data.frame, as.list(artifacts)) - -# We only care about the spell check results and the most recent one -the_url <- artifacts_df %>% - dplyr::filter(name == "spell-check-results") %>% - dplyr::top_n(1, created_at) %>% - dplyr::pull(archive_download_url) - -# Github api get the location of the artifact -response <- httr::GET( - the_url, - httr::add_headers(Authorization = paste0("token ", git_pat)) -) - -# Print out download url -write(response$url, stdout()) diff --git a/scripts/get_the_gist.R b/scripts/get_the_gist.R deleted file mode 100644 index 4beb79e9..00000000 --- a/scripts/get_the_gist.R +++ /dev/null @@ -1,126 +0,0 @@ -# Handle Gists! - -library(magrittr) - -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) - -option_list <- list( - optparse::make_option( - opt_str = c("--gist_key"), - type = "character", - default = NULL, - help = "The key for what the spell check file for this pull request and repository is - In github actions will be: e.g. ${{ github.repository }}_spell_check_${{ github.event.pull_request.number }}", - ), - optparse::make_option( - c("--file"), - type = "character", - default = NULL, - help = "The file to be stored in the gist. Must be relative to base git repository", - ), - optparse::make_option( - opt_str = "--delete", type = "character", - default = "FALSE", help = "Needs a 'TRUE/FALSE' whether the gist should be deleted after we find it" - ), - optparse::make_option( - c("--git_pat"), - type = "character", - default = NULL, - help = "GitHub personal access token stored in a text file", - ), - optparse::make_option( - opt_str = c("-v", "--verbose"), type = "character", - default = "FALSE", help = "Needs a 'TRUE/FALSE' whether more messages should be printed" - ) -) - -# Read the arguments passed -opt_parser <- optparse::OptionParser(option_list = option_list) -opt <- optparse::parse_args(opt_parser) -opt$delete <- as.logical(opt$delete) -opt$verbose <- as.logical(opt$verbose) -opt$file <- file.path(root_dir, opt$file) - - -if (!file.exists(opt$file) && !opt$delete) { - stop(paste("Specified file:", opt$file, "does not exist")) -} - -# Make sure we can login before we continue -system(paste("gh auth login --with-token <", opt$git_pat)) - -get_the_gist <- function(user = "jhudsl-robot", - verbose = TRUE) { - - # Declare URL - url <- paste0("https://api.github.com/users/", user, "/gists?per_page=1000000") - - # Github api get - response <- httr::GET( - url, - httr::accept_json() - ) - - if (httr::http_error(response)) { - warning(paste0("url: ", url, " failed")) - } - - # Get content as JSON - gists <- httr::content(response, as = "parsed") - - - description_key <- unlist(gists)[grep("description", names(unlist(gists)))] - id <- unlist(gists)[grep("^id$", names(unlist(gists)))] - gist_urls <- unlist(gists)[grep("files.spell_check_results.tsv.raw_url", names(unlist(gists)))] - - gists_df <- data.frame(description_key, id, gist_urls) - - return(gists_df) -} - -gist_df <- get_the_gist() - - -if (nrow(gist_df) < 1 ){ - if (opt$verbose) warning("No gists found at all") - gist_target <- gist_df -} else { - gist_target <- gist_df %>% - dplyr::filter(description_key == opt$gist_key) -} - -if (nrow(gist_target) < 1 ) { - # If gist is not found: - if (opt$verbose) message(paste0("No gists match the key:", opt$gist_key)) - if (opt$delete) { - # Warn that there isn't anything to delete - warning("No gist to delete.") - } else { - # Create it - message(paste("Creating gist:", opt$gist_key)) - system(paste("gh gist create --public", opt$file, "-d", opt$gist_key)) - } -} else { - # If gist is found: - if (opt$delete) { - # Delete it - message(paste("Deleting gist:", opt$gist_key)) - system(paste("gh gist delete", gist_target$id)) - } else { - # Or update it - message(paste("Updating gist:", opt$gist_key)) - system(paste("gh gist edit", gist_target$id, "-f", opt$file, "--add", opt$file)) - } -} - - -if (!opt$delete) { - # Print out the url - gist_target <- get_the_gist() %>% - dplyr::filter(description_key == opt$gist_key) %>% - dplyr::pull(gist_urls) - - write(gist_target, stdout()) -} - From 60e27ae85961ee239c8a0f36085b6bceb1bf37ae Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 9 Feb 2022 08:52:26 -0500 Subject: [PATCH 34/47] Polishing up comments and etc --- .github/workflows/delete-preview.yml | 2 +- .github/workflows/docker-build-test.yml | 6 +++--- .github/workflows/release-notes.yml | 5 +++++ .github/workflows/render-bookdown.yml | 5 +++++ .github/workflows/render-coursera.yml | 5 +++++ .github/workflows/render-leanpub.yml | 5 +++++ .github/workflows/render-preview.yml | 7 +------ .github/workflows/send-updates.yml | 2 +- .github/workflows/style-and-sp-check.yml | 1 - .github/workflows/transfer-rendered-files.yml | 2 -- .github/workflows/url-checker.yml | 8 ++++---- 11 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.github/workflows/delete-preview.yml b/.github/workflows/delete-preview.yml index 780c2a76..81b68b93 100644 --- a/.github/workflows/delete-preview.yml +++ b/.github/workflows/delete-preview.yml @@ -9,7 +9,7 @@ on: #---TRIGGER-END---# jobs: - build-all: + delete-preview: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index 390078c5..33f81cac 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -1,6 +1,6 @@ # Candace Savonen Apr 2021 -name: Test build of Dockerfile +name: Build of Docker #---TRIGGER-START---# @@ -20,14 +20,14 @@ on: #---TRIGGER-END----# jobs: - build: + build-docker: runs-on: ubuntu-latest steps: - name: checkout repo uses: actions/checkout@v2 - - name: login as jhudsl-robot + - name: Login as jhudsl-robot run: | git config --local user.email "itcrtrainingnetwork@gmail.com" git config --local user.name "jhudsl-robot" diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index f4eb7d02..69c8eeb0 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -13,6 +13,11 @@ jobs: pr-comment: runs-on: ubuntu-latest steps: + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + - uses: mshick/add-pr-comment@v1 if: ${{ github.head_ref == 'repo-sync/OTTR_Template/default' }} with: diff --git a/.github/workflows/render-bookdown.yml b/.github/workflows/render-bookdown.yml index 297604bd..5c8253dc 100644 --- a/.github/workflows/render-bookdown.yml +++ b/.github/workflows/render-bookdown.yml @@ -26,6 +26,11 @@ jobs: fetch-depth: 0 token: ${{ secrets.GH_PAT }} + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + # We want a fresh run of the renders each time - name: Delete old docs/* run: rm -r docs/* diff --git a/.github/workflows/render-coursera.yml b/.github/workflows/render-coursera.yml index df8d5e33..cfc3a04a 100644 --- a/.github/workflows/render-coursera.yml +++ b/.github/workflows/render-coursera.yml @@ -26,6 +26,11 @@ jobs: fetch-depth: 0 token: ${{ secrets.GH_PAT }} + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + # Run Coursera version - name: Run Coursera version of render id: coursera diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 46336a9c..61ff1e8d 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -26,6 +26,11 @@ jobs: fetch-depth: 0 token: ${{ secrets.GH_PAT }} + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + # Create screenshots - name: Run the screenshot creation run: | diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index c3c56767..d6f4231e 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -11,14 +11,12 @@ on: permissions: write-all jobs: - # This workflow contains a single job called "build-all" render-preview: runs-on: ubuntu-latest container: image: jhudsl/course_template - # Steps represent a sequence of tasks that will be executed as part of the job + steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout files uses: actions/checkout@v2 with: @@ -51,14 +49,11 @@ jobs: id: bookdown run: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')" -##### If you do not wish to host your course on Coursera, you can delete this section ##### # Run Coursera version - name: Run Coursera version of render id: coursera run: Rscript -e "ottr::render_coursera()" -##### End of Coursera rendering section ######################################## - # This checks on the steps before it and makes sure that they completed. # If the renders didn't complete we don't want to commit the file changes - name: Check on render steps diff --git a/.github/workflows/send-updates.yml b/.github/workflows/send-updates.yml index fe309b82..0b0a6949 100644 --- a/.github/workflows/send-updates.yml +++ b/.github/workflows/send-updates.yml @@ -22,7 +22,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@master - - name: login as jhudsl-robot + - name: Login as jhudsl-robot run: | git config --local user.email "itcrtrainingnetwork@gmail.com" git config --local user.name "jhudsl-robot" diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index f4b2551c..7e664d84 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -10,7 +10,6 @@ on: #---TRIGGER-END---# jobs: - # This workflow contains a single job called "style and check" style-n-check: runs-on: ubuntu-latest container: diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index 986ecd88..b70c47ce 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -21,10 +21,8 @@ on: jobs: file-bookdown-pr: - # The type of runner that the job will run on runs-on: ubuntu-latest - # Get repository name by dropping Bookdown if it exists but always append _Leanpub steps: - name: Run git repo check id: git_repo_check diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index 7ed2bcbc..d089edb3 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -3,22 +3,22 @@ # This github actions tests URLs in the Rmd files, README, and CONTRIBUTING.md name: Check URLs - #---TRIGGER-START---# on: workflow_dispatch: pull_request: branches: [ main, staging ] #---TRIGGER-END----# + jobs: - build: + url-check: runs-on: ubuntu-latest steps: - name: checkout repo uses: actions/checkout@v2 - - name: login as jhudsl-robot + - name: Login as jhudsl-robot run: | git config --local user.email "itcrtrainingnetwork@gmail.com" git config --local user.name "jhudsl-robot" @@ -30,7 +30,7 @@ jobs: cleanup: true # A comma-separated list of file types to cover in the URL checks - file_types: .Rmd + file_types: .Rmd, .md # Choose whether to include file with no URLs in the prints. print_all: false From 28fa844bdcc8509eed3006d5c6dcfbf6d4a05c4b Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 9 Feb 2022 08:54:48 -0500 Subject: [PATCH 35/47] No spaces --- .github/workflows/url-checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml index d089edb3..3e556851 100644 --- a/.github/workflows/url-checker.yml +++ b/.github/workflows/url-checker.yml @@ -30,7 +30,7 @@ jobs: cleanup: true # A comma-separated list of file types to cover in the URL checks - file_types: .Rmd, .md + file_types: .Rmd,.md # Choose whether to include file with no URLs in the prints. print_all: false From 6c31f07cc06b0aa76e6ecf0bf35286a7b5aacd9b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:33:45 -0500 Subject: [PATCH 36/47] Update trigger handling --- .github/workflows/manage-gha.yml | 1 - .github/workflows/style-and-sp-check.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index e582e4d4..d674d7d7 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -33,6 +33,5 @@ jobs: if $changes == true; then git add . --force git commit -m 'Update GHA switches' - git pull --set-upstream origin ${{ github.head_ref }} --allow-unrelated-histories git push fi diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 7e664d84..1e5ae2ec 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -2,7 +2,6 @@ name: Style and spell check R markdowns - #---TRIGGER-START---# on: pull_request: From 1274e9e72f45457beebb8eab3ecb2f589e964073 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:37:02 -0500 Subject: [PATCH 37/47] Fix GHA branch handling --- .github/workflows/manage-gha.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index d674d7d7..98a7f9af 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -29,7 +29,8 @@ jobs: - name: Commit updated workflows to current branch id: commit_it run: | - git diff origin/${{ github.head_ref }} -- .github/workflows >/dev/null && changes=true || changes=false + branch_name=$(git rev-parse --abbrev-ref HEAD) + git diff origin/$branch_name -- .github/workflows >/dev/null && changes=true || changes=false if $changes == true; then git add . --force git commit -m 'Update GHA switches' From 5a429cc52421076f3a77e69d19109746f142acf2 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:40:38 -0500 Subject: [PATCH 38/47] Echo if no changes to commit --- .github/workflows/manage-gha.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 98a7f9af..01fa89dc 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -30,9 +30,6 @@ jobs: id: commit_it run: | branch_name=$(git rev-parse --abbrev-ref HEAD) - git diff origin/$branch_name -- .github/workflows >/dev/null && changes=true || changes=false - if $changes == true; then - git add . --force - git commit -m 'Update GHA switches' - git push - fi + git add . --force + git commit -m 'Update GHA switches' || echo "No changes to commit" + git push origin || echo "No changes to commit" From 28c00988683dd49a8b6568e9a5253c955ce95918 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:41:06 -0500 Subject: [PATCH 39/47] Only add github/workflows folder --- .github/workflows/manage-gha.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 01fa89dc..584299ff 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -30,6 +30,6 @@ jobs: id: commit_it run: | branch_name=$(git rev-parse --abbrev-ref HEAD) - git add . --force + git add .github/workflows --force git commit -m 'Update GHA switches' || echo "No changes to commit" git push origin || echo "No changes to commit" From c25a0445e273cbaa1f55b781f8392fa30e09c213 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:44:50 -0500 Subject: [PATCH 40/47] force push --- .github/workflows/render-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index d6f4231e..d71151f1 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -78,7 +78,7 @@ jobs: git add . --force git commit -m 'Render bookdown preview' git pull --set-upstream origin $branch_name --allow-unrelated-histories - git push + git push --force fi fi shell: bash From 2fbb6b76e76d2c0bedbbc90fb78178ee81c8b205 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:53:45 -0500 Subject: [PATCH 41/47] Try to fix manage GHA trigger --- .github/workflows/manage-gha.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 584299ff..6716f45f 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -4,8 +4,8 @@ name: Update Github Actions Switches on: push: - path: - - config_automation.yml + paths: + - 'config_automation.yml' jobs: update-triggers: From 62afbf7a56571f8ac6ccadf1fb3ba1919a90f646 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 10:54:49 -0500 Subject: [PATCH 42/47] Fix commenting --- .github/workflows/manage-gha.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/manage-gha.yml b/.github/workflows/manage-gha.yml index 6716f45f..d36c6441 100644 --- a/.github/workflows/manage-gha.yml +++ b/.github/workflows/manage-gha.yml @@ -9,7 +9,6 @@ on: jobs: update-triggers: - name: Manage GHA runs-on: ubuntu-latest container: image: jhudsl/course_template From 97eee77d0ed8537050ba3dfde1db2f7c7ce680fc Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 11:12:39 -0500 Subject: [PATCH 43/47] Fix file changes --- .github/sync.yml | 1 - .github/workflows/release-notes.yml | 5 ----- _bookdown.yml | 2 +- index.Rmd | 2 +- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index bb381017..013c599d 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -70,7 +70,6 @@ group: dest: .github/workflows/url-checker.yml - source: scripts/spell-check.R dest: scripts/spell-check.R - ###### TO ADD NEW REPOSITORY USE THIS FORMAT; Feel free to add/drop files that # you specifically would like synced (or not). # diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index 69c8eeb0..f4eb7d02 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -13,11 +13,6 @@ jobs: pr-comment: runs-on: ubuntu-latest steps: - - name: Login as jhudsl-robot - run: | - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" - - uses: mshick/add-pr-comment@v1 if: ${{ github.head_ref == 'repo-sync/OTTR_Template/default' }} with: diff --git a/_bookdown.yml b/_bookdown.yml index d5416098..1c9cbe83 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -7,7 +7,7 @@ rmd_files: ["index.Rmd", "About.Rmd", "References.Rmd"] new_session: yes -bibliography: book.bib +bibliography: [book.bib] delete_merged_file: true language: ui: diff --git a/index.Rmd b/index.Rmd index a6140640..7e46307b 100644 --- a/index.Rmd +++ b/index.Rmd @@ -3,7 +3,7 @@ title: "Course Name" date: "`r format(Sys.time(), '%B, %Y')`" site: bookdown::bookdown_site documentclass: book -bibliography: book.bib +bibliography: [book.bib] biblio-style: apalike link-citations: yes description: "Description about Course/Book." From 9e2d930230ec00e8b21b7da28360af2e8084573e Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 14:30:46 -0500 Subject: [PATCH 44/47] Add a gha-triggers.yml file --- gha-triggers.yml | 149 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 gha-triggers.yml diff --git a/gha-triggers.yml b/gha-triggers.yml new file mode 100644 index 00000000..35dc22b9 --- /dev/null +++ b/gha-triggers.yml @@ -0,0 +1,149 @@ +check-quizzes.yml: + status: on + on-trigger: + workflow_dispatch: + pull_request: + branches: [ main, staging ] + paths: + - 'quizzes/*' + off-trigger: + workflow_dispatch: +delete-preview.yml: render-preview.yml + status: on + on-trigger: + pull_request: + types: [closed] + off-trigger: + workflow_dispatch: +docker-build-test.yml: + status: on + on-trigger: + release: + types: + - created + pull_request: + branches: [ main, staging ] + paths: [ docker/Dockerfile, docker/github_package_list.tsv ] + workflow_dispatch: + inputs: + dockerhubpush: + description: 'Push to Dockerhub?' + required: true + default: 'false' + off-trigger: + workflow_dispatch: + inputs: + dockerhubpush: + description: 'Push to Dockerhub?' + required: true + default: 'false' +release-notes.yml: + status: on + on-trigger: + pull_request: + branches: [ main, staging ] + types: [ opened ] + off-trigger: +render-bookdown.yml: + status: on + on-trigger: + workflow_dispatch: + push: + branches: [ main, staging ] + paths: + - '**.Rmd' + - assets/* + off-trigger: + workflow_dispatch: +render-coursera.yml: render-bookdown.yml + status: on + on-trigger: + workflow_dispatch: + workflow_run: + workflows: [ "Render Bookdown" ] + branches: [ main, staging ] + types: + - completed + off-trigger: + workflow_dispatch: +render-leanpub.yml: render-coursera.yml + status: on + on-trigger: + workflow_dispatch: + workflow_run: + workflows: [ "Render Coursera" ] + branches: [ main, staging ] + types: + - completed + off-trigger: + workflow_dispatch: +render-preview.yml: + status: on + on-trigger: + pull_request: + branches: [ main, staging ] + off-trigger: + workflow_dispatch: +send-updates.yml: + status: on + on-trigger: + release: + types: + - published + workflow_dispatch: + inputs: + prtag: + description: 'Tag to use?' + required: true + default: 'null' + off-trigger: + workflow_dispatch: + inputs: + prtag: + description: 'Tag to use?' + required: true + default: 'null' +starting-course.yml: + status: on + on-trigger: + push: + branches: [ main, staging ] + workflow_dispatch: + off-trigger: + workflow_dispatch: +style-and-sp-check.yml: + status: on + on-trigger: + pull_request: + branches: [ main, staging ] + off-trigger: + workflow_dispatch: +test-send-updates.yml: + status: on + on-trigger: + off-trigger: + workflow_dispatch: + inputs: + repo: + description: 'What repo to test on e.g. jhudsl/OTTR_Template_Test' + required: true + default: 'jhudsl/OTTR_Template_Test' +transfer-rendered-files.yml: render-bookdown.yml + status: on + on-trigger: + workflow_dispatch: + workflow_run: + workflows: [ "Render Bookdown" ] + branches: [ main, staging ] + types: + - completed + off-trigger: + workflow_dispatch: +url-checker.yml: + status: on + on-trigger: + workflow_dispatch: + pull_request: + branches: [ main, staging ] + off-trigger: + workflow_dispatch: From cba55f8d7b05ceecc788b922f5b8bd0b33069b1e Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 14:31:13 -0500 Subject: [PATCH 45/47] Update workflow name --- .github/workflows/transfer-rendered-files.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index b70c47ce..61bca65c 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -11,9 +11,8 @@ name: Bookdown to Leanpub repo copy over #---TRIGGER-START---# on: workflow_dispatch: - # Only run after the render finishes running workflow_run: - workflows: [ "Render Bookdown and Coursera" ] + workflows: [ "Render Bookdown" ] branches: [ main, staging ] types: - completed From 316072df6a617c3b035fb5e7aa4b456c9094318a Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 16:55:33 -0500 Subject: [PATCH 46/47] Move yml and fix script --- gha-triggers.yml => .github/gha-triggers.yml | 12 +- scripts/employ-gha-switches.R | 148 ++++++++++++------- 2 files changed, 106 insertions(+), 54 deletions(-) rename gha-triggers.yml => .github/gha-triggers.yml (92%) diff --git a/gha-triggers.yml b/.github/gha-triggers.yml similarity index 92% rename from gha-triggers.yml rename to .github/gha-triggers.yml index 35dc22b9..b969e2a9 100644 --- a/gha-triggers.yml +++ b/.github/gha-triggers.yml @@ -8,13 +8,14 @@ check-quizzes.yml: - 'quizzes/*' off-trigger: workflow_dispatch: -delete-preview.yml: render-preview.yml +delete-preview.yml: status: on on-trigger: pull_request: types: [closed] off-trigger: workflow_dispatch: + dependent_on: render-preview.yml docker-build-test.yml: status: on on-trigger: @@ -55,7 +56,7 @@ render-bookdown.yml: - assets/* off-trigger: workflow_dispatch: -render-coursera.yml: render-bookdown.yml +render-coursera.yml: status: on on-trigger: workflow_dispatch: @@ -66,7 +67,8 @@ render-coursera.yml: render-bookdown.yml - completed off-trigger: workflow_dispatch: -render-leanpub.yml: render-coursera.yml + dependent_on: render-bookdown.yml +render-leanpub.yml: status: on on-trigger: workflow_dispatch: @@ -77,6 +79,7 @@ render-leanpub.yml: render-coursera.yml - completed off-trigger: workflow_dispatch: + dependent_on: render-coursera.yml render-preview.yml: status: on on-trigger: @@ -128,7 +131,7 @@ test-send-updates.yml: description: 'What repo to test on e.g. jhudsl/OTTR_Template_Test' required: true default: 'jhudsl/OTTR_Template_Test' -transfer-rendered-files.yml: render-bookdown.yml +transfer-rendered-files.yml: status: on on-trigger: workflow_dispatch: @@ -139,6 +142,7 @@ transfer-rendered-files.yml: render-bookdown.yml - completed off-trigger: workflow_dispatch: + dependent_on: render-bookdown.yml url-checker.yml: status: on on-trigger: diff --git a/scripts/employ-gha-switches.R b/scripts/employ-gha-switches.R index aee08a3d..3b7169f8 100644 --- a/scripts/employ-gha-switches.R +++ b/scripts/employ-gha-switches.R @@ -2,76 +2,124 @@ library(magrittr) -# Make extract trigger function -extract_trigger <- function(gha_contents) { - # Extract trigger criteria - trigger_start <- grep("TRIGGER-START", gha_contents) - trigger_end <- grep("TRIGGER-END", gha_contents) +option_list <- list( + optparse::make_option( + c("--overwrite"), + action = "store_true", + default = FALSE, + help = "TRUE or FALSE overwrite the trigger no matter what", + ) +) + +# Read the arguments passed +opt_parser <- optparse::OptionParser(option_list = option_list) +opt <- optparse::parse_args(opt_parser) - return(trigger_start:trigger_end) -} # Find .git root directory root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) -### Load in "on" triggers - -# Each github action has its own -on_triggers <- readr::read_rds(file.path(root_dir, ".github", "on-triggers.rds")) - -# Same off trigger for all -off_trigger <- c("#---TRIGGER-START---#", - "on:", - " workflow_dispatch:", - "#---TRIGGER-END----#") - -### Read in and set up config automation yaml +######## Load in triggers +# Each github action has its own on and off trigger versions which are stored +# in this file -- if triggers need to be altered, they must be altered in this file to take effect +trigger_config <- yaml::yaml.load_file(file.path(root_dir, ".github", "gha-triggers.yml")) +######## Get the github actions file paths # Get github actions directory github_actions_dir <- file.path(root_dir, ".github", "workflows") # Get list of github actions files -github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", - full.names = TRUE) +github_actions_files <- list.files(github_actions_dir, + pattern = "\\.yml$", + full.names = TRUE +) + +######## Set up dataframe with information about the GHA +gha_df <- data.frame(gha_files = names(trigger_config)) -# Set up the list of the gha -config_yaml <- yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% +# Read in the configuration file with the specs +config_df <- + yaml::read_yaml(file.path(root_dir, "config_automation.yml")) %>% data.frame() %>% t() %>% data.frame() %>% tibble::rownames_to_column("gha_files") %>% + dplyr::rename(new_status = '.') %>% dplyr::mutate(gha_files = paste0(gsub("\\.", "-", gha_files), ".yml")) -colnames(config_yaml)[2] <- "on_or_off" +# Extract the "dependent on" information +dependent_on_df <- data.frame(dependent_on = unlist(trigger_config)[grep("dependent_on", names(unlist(trigger_config)))], + gha_files = gsub("\\.dependent_on$", "", grep("dependent_on", names(unlist(trigger_config)), value = TRUE))) -# Read in all files -all_gha <- lapply(github_actions_files, function(gha_file) { +# For GHA dependent on other ones, switch their status based on what the new status is +dependent_on_df$recoded_status <- config_df$new_status[match(dependent_on_df$dependent_on, config_df$gha_files)] - # Read in yaml +# Put it all together +gha_df <- gha_df %>% + dplyr::left_join(config_df) %>% + dplyr::left_join(dependent_on_df) %>% + dplyr::mutate(new_status = dplyr::case_when( + !is.na(recoded_status) ~ recoded_status, + TRUE ~ new_status) + ) + +config_gha <- function(gha_file) { + + # Read in this GHA yaml yaml_contents <- readLines(gha_file) - # Should this be on or off? - status <- config_yaml %>% + # Get info about this particular GHA + trigger_info <- trigger_config[[basename(gha_file)]] + + # Extract what the status should be + new_status <- gha_df %>% dplyr::filter(basename(gha_file) == gha_files) %>% - dplyr::pull("on_or_off") - - if (length(status) == 1) { - message(paste("Turning trigger on:", status, "for", basename(gha_file))) - # Get trigger indices - trigger_indices <- extract_trigger(yaml_contents) - - if (status) { - trigger <- on_triggers[[basename(gha_file)]] - } else { - trigger <- off_trigger - } - - # Remove current trigger - yaml_contents <- yaml_contents[-trigger_indices] - - # Put new trigger in - yaml_contents <- append(yaml_contents, trigger, after = trigger_indices[1] - 1) - - writeLines(yaml_contents, gha_file) + dplyr::pull("new_status") + + # If status specified in the config_automation.yml continue + if (!is.na(new_status) && length(new_status) == 1) { + + # If current status doesn't match specified status + # and it wasn't specified to overwrite anyway... + if ((new_status != trigger_info$status) || opt$overwrite) { + + # Output message + message(paste("Switching trigger for", basename(gha_file), "to", new_status)) + + # Get trigger for whether this should be on or off + trigger <- ifelse(new_status, trigger_info[["on-trigger"]], trigger_info[["off-trigger"]]) + + # Make sure it has `on:` at the beginning + trigger$on <- trigger + trigger <- trigger[-1] + + # Temporarily write to yaml so we can read in as plain text + yaml::write_yaml(trigger, "tmp-trigger.yml") + + # Find out where this trigger is supposed to go + trigger_indices <- (grep("TRIGGER-START", yaml_contents) + 1):(grep("TRIGGER-END", yaml_contents) - 1) + + # Remove current trigger + yaml_contents <- yaml_contents[-trigger_indices] + + # Set up new yaml trigger + trigger_text <- gsub("\\'on\\':", "on:", readLines("tmp-trigger.yml")) + + # Put new trigger in + yaml_contents <- append( + yaml_contents, + trigger_text, + after = trigger_indices[1] - 1 + ) + + # Remove temporary file + file.remove("tmp-trigger.yml") + + # Write lines to file + writeLines(yaml_contents, gha_file) + } } -}) +} + +# Read in all files +all_gha <- lapply(github_actions_files, config_gha) From 0e55b557d0d4804a82882301dbe269f7f1e2c93b Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 9 Feb 2022 17:41:14 -0500 Subject: [PATCH 47/47] Don't need store-triggers.R anymore! --- scripts/store-triggers.R | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 scripts/store-triggers.R diff --git a/scripts/store-triggers.R b/scripts/store-triggers.R deleted file mode 100644 index 9d1b988d..00000000 --- a/scripts/store-triggers.R +++ /dev/null @@ -1,32 +0,0 @@ -# Write on-trigger yaml -# This script stores what the 'on' triggers look like for each github action - -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".github")) - -# Get github actions directory -github_actions_dir <- file.path(root_dir, ".github", "workflows") - -# Get list of github actions files -github_actions_files <- list.files(github_actions_dir, pattern = "\\.yml$", - full.names = TRUE) - -# Don't manage the manager -github_actions_files <- grep("manage-gha.yml", github_actions_files, value = TRUE, invert = TRUE) - -# Read in all files -all_gha <- lapply(github_actions_files, readLines) -names(all_gha) <- basename(github_actions_files) - -# Make extract trigger function -extract_trigger <- function(gha_contents) { - # Extract trigger criteria - trigger_start <- grep("TRIGGER-START", gha_contents) - trigger_end <- grep("TRIGGER-END", gha_contents) - - return(gha_contents[trigger_start:trigger_end]) -} - -on_triggers <- lapply(all_gha, extract_trigger) - -readr::write_rds(on_triggers, file.path(root_dir, ".github", "on-triggers.rds"))