Skip to content

Cleanup template files #1

Cleanup template files

Cleanup template files #1

Workflow file for this run

# Candace Savonen 2021
# Updated May 2025
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@v4
with:
fetch-depth: 0
# 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.
# Delete the branch if this has been run before
- name: Delete branch locally and remotely
run: git push origin --delete preview-${{ github.event.pull_request.number }} || echo "No branch to delete"
# Make the branch fresh
- name: Make the branch fresh
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
branch_name='preview-${{ github.event.pull_request.number }}'
echo branch doesnt exist
git checkout -b $branch_name || echo branch exists
git push --set-upstream origin $branch_name || echo branch exists remotely
shell: bash
outputs:
toggle_website: "${{ env.RENDER_WEBSITE }}"
toggle_spell_check: "${{ env.SPELL_CHECK }}"
spell_error_min: "${{ env.SPELL_ERROR_MIN }}"
toggle_style_code: "${{ env.STYLE_CODE }}"
toggle_url_check: "${{ env.URL_CHECKER }}"
url_error_min: "${{ env.URL_ERROR_MIN }}"
toggle_quiz_check: "${{ env.CHECK_QUIZZES }}"
quiz_error_min: "${{ env.QUIZ_ERROR_MIN }}"
toggle_md_linter: "${{ env.MARKDOWN_LINTER }}"
toggle_readability: "${{ env.READABILITY_REPORT }}"
toggle_render_preview: "${{ env.RENDER_PREVIEW }}"
toggle_dictionary_sort: "${{ env.DICTIONARY_SORT }}"
rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}"
toggle_feedback_link: "${{ env.FEEDBACK_LINK }}"
toggle_student_guide: "${{ env.RENDER_STUDENT_GUIDE }}"
########################## Make the error reports ##############################
ottr-reports:
name: Run Reports
needs: yaml-check
if: ${{needs.yaml-check.outputs.toggle_spell_check == 'true' || needs.yaml-check.outputs.toggle_url_check == 'true' || needs.yaml-check.outputs.toggle_quiz_check == 'true'}}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Reports
id: run-reports
uses: ottrproject/ottr-reports@main
with:
check_spelling: ${{needs.yaml-check.outputs.toggle_spell_check}}
spelling_error_min: ${{needs.yaml-check.outputs.spell_error_min}}
check_urls: ${{needs.yaml-check.outputs.toggle_url_check}}
url_error_min: ${{needs.yaml-check.outputs.url_error_min}}
check_quiz_form: ${{needs.yaml-check.outputs.toggle_quiz_check}}
quiz_error_min: ${{needs.yaml-check.outputs.quiz_error_min}}
sort_dictionary: ${{needs.yaml-check.outputs.toggle_dictionary_sort}}
############################# Style the code ###################################
style-code:
name: Style code
needs: yaml-check
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_style_code == 'true'}}
container:
image: jhudsl/base_ottr:main
steps:
- name: Checkout files
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run styler
run: Rscript -e "styler::style_file(list.files(pattern = '(R|q)md$', recursive = FALSE, full.names = TRUE));warnings()"
- name: Commit styled files
run: |
git config --system --add safe.directory "$GITHUB_WORKSPACE"
git add \*md
git commit -m 'Style *mds' || echo "No changes to commit"
git push origin || echo "No changes to commit"
############################# Readability Report ###################################
readability-report:
name: Readability report
needs: yaml-check
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_readability == 'true'}}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Readability report
uses: Rebilly/lexi@v2
with:
github-token: ${{ secrets.GH_PAT }}
glob: '**/*.md'
############################# AnVIL Feedback Link ##############################
# Do not remove this section with OTTR syncs!
anvil-feedback:
name: Make AnVIL Feedback Link
needs: [yaml-check]
runs-on: ubuntu-latest
container:
image: ${{needs.yaml-check.outputs.rendering_docker_image}}
steps:
- name: Checkout files
uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up git checkout
- name: Set up git checkout
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
branch_name='${{ github.head_ref }}'
git fetch --all
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} --allow-unrelated-histories
shell: bash
# Make sure the link for AnVIL feedback is prepopulated for the specific course
- name: Set up feedback link
id: feedback
if: ${{needs.yaml-check.outputs.toggle_feedback_link == 'true'}}
run: |
bash .github/AnVIL_Feedback_Script.sh
git add _output.yml
git commit -m 'Set up feedback link' || echo "No changes to commit"
git push origin || echo "No changes to commit"
############################# Render Preview ###################################
render-preview:
name: Render preview
needs: [yaml-check, anvil-feedback]
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_render_preview == 'true'}}
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run render
uses: ottrproject/ottr-preview@main
with:
toggle_website: ${{needs.yaml-check.outputs.toggle_website}}
docker_image: ${{needs.yaml-check.outputs.rendering_docker_image}}
############################# Render Student Guide #############################
# Do not remove this section with OTTR syncs!
render-anvil-special:
name: Render AnVIL Special
needs: [yaml-check, render-preview]
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_render_preview == 'true'}}
container:
image: ${{needs.yaml-check.outputs.rendering_docker_image}}
steps:
- name: Checkout files
uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up git checkout
- name: Set up git checkout
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
branch_name='preview-${{ github.event.pull_request.number }}'
git fetch --all
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }} --allow-unrelated-histories
shell: bash
# Render a student guide if specified. This is a bit clunky because
# Bookdown does not work well if the files aren't named as such in the
# root directory
- name: Run student guide render
if: ${{needs.yaml-check.outputs.toggle_student_guide == 'true'}}
id: student_guide
run: |
mkdir tmp1
mv _bookdown.yml _output.yml tmp1
mv student-guide/_bookdown.yml student-guide/_output.yml .
Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"
mv _bookdown.yml _output.yml student-guide
mv tmp1/_bookdown.yml tmp1/_output.yml .
rm -r tmp1
git add student-guide/*
git commit -m 'Create student guide' || echo "No changes to commit"
# 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 "changes=$changes" >> $GITHUB_OUTPUT
git add . --force
git commit -m 'Render AnVIL Special' || echo "No changes to commit"
git pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force || echo "No changes to commit"
shell: bash