Skip to content

Commit

Permalink
Add a "no quizzes" handling ability as well as some merge conflict re…
Browse files Browse the repository at this point in the history
…solutions (#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
  • Loading branch information
cansavvy authored Feb 19, 2022
1 parent 6b98e41 commit e07c215
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
2 changes: 0 additions & 2 deletions .github/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

group:
- files:
- source: config_automation.yml
dest: config_automation.yml
- source: .github/workflows/
dest: .github/workflows/
deleteOrphaned: true
Expand Down
20 changes: 6 additions & 14 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
53 changes: 39 additions & 14 deletions .github/workflows/render-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"
4 changes: 3 additions & 1 deletion .github/workflows/transfer-rendered-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/make_screenshots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit e07c215

Please sign in to comment.