From 2ef1ae7cf7d41c7d5c80e99c372308c59e156f6a Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:02:39 -0500 Subject: [PATCH 01/10] Test leanpub from here --- .github/workflows/render-leanpub.yml | 57 ++++++++++++++++++++++++++++ quizzes/quiz_ch1.md | 54 ++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/render-leanpub.yml create mode 100644 quizzes/quiz_ch1.md diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml new file mode 100644 index 00000000..a4557ed4 --- /dev/null +++ b/.github/workflows/render-leanpub.yml @@ -0,0 +1,57 @@ + +# 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 + +name: Render and publish Leanpub + +# Controls when the action will run. Triggers the workflow on push +# events only for the master branch +on: + workflow_dispatch: + pull_request: + types: [closed] + +jobs: + publish: + # 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: + # 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 leanbuild checks +# - name: Run leanbuild checks +# run: | +# docker run \ +# --mount type=bind,target=/home/rstudio,source=$PWD \ +# jhudsl/course_template \ +# Rscript --vanilla scipts/leanbuild_checks.R + + # Run leanpub rendering + - name: Run leanbuild::bookdown_to_leanpub + run: | + docker run \ + --mount type=bind,target=/home/rstudio,source=$PWD \ + jhudsl/course_template \ + Rscript -e "leanbuild::bookdown_to_leanpub(footer_text = '*Please provide any feedback with [this form!](https://forms.gle/hc8Xt3Y2Znjb6M4Y7) We appreciate your thoughts.*'); + leanbuild::render_coursera(convert_quizzes = TRUE)" + + # Commit the rendered leanpub files + - name: Commit rendered leanpub files + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git add -A + git add --force manuscript/* + git commit -m 'Render leanpub' || echo "No changes to commit" + git push origin main || echo "No changes to push" diff --git a/quizzes/quiz_ch1.md b/quizzes/quiz_ch1.md new file mode 100644 index 00000000..26b44552 --- /dev/null +++ b/quizzes/quiz_ch1.md @@ -0,0 +1,54 @@ + +{quiz, id: quiz_name_here, attempts: 10} + +## Template quiz + +Put any other instructions your quiz takers need to know here like: Choose the best answer. + +{choose-answers: 4} +? First question to ask goes here. (Note- you need a question mark at end like this. Just one is required if using a question mark in your question field)? + +C) One correct answer here marked with a "C" +C) A second correct answer here +m) Mandatory incorrect answers have an "m" +m) A second mandatory incorrect answer +o) An optional incorrect answer here marked with an "o" +o) A second optional incorrect answer here + +{choose-answers: 4} +? Question example with just a question mark? + +C) One correct answer here marked with a "C" +C) A second correct answer here +m) Mandatory incorrect answers have an "m" +m) A second mandatory incorrect answer +o) An optional incorrect answer here marked with an "o" +o) A second optional incorrect answer here + +{choose-answers: 4} +? Second question to ask goes here? + +C) One correct answer here marked with a "C" +C) A second correct answer here +m) Mandatory incorrect answers have an "m" +m) A second mandatory incorrect answer +o) An optional incorrect answer here marked with an "o" +o) A second optional incorrect answer here + + +{choose-answers: 4} +? A more complicated example. Note the question mark at the end of the options! Which of the following are correct +1. An option described +2. A second option +3. A third option +4. A fourth option +5. A fifth option ? + +C) All of the examples listed except 5 +C) All of the listed examples except 5 +m) 1, 3, and 5 +m) 1, 2, and 3 +o) All of the examples except 1 and 5 +o) All of the examples listed + +{/quiz} From 481e7fbfce227178f654775a1ec7f1badd64edf9 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:04:28 -0500 Subject: [PATCH 02/10] Update comments --- .github/workflows/render-leanpub.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index a4557ed4..560e356d 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -1,9 +1,5 @@ -# 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 +# Jan 2022 Candace Savonen name: Render and publish Leanpub From 75255a82893ecb9a89bfc248bcb5b28742fdfa20 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:05:27 -0500 Subject: [PATCH 03/10] Add check quizzes too --- .github/workflows/check-quizzes.yml | 112 ++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 .github/workflows/check-quizzes.yml diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml new file mode 100644 index 00000000..3bbf6856 --- /dev/null +++ b/.github/workflows/check-quizzes.yml @@ -0,0 +1,112 @@ + +# Candace Savonen Jan 2022 + +name: Check Leanpub Quizzes + +on: + pull_request: + branches: [ main ] + 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 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 "leanbuild::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 + + # Handle the commenting + - 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 From ab085079c92deeeb3ccb5757739fcfbd50110503 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:18:10 -0500 Subject: [PATCH 04/10] Couple edits --- .github/workflows/check-quizzes.yml | 2 +- .github/workflows/render-leanpub.yml | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 3bbf6856..13891681 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -5,7 +5,7 @@ name: Check Leanpub Quizzes on: pull_request: - branches: [ main ] + branches: [ main, staging] paths: - 'quizzes/*' jobs: diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 560e356d..b7803c20 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -25,14 +25,6 @@ jobs: # use github PAT token: ${{ secrets.GH_PAT }} -# # Run leanbuild checks -# - name: Run leanbuild checks -# run: | -# docker run \ -# --mount type=bind,target=/home/rstudio,source=$PWD \ -# jhudsl/course_template \ -# Rscript --vanilla scipts/leanbuild_checks.R - # Run leanpub rendering - name: Run leanbuild::bookdown_to_leanpub run: | From a5e30d868c357af5576fa2dabc6a43adf4bb6fcc Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:25:23 -0500 Subject: [PATCH 05/10] Shut them off for now --- .github/workflows/check-quizzes.yml | 10 ++++++---- .github/workflows/render-leanpub.yml | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 13891681..0b13fa6a 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -4,10 +4,12 @@ name: Check Leanpub Quizzes on: - pull_request: - branches: [ main, staging] - paths: - - 'quizzes/*' + workflow_dispatch: +# pull_request: +# branches: [ main, staging] +# paths: +# - 'quizzes/*' + jobs: check-quizzes: runs-on: ubuntu-latest diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index b7803c20..3245d6fc 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -7,13 +7,21 @@ name: Render and publish Leanpub # events only for the master branch on: workflow_dispatch: - pull_request: - types: [closed] +# pull_request: +# branches: [ main ] +# types: [closed] +# paths: +# - '**.Rmd' +# - docker/* +# - assets/* +# - quizzes/* jobs: - publish: - # The type of runner that the job will run on + # This workflow contains a single job called "build-all" + render-main: 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 @@ -28,10 +36,7 @@ jobs: # Run leanpub rendering - name: Run leanbuild::bookdown_to_leanpub run: | - docker run \ - --mount type=bind,target=/home/rstudio,source=$PWD \ - jhudsl/course_template \ - Rscript -e "leanbuild::bookdown_to_leanpub(footer_text = '*Please provide any feedback with [this form!](https://forms.gle/hc8Xt3Y2Znjb6M4Y7) We appreciate your thoughts.*'); + Rscript -e "leanbuild::bookdown_to_leanpub(make_book_txt = TRUE); leanbuild::render_coursera(convert_quizzes = TRUE)" # Commit the rendered leanpub files From fac67fd1f1d98e4909ebd283e0fe348fd8faae78 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 17:31:29 -0500 Subject: [PATCH 06/10] Update comments --- .github/workflows/render-leanpub.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 3245d6fc..691696f9 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -3,8 +3,6 @@ name: Render and publish Leanpub -# Controls when the action will run. Triggers the workflow on push -# events only for the master branch on: workflow_dispatch: # pull_request: From 6ea8c43e0ad2fe8a00ff16d3d0bec4cde94b4131 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 18:00:14 -0500 Subject: [PATCH 07/10] Note which places needed to be uncommented --- .github/workflows/check-quizzes.yml | 3 ++- .github/workflows/render-leanpub.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 0b13fa6a..1d028b4e 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -5,11 +5,12 @@ 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 ######### jobs: check-quizzes: runs-on: ubuntu-latest diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 691696f9..97bc41cf 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: +### UNCOMMENT THIS SECTION IF YOU WISH PREPARE YOUR COURSE FOR LEANPUB AUTOMATICALLY # pull_request: # branches: [ main ] # types: [closed] @@ -13,7 +14,7 @@ on: # - docker/* # - assets/* # - quizzes/* - +######### END OF SECTION ######### jobs: # This workflow contains a single job called "build-all" render-main: From 6228cd28971b210e8ee23a89157429f7bda2e101 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 19:28:30 -0500 Subject: [PATCH 08/10] Just making the step clearer --- .github/workflows/render-leanpub.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/render-leanpub.yml b/.github/workflows/render-leanpub.yml index 97bc41cf..2f896fd1 100644 --- a/.github/workflows/render-leanpub.yml +++ b/.github/workflows/render-leanpub.yml @@ -35,8 +35,12 @@ jobs: # Run leanpub rendering - name: Run leanbuild::bookdown_to_leanpub run: | - Rscript -e "leanbuild::bookdown_to_leanpub(make_book_txt = TRUE); - leanbuild::render_coursera(convert_quizzes = TRUE)" + Rscript -e "leanbuild::bookdown_to_leanpub(make_book_txt = TRUE)" + + # Convert quizzes to Coursera format + - name: Convert quizzes to coursera + run: | + Rscript -e "leanbuild::render_coursera(convert_quizzes = TRUE)" # Commit the rendered leanpub files - name: Commit rendered leanpub files From 1ec62336c5ad8b031856d9b41333afd907e3fee4 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 19:30:07 -0500 Subject: [PATCH 09/10] Add a git fetch --- .github/workflows/check-quizzes.yml | 1 + .github/workflows/render-preview.yml | 1 + .github/workflows/style-and-sp-check.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml index 1d028b4e..34649042 100644 --- a/.github/workflows/check-quizzes.yml +++ b/.github/workflows/check-quizzes.yml @@ -36,6 +36,7 @@ jobs: 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 diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index 12a70fc6..a3b91bbf 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -37,6 +37,7 @@ jobs: 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 diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 4deb0c2f..9c7898e0 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -35,6 +35,7 @@ jobs: 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 From abcf1e6ebb8277a0541fdcc3d2431d942c859bf2 Mon Sep 17 00:00:00 2001 From: jhudsl-robot Date: Wed, 26 Jan 2022 19:38:27 -0500 Subject: [PATCH 10/10] Add quizzes to spell check --- scripts/spell-check.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/spell-check.R b/scripts/spell-check.R index 54445781..e7fc2e1c 100644 --- a/scripts/spell-check.R +++ b/scripts/spell-check.R @@ -25,6 +25,13 @@ dictionary <- c(dictionary, spelling::spell_check_text("⬇️")$word) # Only declare `.Rmd` files but not the ones in the style-sets directory files <- list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE) + +# Get quiz file names +quiz_files <- list.files(file.path(root_dir, "quizzes"), pattern = '\\.md$', full.names = TRUE) + +# Put into one list +files <- c(files, quiz_files) + files <- grep("About.Rmd", files, ignore.case = TRUE, invert = TRUE, value = TRUE) files <- grep("style-sets", files, ignore.case = TRUE, invert = TRUE, value = TRUE)