diff --git a/.github/workflows/check-quizzes.yml b/.github/workflows/check-quizzes.yml deleted file mode 100644 index 189ae4d8..00000000 --- a/.github/workflows/check-quizzes.yml +++ /dev/null @@ -1,116 +0,0 @@ -# Candace Savonen Jan 2022 - -name: Check Leanpub Quizzes - -#---TRIGGER-START---# -on: - workflow_dispatch: - pull_request: - branches: [ main, staging ] - paths: - - 'quizzes/*' -#---TRIGGER-END----# - -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 "itcrtrainingnetwork@gmail.com" - 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 fetch --all - 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 "ottr::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 diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build.yml similarity index 68% rename from .github/workflows/docker-build-test.yml rename to .github/workflows/docker-build.yml index 33f81cac..d1971c0b 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build.yml @@ -1,26 +1,18 @@ # Candace Savonen Apr 2021 -name: Build of Docker +name: Build Docker - -#---TRIGGER-START---# on: - release: - types: - - created - pull_request: - branches: [ main, staging ] - paths: [ docker/Dockerfile, docker/github_package_list.tsv ] workflow_dispatch: inputs: dockerhubpush: description: 'Push to Dockerhub?' required: true default: 'false' -#---TRIGGER-END----# jobs: build-docker: + name: Build Docker image runs-on: ubuntu-latest steps: @@ -33,18 +25,15 @@ jobs: git config --local user.name "jhudsl-robot" - name: Don't re-test if this is a sync branch - if: ${{ github.head_ref == 'repo-sync/OTTR_Template/default' }} run: | echo This was tested on OTTR_Template no need to re-run # Set up Docker build - name: Set up Docker Buildx - if: ${{ github.head_ref != 'repo-sync/OTTR_Template/default' }} uses: docker/setup-buildx-action@v1 # Setup layer cache - name: Cache Docker layers - if: ${{ github.head_ref != 'repo-sync/OTTR_Template/default' }} uses: actions/cache@v2 with: path: /tmp/.buildx-cache @@ -58,12 +47,10 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Get token - if: ${{ github.head_ref != 'repo-sync/OTTR_Template/default' }} run: echo ${{ secrets.GH_PAT }} > docker/git_token.txt # Build docker image - name: Build Docker image - if: ${{ github.head_ref != 'repo-sync/OTTR_Template/default' }} uses: docker/build-push-action@v2 with: push: false @@ -86,14 +73,6 @@ jobs: run: docker push jhudsl/course_template - name: Get the version - if: ${{ github.head_ref != 'repo-sync/OTTR_Template/default' }} id: get_version run: | echo ::set-output name=version::$(echo $GITHUB_REF | cut -d / -f 3) - - # Push the Docker image if it is a release - - name: Push Docker image if release - if: ${{ github.event_name == 'release' }} - run: | - docker tag jhudsl/course_template:latest jhudsl/course_template:${{ steps.get_version.outputs.version }} - docker push jhudsl/course_template:${{ steps.get_version.outputs.version }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..c1943e01 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,452 @@ +# Candace Savonen Dec 2021 + +name: Pull Request + +on: + pull_request: + branches: [ main, staging ] + +jobs: + + yaml-check: + name: Load user automation choices + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Use the yaml-env-action action. + - name: Load environment from YAML + uses: doughepi/yaml-env-action@v1.0.0 + with: + files: config_automation.yml # Pass a space-separated list of configuration files. Rightmost files take precedence. + + - name: Verify Dockerfiles changed? + uses: tj-actions/verify-changed-files@v8.8 + id: verify-changed-files + with: + files: | + docker/Dockerfile + docker/github_package_list.tsv + + outputs: + toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" + toggle_spell_check: "${{ env.STYLE_AND_SP_CHECK }}" + toggle_url_check: "${{ env.URL_CHECKER }}" + toggle_render_preview: "${{ env.RENDER_PREVIEW }}" + toggle_docker_build: "${{ env.DOCKER_BUILD }}" + dockerfiles_changed: steps.verify-changed-files.outputs.files_changed + + style-n-check: + name: Check style and spelling + needs: yaml-check + runs-on: ubuntu-latest + if: ${{needs.yaml-check.outputs.toggle_spell_check == 'yes'}} + 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 "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + branch_name='preview-${{ 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 fetch --all + git checkout $branch_name + git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} + fi + shell: bash + + - name: Run spell check + id: spell_check_run + run: | + results=$(Rscript "scripts/spell-check.R") + echo "::set-output name=sp_chk_results::$results" + cat resources/spell_check_results.tsv + + - name: Archive spelling errors + uses: actions/upload-artifact@v2 + with: + name: spell-check-results + path: resources/spell_check_results.tsv + + - name: Commit spell check errors + run: | + 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 push --force origin $branch_name || echo "No changes to commit" + + - name: Build components of the spell check comment + id: build-components + env: + GH_PAT: ${{ secrets.GH_PAT }} + run: | + branch_name='preview-${{ github.event.pull_request.number }}' + sp_error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/resources/spell_check_results.tsv + echo ::set-output name=time::$(date +'%Y-%m-%d') + echo ::set-output name=commit_id::$GITHUB_SHA + echo ::set-output name=sp_error_url::$sp_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: spelling errors + + - name: Spelling errors! + if: ${{ steps.spell_check_run.outputs.sp_chk_results >= 3 }} + 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 spelling errors that need to be addressed. [Read this guide for more info](https://github.com/jhudsl/OTTR_Template/wiki/Spell-check). + [Download the errors here.](${{ steps.build-components.outputs.sp_error_url }}) + _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + edit-mode: replace + + - name: Check spell check results - fail if too many errors + if: ${{ steps.spell_check_run.outputs.sp_chk_results >= 3 }} + run: exit 1 + + - name: No spelling errors + if: ${{ steps.spell_check_run.outputs.sp_chk_results < 3 }} + 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 spelling errors! :tada: + _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + edit-mode: replace + + - name: Run styler + run: Rscript -e "styler::style_file(list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE));warnings()" + + - name: Commit styled files + run: | + git add \*.Rmd + git add resources/spell_check_results.tsv + git commit -m 'Style Rmds' || echo "No changes to commit" + git push origin || echo "No changes to commit" + + url-check: + name: Check URLs + needs: yaml-check + runs-on: ubuntu-latest + if: ${{needs.yaml-check.outputs.toggle_url_check == 'yes'}} + + steps: + - name: checkout repo + uses: actions/checkout@v2 + + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + - name: URLs-checker + uses: urlstechie/urlchecker-action@master + with: + # Delete the cloned repository after running URLchecked (default is false) + cleanup: true + + # A comma-separated list of file types to cover in the URL checks + file_types: .Rmd,.md + + # Choose whether to include file with no URLs in the prints. + print_all: false + + # A comma separated links to exclude during URL checks + exclude_urls: https://jhudatascience.org/{Course_Name}} + + # choose if the force pass or not + force_pass : true + + check-quizzes: + name: Check Leanpub quizzes + needs: yaml-check + runs-on: ubuntu-latest + container: + image: jhudsl/course_template + if: ${{needs.yaml-check.outputs.toggle_quiz_check == 'yes'}} + steps: + - name: Checkout files + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure git + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + 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 fetch --all + 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 "ottr::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 + + render-preview: + name: Render preview + needs: yaml-check + runs-on: ubuntu-latest + container: + image: jhudsl/course_template + if: ${{needs.yaml-check.outputs.toggle_render_preview == 'yes'}} + steps: + - name: Checkout files + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # Set up git checkout + - name: Set up git checkout + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + branch_name='preview-${{ 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 fetch --all + git checkout $branch_name + git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} + fi + + rm -r docs/* + shell: bash + + # Run bookdown rendering + - name: Run bookdown render + 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()" + + # 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' + run: | + echo Bookdown status ${{steps.bookdown.outcome}} + echo Coursera status ${{steps.coursera.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 add . --force + git commit -m 'Render bookdown 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 + + - 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: latest commit + + - name: Build components of the comment + id: build-components + 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") + 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=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' + 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 }}) + - 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' + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + The latest commit did not produce rendering changes. + + _Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ + edit-mode: replace + + build-docker: + name: Build Docker image + needs: yaml-check + runs-on: ubuntu-latest + if: ${{needs.yaml-check.outputs.toggle_docker_build == 'yes' && needs.yaml-check.outputs.dockerfiles_changed == 'true' && github.head_ref != 'repo-sync/OTTR_Template/default'}} + + steps: + - name: checkout repo + uses: actions/checkout@v2 + + - name: Verify Dockerfiles changed? + uses: tj-actions/verify-changed-files@v8.8 + id: verify-changed-files + with: + files: | + docker/Dockerfile + docker/github_package_list.tsv + + - name: Login as jhudsl-robot + run: | + git config --local user.email "itcrtrainingnetwork@gmail.com" + git config --local user.name "jhudsl-robot" + + # Set up Docker build + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + # Setup layer cache + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Set up Docker Build + uses: docker/setup-buildx-action@v1 + + - name: Get token + run: echo ${{ secrets.GH_PAT }} > docker/git_token.txt + + - name: Build Docker image + uses: docker/build-push-action@v2 + with: + push: false + load: true + context: docker + file: docker/Dockerfile + tags: jhudsl/course_template diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml deleted file mode 100644 index 078a7978..00000000 --- a/.github/workflows/render-preview.yml +++ /dev/null @@ -1,124 +0,0 @@ -# Candace Savonen Apr 2021 - -name: Render Preview - -#---TRIGGER-START---# -on: - pull_request: - branches: [ main, staging ] -#---TRIGGER-END----# - -permissions: write-all - -jobs: - render-preview: - runs-on: ubuntu-latest - container: - image: jhudsl/course_template - - steps: - - name: Checkout files - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - # Set up git checkout - - name: Set up git checkout - run: | - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" - - branch_name='preview-${{ 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 fetch --all - git checkout $branch_name - git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} - fi - - rm -r docs/* - shell: bash - - # Run bookdown rendering - - name: Run bookdown render - 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()" - - # 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' - run: | - echo Bookdown status ${{steps.bookdown.outcome}} - echo Coursera status ${{steps.coursera.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 add . --force - git commit -m 'Render bookdown 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 - - - 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: latest commit - - - name: Build components of the comment - id: build-components - 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") - 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=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' - 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 }}) - - 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' - uses: peter-evans/create-or-update-comment@v1 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - The latest commit did not produce rendering changes. - - _Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ - edit-mode: replace diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml deleted file mode 100644 index 07899132..00000000 --- a/.github/workflows/style-and-sp-check.yml +++ /dev/null @@ -1,118 +0,0 @@ -# Candace Savonen Dec 2021 - -name: Style and spell check R markdowns - -#---TRIGGER-START---# -on: - pull_request: - branches: [ main, staging ] -#---TRIGGER-END---# - -jobs: - style-n-check: - 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 "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" - - branch_name='preview-${{ 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 fetch --all - git checkout $branch_name - git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} - fi - shell: bash - - - name: Run spell check - id: spell_check_run - run: | - results=$(Rscript "scripts/spell-check.R") - echo "::set-output name=sp_chk_results::$results" - cat resources/spell_check_results.tsv - - - name: Archive spelling errors - uses: actions/upload-artifact@v2 - with: - name: spell-check-results - path: resources/spell_check_results.tsv - - - name: Commit spell check errors - run: | - 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 push --force origin $branch_name || echo "No changes to commit" - - - name: Build components of the spell check comment - id: build-components - env: - GH_PAT: ${{ secrets.GH_PAT }} - run: | - branch_name='preview-${{ github.event.pull_request.number }}' - sp_error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/resources/spell_check_results.tsv - echo ::set-output name=time::$(date +'%Y-%m-%d') - echo ::set-output name=commit_id::$GITHUB_SHA - echo ::set-output name=sp_error_url::$sp_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: spelling errors - - - name: Spelling errors! - if: ${{ steps.spell_check_run.outputs.sp_chk_results >= 3 }} - 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 spelling errors that need to be addressed. [Read this guide for more info](https://github.com/jhudsl/OTTR_Template/wiki/Spell-check). - [Download the errors here.](${{ steps.build-components.outputs.sp_error_url }}) - _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ - edit-mode: replace - - - name: Check spell check results - fail if too many errors - if: ${{ steps.spell_check_run.outputs.sp_chk_results >= 3 }} - run: exit 1 - - - name: No spelling errors - if: ${{ steps.spell_check_run.outputs.sp_chk_results < 3 }} - 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 spelling errors! :tada: - _Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_ - edit-mode: replace - - - name: Run styler - run: Rscript -e "styler::style_file(list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE));warnings()" - - - name: Commit styled files - run: | - git add \*.Rmd - git add resources/spell_check_results.tsv - git commit -m 'Style Rmds' || echo "No changes to commit" - git push origin || echo "No changes to commit" diff --git a/.github/workflows/url-checker.yml b/.github/workflows/url-checker.yml deleted file mode 100644 index 3e556851..00000000 --- a/.github/workflows/url-checker.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Adapted from https://github.com/marketplace/actions/url-checker by Candace Savonen - -# This github actions tests URLs in the Rmd files, README, and CONTRIBUTING.md -name: Check URLs - -#---TRIGGER-START---# -on: - workflow_dispatch: - pull_request: - branches: [ main, staging ] -#---TRIGGER-END----# - -jobs: - url-check: - runs-on: ubuntu-latest - - steps: - - name: checkout repo - uses: actions/checkout@v2 - - - name: Login as jhudsl-robot - run: | - git config --local user.email "itcrtrainingnetwork@gmail.com" - git config --local user.name "jhudsl-robot" - - - name: URLs-checker - uses: urlstechie/urlchecker-action@master - with: - # Delete the cloned repository after running URLchecked (default is false) - cleanup: true - - # A comma-separated list of file types to cover in the URL checks - file_types: .Rmd,.md - - # Choose whether to include file with no URLs in the prints. - print_all: false - - # A comma separated links to exclude during URL checks - exclude_urls: https://jhudatascience.org/{Course_Name}} - - # choose if the force pass or not - force_pass : true diff --git a/config_automation.yml b/config_automation.yml new file mode 100644 index 00000000..573368e8 --- /dev/null +++ b/config_automation.yml @@ -0,0 +1,14 @@ +# Formatting Checks (run at pull request) +check-quizzes: yes +url-checker: yes +render-preview: yes +style-and-sp-check: yes + +# Rendering +render-bookdown: yes +render-leanpub: yes +render-coursera: yes + +# Docker specific +docker-build: yes + \ No newline at end of file