From 5f74611e325116efa304e29900102cceda2b8966 Mon Sep 17 00:00:00 2001 From: Elizabeth Humphries Date: Mon, 1 Jul 2024 11:02:29 -0400 Subject: [PATCH] copying ava fixes for ottr --- .github/workflows/pull_request.yml | 70 ++++++++++------------ .github/workflows/render-all.yml | 93 ++++++++++++++++++------------ config_automation.yml | 4 ++ 3 files changed, 90 insertions(+), 77 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3349cc0..2e122ba 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -14,9 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + token: ${{ secrets.GH_PAT }} # Use the yaml-env-action action. - name: Load environment from YAML @@ -31,15 +32,17 @@ jobs: # Make the branch fresh - name: Make the branch fresh run: | - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' branch_name='preview-${{ github.event.pull_request.number }}' echo branch doesnt exist git checkout -b $branch_name || echo branch exists - git push --set-upstream origin $branch_name + git push --set-upstream origin $branch_name || echo echo branch exists remotely shell: bash + outputs: toggle_spell_check: "${{ env.SPELL_CHECK }}" toggle_style_code: "${{ env.STYLE_CODE }}" @@ -47,7 +50,6 @@ jobs: toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" toggle_render_preview: "${{ env.RENDER_PREVIEW }}" rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}" - render_student_guide: "${{ env.RENDER_STUDENT_GUIDE }}" ########################## Make the error reports ############################## spell-check: @@ -59,6 +61,7 @@ jobs: check_type: spelling error_min: 3 gh_pat: secrets.GH_PAT + branch_name: ${GITHUB_HEAD_REF} url-check: name: Check URLs @@ -69,6 +72,7 @@ jobs: check_type: urls error_min: 0 gh_pat: secrets.GH_PAT + branch_name: ${GITHUB_HEAD_REF} quiz-check: name: Check quiz formatting @@ -79,6 +83,7 @@ jobs: check_type: quiz_format error_min: 0 gh_pat: secrets.GH_PAT + branch_name: ${GITHUB_HEAD_REF} ############################# Style the code ################################### style-code: @@ -91,7 +96,7 @@ jobs: steps: - name: Checkout files - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -117,47 +122,27 @@ jobs: steps: - name: Checkout files - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 # Set up git checkout - name: Set up git checkout run: | - git config --system --add safe.directory "$GITHUB_WORKSPACE" - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' branch_name='preview-${{ github.event.pull_request.number }}' git fetch --all git checkout $branch_name git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} --allow-unrelated-histories shell: bash - - # Make sure the link for AnVIL feedback is prepopulated for the specific course - - name: Set up feedback link - id: feedback - run: bash scripts/AnVIL_Feedback_Script.sh - + # Run bookdown rendering - name: Run bookdown render id: bookdown run: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')" - - # Render a student guide if specified. This is a bit clunky because - # Bookdown does not work well if the files aren't named as such in the - # root directory - - name: Run student guide render - if: ${{needs.yaml-check.outputs.render_student_guide == 'yes'}} - id: student_guide - run: | - mkdir tmp1 - mv _bookdown.yml _output.yml tmp1 - mv student-guide/_bookdown.yml student-guide/_output.yml . - Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')" - mv _bookdown.yml _output.yml student-guide - mv tmp1/_bookdown.yml tmp1/_output.yml . - rm -r tmp1 # Run TOC-less version # Rendered content for Leanpub and Coursera is very similar. @@ -175,6 +160,9 @@ jobs: echo Toc-less status ${{steps.tocless.outcome}} exit 1 + - name: Website preview for download + run: zip website-preview.zip docs/* -r + # Commit the rendered bookdown files - name: Commit rendered bookdown files to preview branch id: commit @@ -184,7 +172,7 @@ jobs: echo "changes=$changes" >> $GITHUB_OUTPUT git add . --force git commit -m 'Render preview' || echo "No changes to commit" - git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours + git pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours git push --force || echo "No changes to commit" shell: bash @@ -199,13 +187,15 @@ jobs: - name: Build components of the comment id: build-components run: | - course_name=$(head -n 1 student-guide/_bookdown.yml | cut -d'"' -f 2| tr " " "-") + course_name=$(head -n 1 _bookdown.yml | cut -d'"' -f 2| tr " " "-") bookdown_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/index.html") tocless_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/no_toc/index.html") - student_docx_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/student-guide/$course_name.docx") + docx_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/docs/$course_name.docx") + zip_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/website-preview.zip") + echo "zip_link=$zip_link" >> $GITHUB_OUTPUT echo "bookdown_link=$bookdown_link" >> $GITHUB_OUTPUT echo "tocless_link=$tocless_link" >> $GITHUB_OUTPUT - echo "student_docx_link=$student_docx_link" >> $GITHUB_OUTPUT + echo "docx_link=$docx_link" >> $GITHUB_OUTPUT echo "time=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT echo ${{steps.commit.outputs.changes}} @@ -218,11 +208,13 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | Re-rendered previews from the latest commit: - - See [preview of Bookdown here](${{ steps.build-components.outputs.bookdown_link }}) - - See [preview of Coursera/Leanpub version here](${{ steps.build-components.outputs.tocless_link }}) - - Download the [preview of the Student Guide .docx file](${{ steps.build-components.outputs.student_docx_link }}) + - :eyes: Quick [preview of course website here](${{ steps.build-components.outputs.bookdown_link }}) \* + - :microscope: Comprehensive [download of the course website here](${{ steps.build-components.outputs.zip_link }}) + - Download the [.docx file](${{ steps.build-components.outputs.docx_link }}) - _Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + \* note not all html features will be properly displayed in the "quick preview" but it will give you a rough idea. + + _Updated at ${{ steps.build-components.outputs.time }} with changes from the latest commit ${{ steps.build-components.outputs.commit_id }}_ edit-mode: replace - name: Comment if no changes diff --git a/.github/workflows/render-all.yml b/.github/workflows/render-all.yml index 65902ba..3de168a 100644 --- a/.github/workflows/render-all.yml +++ b/.github/workflows/render-all.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Use the yaml-env-action action. - name: Load environment from YAML @@ -29,6 +29,7 @@ jobs: toggle_bookdown: "${{ env.RENDER_BOOKDOWN }}" toggle_coursera: "${{ env.RENDER_COURSERA }}" toggle_leanpub: "${{ env.RENDER_LEANPUB }}" + make_book_txt: "${{ env.MAKE_BOOK_TXT }}" rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}" toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" @@ -42,16 +43,16 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_PAT }} - - name: Login as jhudsl-robot + - name: Login as github actions bot run: | - git config --system --add safe.directory "$GITHUB_WORKSPACE" - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' # We want a fresh run of the renders each time - name: Delete old docs/* @@ -98,14 +99,15 @@ jobs: GH_PAT: ${{ secrets.GH_PAT }} run: | git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} + git fetch origin git add --force docs/* git commit -m 'Render bookdown' || echo "No changes to commit" - git pull --allow-unrelated-histories --strategy-option=ours - git push origin main || echo "No changes to push" + git pull --rebase --allow-unrelated-histories --strategy-option=ours + git push -u origin main || echo "No changes to push" render-tocless: name: Render TOC-less version for Leanpub or Coursera - needs: [yaml-check] + needs: [yaml-check, render-bookdown] runs-on: ubuntu-latest container: image: ${{needs.yaml-check.outputs.rendering_docker_image}} @@ -113,16 +115,16 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_PAT }} - - name: Login as jhudsl-robot + - name: Login as github-actions bot run: | - git config --system --add safe.directory "$GITHUB_WORKSPACE" - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' # Rendered content for Leanpub and Coursera is very similar. # This job creates a shared scaffold for both. @@ -136,10 +138,11 @@ jobs: GH_PAT: ${{ secrets.GH_PAT }} run: | git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} + git fetch origin git add --force docs/no_toc* git commit -m 'Render toc-less' || echo "No changes to commit" - git pull --allow-unrelated-histories --strategy-option=ours - git push origin main || echo "No changes to push" + git pull --rebase --allow-unrelated-histories --strategy-option=ours + git push -u origin main || echo "No changes to push" render-leanpub: name: Finish Leanpub prep @@ -151,16 +154,16 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_PAT }} - - name: Login as jhudsl-robot + - name: Login as github actions bot run: | - git config --system --add safe.directory "$GITHUB_WORKSPACE" - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' # Create screenshots - name: Run the screenshot creation @@ -169,31 +172,41 @@ jobs: rm -rf resources/chapt_screen_images # Make new screenshots - chapt_urls=$(Rscript --vanilla scripts/make_screenshots.R \ + curl -o make_screenshots.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/make_screenshots.R + chapt_urls=$(Rscript --vanilla make_screenshots.R \ --git_pat ${{ secrets.GH_PAT }} \ --repo $GITHUB_REPOSITORY \ --output_dir resources/chapt_screen_images) # We want a fresh run of the renders each time - - name: Delete old manuscript/ - run: rm -rf manuscript/ + - name: Delete manuscript/ + env: + GH_PAT: ${{ secrets.GH_PAT }} + run: | + rm -rf manuscript/ + git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} + git fetch origin + git add . + git commit -m 'Delete manuscript folder' || echo "No changes to commit" + git pull --rebase --allow-unrelated-histories --strategy-option=ours + git push -u origin main || echo "No changes to push" - name: Run ottrpal::bookdown_to_embed_leanpub - if: needs.yaml-check.outputs.toggle_quiz_check == 'no' + if: ${{ needs.yaml-check.outputs.toggle_quiz_check == 'no'}} run: | Rscript -e "ottrpal::bookdown_to_embed_leanpub( render = FALSE, \ chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \ - make_book_txt = TRUE, \ + make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'), \ quiz_dir = NULL)" - name: Run ottrpal::bookdown_to_embed_leanpub - if: needs.yaml-check.outputs.toggle_quiz_check == 'yes' + if: ${{ needs.yaml-check.outputs.toggle_quiz_check == 'yes'}} run: | Rscript -e "ottrpal::bookdown_to_embed_leanpub( render = FALSE, \ chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \ - make_book_txt = TRUE)" + make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'))" # Commit the rendered Leanpub files - name: Commit rendered Leanpub files @@ -201,13 +214,12 @@ jobs: GH_PAT: ${{ secrets.GH_PAT }} run: | mkdir -p manuscript - git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} git add --force manuscript/* git add --force resources/* git add --force docs/* git commit -m 'Render Leanpub' || echo "No changes to commit" - git pull --allow-unrelated-histories --strategy-option=ours - git push origin main || echo "No changes to push" + git pull --rebase --allow-unrelated-histories --strategy-option=ours + git push --force --set-upstream origin main || echo "No changes to push" render-coursera: name: Finish Coursera prep @@ -219,16 +231,16 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_PAT }} - - name: Login as jhudsl-robot + - name: Login as github action run: | - git config --system --add safe.directory "$GITHUB_WORKSPACE" - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" + git config --global --add safe.directory $GITHUB_WORKSPACE + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' # Run Coursera version - name: Convert Leanpub quizzes to Coursera @@ -237,14 +249,19 @@ jobs: run: Rscript -e "ottrpal::convert_coursera_quizzes()" # Commit the rendered bookdown files + # Only commit coursera quizzes if the directory is present - name: Commit rendered Coursera files env: GH_PAT: ${{ secrets.GH_PAT }} run: | git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} + git fetch origin + if [ -d 'coursera_quizzes' ]; then + git add --force coursera_quizzes/* + fi git add --force manuscript/* git add --force resources/* git add --force docs/* git commit -m 'Render Coursera quizzes' || echo "No changes to commit" - git pull --allow-unrelated-histories --strategy-option=ours - git push origin main || echo "No changes to push" + git pull --rebase --allow-unrelated-histories --strategy-option=ours + git push -u origin main || echo "No changes to push" diff --git a/config_automation.yml b/config_automation.yml index ccc0611..b1c3f2f 100644 --- a/config_automation.yml +++ b/config_automation.yml @@ -22,6 +22,10 @@ render-coursera: yes ##### Rendering of student guide (if applicable) render-student-guide: yes +## Automate the creation of Book.txt file? TRUE/FALSE? +## This is only relevant if render-leanpub is yes, otherwise it will be ignored +make-book-txt: TRUE + # What docker image should be used for rendering? # The default is jhudsl/course_template:main rendering-docker-image: 'jhudsl/base_ottr:main'