Skip to content

Commit

Permalink
Disentangle bookdown/coursera/leanpub rendering. (#459)
Browse files Browse the repository at this point in the history
* Rearrange render-all for clarity

* Fix no changes render comment

* Disentangle Leanpub from Coursera from Bookdown

* Update render-tocless

* Delete redundant render

* Fix changes/no_changes bit

* Fix logic

* Incorporate @avahoffman 's comments
  • Loading branch information
cansavvy authored Feb 11, 2022
1 parent f7410e3 commit 0637d3a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 50 deletions.
30 changes: 17 additions & 13 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,27 +326,31 @@ jobs:
id: bookdown
run: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"

# Run Coursera version
- name: Run Coursera version of render
id: coursera
run: Rscript -e "ottr::render_coursera()"
# Run TOC-less version
# Rendered content for Leanpub and Coursera is very similar.
# This job creates a shared scaffold for both.
- name: Run TOC-less version of render
id: tocless
run: Rscript -e "ottr::render_without_toc()"

# 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'
if: steps.bookdown.outcome != 'success' || steps.tocless.outcome != 'success'
run: |
echo Bookdown status ${{steps.bookdown.outcome}}
echo Coursera status ${{steps.coursera.outcome}}
echo Toc-less status ${{steps.tocless.outcome}}
exit 1
# Commit the rendered bookdown files
- name: Commit rendered bookdown files to preview branch
id: commit
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git diff origin/main -- docs >/dev/null && changes=true || changes=false
echo ::set-output name=changes::$changes
git add . --force
git commit -m 'Render bookdown preview' || echo "No changes to commit"
git commit -m 'Render preview' || echo "No changes to commit"
git pull --set-upstream origin $branch_name --allow-unrelated-histories
git push --force || echo "No changes to commit"
shell: bash
Expand All @@ -364,32 +368,32 @@ jobs:
run: |
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")
coursera_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/coursera/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")
docx_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/docs/$course_name.docx")
echo ::set-output name=bookdown_link::$bookdown_link
echo ::set-output name=coursera_link::$coursera_link
echo ::set-output name=tocless_link::$tocless_link
echo ::set-output name=docx_link::$docx_link
echo ::set-output name=time::$(date +'%Y-%m-%d')
echo ::set-output name=commit_id::$GITHUB_SHA
echo ${{steps.commit.outputs.changes}}
- name: Create or update comment
if: steps.commit.outputs.changes == 'changes'
if: steps.commit.outputs.changes == 'true'
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
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 version here](${{ steps.build-components.outputs.coursera_link }})
- See [preview of Coursera/Leanpub version here](${{ steps.build-components.outputs.tocless_link }})
- Download the [preview of .docx file](${{ steps.build-components.outputs.docx_link }})
_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace

- name: No comment if no changes
if: steps.commit.outputs.changes == 'no_changes'
- name: Comment if no changes
if: steps.commit.outputs.changes == 'false'
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
Expand Down
98 changes: 61 additions & 37 deletions .github/workflows/render-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,33 @@ jobs:
git commit -m 'Render bookdown' || echo "No changes to commit"
git push origin main || echo "No changes to push"
render-coursera:
name: Render Coursera
needs: [yaml-check, render-bookdown]
render-tocless:
name: Render TOC-less version for Leanpub or Coursera
needs: [yaml-check]
runs-on: ubuntu-latest
container:
image: jhudsl/course_template
if: ${{needs.yaml-check.outputs.toggle_coursera == 'yes'}}
image: jhudsl/ottr
if: ${{needs.yaml-check.outputs.toggle_coursera == 'yes' || needs.yaml-check.outputs.toggle_leanpub == 'yes'}}

steps:
- name: checkout
uses: actions/checkout@v2
with:
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
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
# Rendered content for Leanpub and Coursera is very similar.
# This job creates a shared scaffold for both.
- name: Run TOC-less version of render
id: tocless
run: Rscript -e "ottr::render_without_toc()"

# Commit the TOC-less version files
- name: Commit tocless bookdown 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 add --force docs/no_toc*
git commit -m 'Render toc-less' || echo "No changes to commit"
git push origin main || echo "No changes to push"
render-leanpub:
name: Render Leanpub
needs: [yaml-check, render-coursera]
name: Finish Leanpub prep
needs: [yaml-check, render-tocless]
runs-on: ubuntu-latest
container:
image: jhudsl/ottr
Expand Down Expand Up @@ -151,10 +133,10 @@ jobs:
- name: Delete old manuscript/
run: rm -rf manuscript/

# Run Leanpub rendering
- name: Run ottr::bookdown_to_embed_leanpub
run: |
Rscript -e "ottr::bookdown_to_embed_leanpub( \
Rscript -e "ottr::bookdown_to_embed_leanpub(
render = FALSE \
chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \
make_book_txt = TRUE)"
Expand All @@ -166,3 +148,45 @@ jobs:
git add --force manuscript/*
git commit -m 'Render Leanpub' || echo "No changes to commit"
git push --force origin main || echo "No changes to push"
render-coursera:
name: Finish Coursera prep
needs: [yaml-check, render-tocless]
runs-on: ubuntu-latest
container:
image: jhudsl/course_template
if: ${{needs.yaml-check.outputs.toggle_coursera == 'yes'}}

steps:
- name: checkout
uses: actions/checkout@v2
with:
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
run: Rscript -e "ottr::convert_coursera_quizzes()"

# 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 quizzes' || echo "No changes to commit"
git push origin main || echo "No changes to push"

0 comments on commit 0637d3a

Please sign in to comment.