Skip to content

Commit

Permalink
Test leanpub from here (#420)
Browse files Browse the repository at this point in the history
* Test leanpub from here

* Update comments

* Add check quizzes too

* Couple edits

* Shut them off for now

* Update comments
  • Loading branch information
cansavvy authored Jan 26, 2022
1 parent 623fed7 commit 42b427f
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 0 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/check-quizzes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

# Candace Savonen Jan 2022

name: Check Leanpub Quizzes

on:
workflow_dispatch:
# pull_request:
# branches: [ main, staging]
# paths:
# - 'quizzes/*'

jobs:
check-quizzes:
runs-on: ubuntu-latest
container:
image: jhudsl/course_template

steps:
- name: Checkout files
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Configure git
run: |
git config --local user.email "[email protected]"
git config --local user.name "jhudsl-robot"
branch_name='check-${{ github.event.pull_request.number }}'
exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs)
if [[ $exists == 0 ]];then
echo branch doesnt exist
git checkout -b $branch_name
git push --set-upstream origin $branch_name
else
echo branch does exist
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }}
fi
shell: bash

- name: Run quiz check
id: quiz_check_run
run: |
Rscript -e "leanbuild::check_quizzes(quiz_dir = 'quizzes', write_report = TRUE, verbose = TRUE)"
results=0
if -f "question_error_report.tsv"; then
results=$(wc -l < question_error_report.tsv >/dev/null)
fi
echo ::set-output name=quiz_chk_results::$results
- name: Commit quiz check errors
run: |
branch_name='check-${{ 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
- name: Build components of the quiz check comment
id: build-components
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
branch_name='check-${{ github.event.pull_request.number }}'
quiz_error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/question_error_report.tsv
echo ::set-output name=time::$(date +'%Y-%m-%d')
echo ::set-output name=commit_id::$GITHUB_SHA
echo ::set-output name=quiz_error_url::$quiz_error_url
# Handle the commenting
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: quiz errors

- name: Quiz errors!
if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: There are quiz errors that need to be addressed. [Read this guide for more info](https://github.com/jhudsl/OTTR_Template/wiki/Publishing-on-Leanpub#setting-up-quizzes).
[Download the errors here.](${{ steps.build-components.outputs.quiz_error_url }})
_Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace

- name: Check quiz check results - fail if too many errors
if: ${{ steps.quiz_check_run.outputs.quiz_chk_results >= 2 }}
run: exit 1

- name: No quiz errors
if: ${{ steps.quiz_check_run.outputs.quiz_chk_results < 2 }}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
No quiz errors detected! :tada:
_Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
48 changes: 48 additions & 0 deletions .github/workflows/render-leanpub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

# Jan 2022 Candace Savonen

name: Render and publish Leanpub

on:
workflow_dispatch:
# pull_request:
# branches: [ main ]
# types: [closed]
# paths:
# - '**.Rmd'
# - docker/*
# - assets/*
# - quizzes/*

jobs:
# This workflow contains a single job called "build-all"
render-main:
runs-on: ubuntu-latest
container:
image: jhudsl/course_template
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout
uses: actions/checkout@v2
with:
# get the full repo
fetch-depth: 0
# use github PAT
token: ${{ secrets.GH_PAT }}

# Run leanpub rendering
- name: Run leanbuild::bookdown_to_leanpub
run: |
Rscript -e "leanbuild::bookdown_to_leanpub(make_book_txt = TRUE);
leanbuild::render_coursera(convert_quizzes = TRUE)"
# Commit the rendered leanpub files
- name: Commit rendered leanpub files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add -A
git add --force manuscript/*
git commit -m 'Render leanpub' || echo "No changes to commit"
git push origin main || echo "No changes to push"
54 changes: 54 additions & 0 deletions quizzes/quiz_ch1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

{quiz, id: quiz_name_here, attempts: 10}

## Template quiz

Put any other instructions your quiz takers need to know here like: Choose the best answer.

{choose-answers: 4}
? First question to ask goes here. (Note- you need a question mark at end like this. Just one is required if using a question mark in your question field)?

C) One correct answer here marked with a "C"
C) A second correct answer here
m) Mandatory incorrect answers have an "m"
m) A second mandatory incorrect answer
o) An optional incorrect answer here marked with an "o"
o) A second optional incorrect answer here

{choose-answers: 4}
? Question example with just a question mark?

C) One correct answer here marked with a "C"
C) A second correct answer here
m) Mandatory incorrect answers have an "m"
m) A second mandatory incorrect answer
o) An optional incorrect answer here marked with an "o"
o) A second optional incorrect answer here

{choose-answers: 4}
? Second question to ask goes here?

C) One correct answer here marked with a "C"
C) A second correct answer here
m) Mandatory incorrect answers have an "m"
m) A second mandatory incorrect answer
o) An optional incorrect answer here marked with an "o"
o) A second optional incorrect answer here


{choose-answers: 4}
? A more complicated example. Note the question mark at the end of the options! Which of the following are correct
1. An option described
2. A second option
3. A third option
4. A fourth option
5. A fifth option ?

C) All of the examples listed except 5
C) All of the listed examples except 5
m) 1, 3, and 5
m) 1, 2, and 3
o) All of the examples except 1 and 5
o) All of the examples listed

{/quiz}

0 comments on commit 42b427f

Please sign in to comment.