Skip to content

🔄 Synced file(s) with ottrproject/OTTR_Template_Website #37

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
117 changes: 117 additions & 0 deletions .github/workflows/check-url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Periodic URL Check

on:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *'

jobs:
set-up:
name: Load user automation choices
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
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.
outputs:
toggle_url_check_periodically: "${{ env.URL_CHECK_PERIODICALLY }}"

url-check:
name: Check URLs
needs: set-up
if: ${{needs.set-up.outputs.toggle_url_check_periodically == 'true'}}
runs-on: ubuntu-latest
container:
image: jhudsl/base_ottr:main

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

# Delete the branch if this has been run before
- name: Delete branch locally and remotely
run: git push origin --delete preview-spell-error || 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'

echo branch doesnt exist
git checkout -b preview-spell-error || echo branch exists
git push --set-upstream origin preview-spell-error || echo echo branch exists remotely
shell: bash

- name: Run the check
uses: ottrproject/ottr-reports@main
id: check_results
continue-on-error: true
with:
check_type: urls
error_min: 1

- name: Declare file path and time
id: check-report
run: |
error_num=$(cat check_reports/url_checks.tsv | wc -l)
error_num="$((error_num-1))"
echo "error_num=$error_num" >> $GITHUB_OUTPUT
echo "error_url=https://github.com/${GITHUB_REPOSITORY}/blob/preview-spell-error/check_reports/url_checks.tsv" >> $GITHUB_OUTPUT
shell: bash

- name: Stop if failure
if: steps.check_results.outcome == 'failure'
run: exit 1

- name: Print out error variables
run: |
echo ${{ steps.check-report.outputs.error_url }}
echo ${{ steps.check-report.outputs.error_num }}

# Commit file
- name: Commit spell check file
if: ${{ steps.check-report.outputs.error_num >= 1 }}
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
git add --force check_reports/url_checks.tsv
git commit -m 'Add spell check file' || echo "No changes to commit"
git push --set-upstream origin preview-spell-error || echo echo branch exists remotely

- name: Find issues
id: find-issue
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
echo "$GITHUB_REPOSITORY"
curl -o find_issue.R https://raw.githubusercontent.com/ottrproject/ottr-reports/main/scripts/find_issue.R
issue_exists=$(Rscript --vanilla find_issue.R --repo $GITHUB_REPOSITORY --git_pat $GH_PAT)
echo URL issue exists: $issue_exists
echo "issue_existence=$issue_exists" >> $GITHUB_OUTPUT

- name: If too many URL errors, then make an issue
if: ${{ steps.check-report.outputs.error_num >= 1 && steps.find-issue.outputs.issue_existence == 0}}
uses: JasonEtco/create-an-issue@v2
with:
filename: .github/ISSUE_TEMPLATE/url-error.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_URL: ${{ steps.check-report.outputs.error_url }}
ERROR_NUM: ${{ steps.check-report.outputs.error_num }}

- name: If no URL errors than delete the branch we made
if: ${{ steps.check-report.outputs.error_num < 1 }}
run: |
git config --system --add safe.directory "$GITHUB_WORKSPACE"
git push origin --delete preview-spell-error || echo "No branch to delete"
2 changes: 1 addition & 1 deletion .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ jobs:
uses: actions/checkout@v4

- name: Verify Dockerfiles changed?
uses: tj-actions/verify-changed-files@v8.8
uses: tj-actions/verify-changed-files@v17
id: verify-changed-files
with:
files: |
201 changes: 90 additions & 111 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Candace Savonen Dec 2021
# Updated April 2023
# Candace Savonen 2021
# Updated May 2025

name: Pull Request

on:
@@ -30,144 +31,122 @@ jobs:
# Make the branch fresh
- name: Make the branch fresh
run: |
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
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
git push --set-upstream origin $branch_name || echo branch exists remotely
shell: bash



outputs:
public_repository: "${{ steps.public_repository.outputs.public }}"
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 }}"

########################## Make the error reports ##############################
spell-check:
name: Check spelling
needs: yaml-check
if: ${{needs.yaml-check.outputs.toggle_spell_check == 'yes'}}
uses: jhudsl/ottr-reports/.github/workflows/report-maker.yml@main
with:
check_type: spelling
error_min: 3
secrets:
gh_pat: ${{ secrets.GH_PAT }}

url-check:
name: Check URLs
ottr-reports:
name: Run Reports
needs: yaml-check
if: ${{needs.yaml-check.outputs.toggle_url_check == 'yes'}}
uses: jhudsl/ottr-reports/.github/workflows/report-maker.yml@main
with:
check_type: urls
error_min: 0
secrets:
gh_pat: ${{ secrets.GH_PAT }}
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

render-preview:
name: Render preview
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/course_template:main
if: ${{needs.yaml-check.outputs.toggle_render_preview == 'yes'}}
image: jhudsl/base_ottr:main

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

# Set up git checkout
- name: Set up git checkout
run: |
git config --system --add safe.directory $GITHUB_WORKSPACE
git config --local user.email "itcrtrainingnetwork@gmail.com"
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
- name: Run styler
run: Rscript -e "styler::style_file(list.files(pattern = '(R|q)md$', recursive = FALSE, full.names = TRUE));warnings()"

# We want a fresh run of the renders each time - so first delete old html files
- name: Delete old *.html
run: Rscript -e "rmarkdown::clean_site(preview = FALSE)"

# Now we want to render all the html files from the Rmd files
- name: Run render html
id: site
run: Rscript -e "rmarkdown::render_site()"

# We may have html files that we want to render to add as links on the pages -these will be stored in a dir called subdir_html
- name: Render subdir_html
id: subdir_html
run: Rscript -e "for (i in list.files(path = './subdir_html', pattern = 'Rmd$', recursive = TRUE, full.names = TRUE)){rmarkdown::render(i)}"

# 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.site.outcome != 'success'
- name: Commit styled files
run: |
echo site status ${{steps.site.outcome}}
exit 1
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"

# Commit the rendered website files
- name: Commit rendered website files to preview branch
id: commit
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git diff origin/main -- '*.html' >/dev/null && changes=true || changes=false
echo ::set-output name=changes::$changes
git add . --force
git commit -m 'Render preview' || echo "No changes to commit"
git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force || echo "No changes to commit"
shell: bash
############################# Readability Report ###################################

- 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
readability-report:
name: Readability report
needs: yaml-check
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_readability == 'true'}}

- name: Build components of the comment
id: build-components
run: |
course_name=$(head -n 1 _website.yml | cut -d'"' -f 2| tr " " "-")
website_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/index.html")
echo ::set-output name=website_link::$website_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 == 'true'
uses: peter-evans/create-or-update-comment@v1
steps:
- name: Checkout repo
uses: actions/checkout@v4
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 website here](${{ steps.build-components.outputs.website_link }})

_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
fetch-depth: 0

- name: No comment if no changes
if: steps.commit.outputs.changes == 'false'
uses: peter-evans/create-or-update-comment@v1
- name: Readability report
uses: Rebilly/lexi@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The latest commit did not produce rendering changes.
github-token: ${{ secrets.GH_PAT }}
glob: '**/*.md'

############################# Render Preview ###################################
render-preview:
name: Render preview
needs: yaml-check
runs-on: ubuntu-latest
if: ${{needs.yaml-check.outputs.toggle_render_preview == 'true'}}
permissions:
pull-requests: write
contents: write

_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace
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}}
Loading