Skip to content

Commit

Permalink
Add report-maker.yml here. (#512)
Browse files Browse the repository at this point in the history
* delete report.maker.yml

* Add report-maker.yml here
  • Loading branch information
cansavvy authored Mar 21, 2022
1 parent e6b7e44 commit 883f6e4
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
147 changes: 147 additions & 0 deletions .github/workflows/report-maker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Candace Savonen March 2022

name: Run error checker

on:
workflow_call:
inputs:
check_type:
required: true
type: string
error_min:
default: 0
type: number

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

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

- name: Declare variables
id: declare
run: |
if ${{inputs.check_type == 'spelling'}} ;then
error_name='Spelling errors'
report_path='resources/spell_check_results.tsv'
elif ${{inputs.check_type == 'urls'}} ;then
error_name='Broken URLs'
report_path='resources/url_checks.csv'
elif ${{inputs.check_type == 'quiz_format'}} ;then
error_name='Quiz format errors'
report_path='resources/question_error_report.tsv'
fi
echo $error_name
echo $report_path
echo "::set-output name=error_name::$error_name"
echo "::set-output name=report_path::$report_path"
- name: Configure git
run: |
git config --local user.email "[email protected]"
git config --local user.name "jhudsl-robot"
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

###################### Run the appropriate test ################################

- name: URLs checker
if: ${{ inputs.check_type == 'urls' }}
uses: urlstechie/urlchecker-action@master
with:
branch: preview-${{ github.event.pull_request.number }}
cleanup: false
file_types: .Rmd,.md
print_all: false
exclude_files: .github/PULL_REQUEST_TEMPLATE.md, docs/*
exclude_urls: https://jhudatascience.org/{Course_Name}}
force_pass: true
save: ${{ steps.declare.outputs.report_path }}

- name: Count URL errors
if: ${{ inputs.check_type == 'urls' }}
run: |
echo "chk_results=$(Rscript scripts/url-check.R)" >> $GITHUB_ENV
- name: Run spelling check
if: ${{ inputs.check_type == 'spelling' }}
run: |
echo "chk_results=$(Rscript scripts/spell-check.R)" >> $GITHUB_ENV
- name: Run quiz check
if: ${{ inputs.check_type == 'quiz_format' }}
run: |
Rscript -e "ottrpal::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 "chk_results=$results" >> $GITHUB_ENV
############################# Handle commenting ################################

- name: Commit check errors
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git add --force ${{ steps.declare.outputs.report_path }} || echo "No changes to commit"
git commit -m 'Add ${{ steps.declare.outputs.error_name }} check file' || echo "No changes to commit"
git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
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 }}'
error_url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/$branch_name/${{ steps.declare.outputs.report_path }}
echo ::set-output name=time::$(date +'%Y-%m-%d')
echo ::set-output name=commit_id::$GITHUB_SHA
echo ::set-output name=error_url::$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: ${{ steps.declare.outputs.error_name }}

- name: There are errors!
if: ${{ env.chk_results >= inputs.error_min }}
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: ${{ steps.declare.outputs.error_name }} :warning:
There are ${{ steps.declare.outputs.error_name }} 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.error_url }})
_Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace

- name: Check check results - fail if too many errors
if: ${{ env.chk_results >= inputs.error_min }}
run: exit 1

- name: No errors
if: ${{ env.chk_results < inputs.error_min }}
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 ${{ steps.declare.outputs.error_name }}! :tada:
_Comment updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
1 change: 1 addition & 0 deletions .github/workflows/starting-course.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
# Cleanup
rm -rf \
.github/workflows/report-maker.yml \
.github/workflows/send-updates.yml \
.github/workflows/test-send-updates.yml \
.github/sync.yml \
Expand Down

0 comments on commit 883f6e4

Please sign in to comment.