Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disentangle bookdown/coursera/leanpub rendering. #459

Merged
merged 8 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
cansavvy marked this conversation as resolved.
Show resolved Hide resolved
# 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:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new section that will run before Leanpub or Coursera if either is set to yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to call this something like "Start Leanpub/Coursera render" and then have the jobs below be "Finish Leanpub" and "Finish Coursera"

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 \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized its redundant to have bookdown re-rendered if we just did it. So we're using the option here to skip the bookdown::render() step done by this function if bookdown was just run previously.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I just realized it never needs to be re-rendered here because the render-tocless section does this.

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"