From e07c215909f7dceb32f0f29003c660803e23cf6f Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Fri, 18 Feb 2022 21:18:13 -0500 Subject: [PATCH] Add a "no quizzes" handling ability as well as some merge conflict resolutions (#480) * Add docker image as option * Add a "no quizzes" option * Add some ${{ }} * Missed one * Fix typo * Test no quiz render * Skip quiz_dir * Update Leanpub/Coursera handling * Fix file path * Polish up screenshot making * Make it not a force push * Update file path * git set-remote with PAT * Add git set remote * git pull settings * git add all for coursera * Update trigger for transfer * set output_dir * Update file handling * add runs-on * Update folders that are transferred * Update PR comment too * return defaults * Restore quizzes * switch theirs -> ours --- .github/sync.yml | 2 - .github/workflows/pull_request.yml | 20 +++---- .github/workflows/render-all.yml | 53 ++++++++++++++----- .github/workflows/transfer-rendered-files.yml | 4 +- scripts/make_screenshots.R | 2 +- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index ab7d2b00..3839f7e7 100755 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -3,8 +3,6 @@ group: - files: - - source: config_automation.yml - dest: config_automation.yml - source: .github/workflows/ dest: .github/workflows/ deleteOrphaned: true diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ddf0e37d..c71bdc73 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -100,7 +100,7 @@ jobs: branch_name='preview-${{ github.event.pull_request.number }}' git add --force resources/spell_check_results.tsv git commit -m 'Add spell check file' || echo "No changes to commit" - git pull --set-upstream origin $branch_name --allow-unrelated-histories + git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours git push --force origin $branch_name || echo "No changes to commit" - name: Build components of the spell check comment @@ -243,18 +243,10 @@ jobs: - name: Commit quiz check errors run: | branch_name='preview-${{ 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 + git add --force question_error_report.tsv || echo "No changes to commit" + git commit -m 'Add question error report file' || echo "No changes to commit" + git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours + git push origin $branch_name || echo "No changes to commit" - name: Build components of the quiz check comment id: build-components @@ -359,7 +351,7 @@ jobs: echo ::set-output name=changes::$changes git add . --force git commit -m 'Render preview' || echo "No changes to commit" - git pull --set-upstream origin $branch_name --allow-unrelated-histories + git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours git push --force || echo "No changes to commit" shell: bash diff --git a/.github/workflows/render-all.yml b/.github/workflows/render-all.yml index 772391b4..d76dd945 100644 --- a/.github/workflows/render-all.yml +++ b/.github/workflows/render-all.yml @@ -30,6 +30,7 @@ jobs: toggle_coursera: "${{ env.RENDER_COURSERA }}" toggle_leanpub: "${{ env.RENDER_LEANPUB }}" rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}" + toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" render-bookdown: name: Render bookdown @@ -73,11 +74,13 @@ jobs: # Commit the rendered bookdown files - name: Commit rendered bookdown files + env: + GH_PAT: ${{ secrets.GH_PAT }} run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" + git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} 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" render-tocless: @@ -108,11 +111,13 @@ jobs: # Commit the TOC-less version files - name: Commit tocless bookdown files + env: + GH_PAT: ${{ secrets.GH_PAT }} run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" + git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} 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" render-leanpub: @@ -138,29 +143,47 @@ jobs: # Create screenshots - name: Run the screenshot creation run: | + # Remove old folder + rm -rf resources/chapt_screen_images + + # Make new screenshots chapt_urls=$(Rscript --vanilla scripts/make_screenshots.R \ --git_pat ${{ secrets.GH_PAT }} \ - --repo $GITHUB_REPOSITORY) + --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: Run ottrpal::bookdown_to_embed_leanpub + 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, \ + quiz_dir = NULL)" + + - name: Run ottrpal::bookdown_to_embed_leanpub + 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)" - # Commit the rendered leanpub files - - name: Commit rendered leanpub files + # Commit the rendered Leanpub files + - name: Commit rendered Leanpub files + env: + GH_PAT: ${{ secrets.GH_PAT }} run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" + git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} git add --force manuscript/* + git add --force resources/* git commit -m 'Render Leanpub' || echo "No changes to commit" - git push --force origin main || echo "No changes to push" + git pull --allow-unrelated-histories --strategy-option=ours + git push origin main || echo "No changes to push" render-coursera: name: Finish Coursera prep @@ -184,15 +207,17 @@ jobs: # Run Coursera version - name: Convert Leanpub quizzes to Coursera - if: needs.yaml-check.outputs.toggle_leanpub == 'yes' + if: needs.yaml-check.outputs.toggle_leanpub == 'yes' && needs.yaml-check.outputs.toggle_quiz_check == 'yes' id: coursera run: Rscript -e "ottrpal::convert_coursera_quizzes()" # Commit the rendered bookdown files - name: Commit rendered Coursera files + env: + GH_PAT: ${{ secrets.GH_PAT }} run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - git add --force docs/coursera/* + git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY} + git add --force . 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" diff --git a/.github/workflows/transfer-rendered-files.yml b/.github/workflows/transfer-rendered-files.yml index 504e36ae..82f96439 100644 --- a/.github/workflows/transfer-rendered-files.yml +++ b/.github/workflows/transfer-rendered-files.yml @@ -33,8 +33,10 @@ jobs: toggle_leanpub: "${{ env.RENDER_LEANPUB }}" - file-bookdown-pr: + file-quizzes-pr: + name: File _Quizzes Transfer PR runs-on: ubuntu-latest + needs: [yaml-check] if: ${{needs.yaml-check.outputs.toggle_coursera == 'yes' || needs.yaml-check.outputs.toggle_leanpub == 'yes'}} steps: diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index 6180ec64..317009f3 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -54,7 +54,7 @@ if (is.null(opt$base_url)) { base_url <- cow::get_pages_url(repo_name = opt$repo, git_pat = opt$git_pat) } -chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc")) +chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc/")) file_names <- lapply(chapt_df$url, function(url) { file_name <- gsub(".html", ".png", file.path(output_folder, basename(url)))