Skip to content

Commit

Permalink
Merge pull request #187 from opencasestudies/repo-sync/OTTR_Template/…
Browse files Browse the repository at this point in the history
…default

🔄 Synced file(s) with jhudsl/OTTR_Template
  • Loading branch information
carriewright11 authored Sep 25, 2024
2 parents cbed8eb + d207dca commit 5234a25
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 141 deletions.
39 changes: 39 additions & 0 deletions .github/switch_sync_repo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env Rscript

# This script switches the repo entry for the yaml file to whatever is specified
# Written by Candace Savonen Jan 2022

if (!("optparse" %in% installed.packages())){
install.packages("optparse")
}

library(optparse)

option_list <- list(
optparse::make_option(
c("--repo"),
type = "character",
default = "jhudsl/OTTR_Template_Test",
help = "GitHub repository name, e.g. jhudsl/OTTR_Template_Test",
)
)

# Read the arguments passed
opt_parser <- optparse::OptionParser(option_list = option_list)
opt <- optparse::parse_args(opt_parser)

# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))

# Get test sync yaml path
sync_file_path <- file.path(root_dir, ".github", "test-sync.yml")

yaml_contents <- yaml::yaml.load_file(sync_file_path)

# Only keep first grouping
yaml_contents$group <- yaml_contents$group[[1]]

# Switch out repo
yaml_contents$group$repos <- opt$repo

yaml::write_yaml(yaml_contents, sync_file_path)
78 changes: 0 additions & 78 deletions .github/workflows/docker-build.yml

This file was deleted.

45 changes: 26 additions & 19 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Candace Savonen 2021
# Updated Jan 2023
# Updated May 2024

name: Pull Request

Expand All @@ -17,7 +17,6 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}

# Use the yaml-env-action action.
- name: Load environment from YAML
Expand All @@ -39,11 +38,12 @@ jobs:
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 echo branch exists remotely
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 }}"
toggle_style_code: "${{ env.STYLE_CODE }}"
toggle_url_check: "${{ env.URL_CHECKER }}"
Expand Down Expand Up @@ -101,13 +101,13 @@ jobs:
fetch-depth: 0

- name: Run styler
run: Rscript -e "styler::style_file(list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE));warnings()"
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 \*.Rmd
git commit -m 'Style Rmds' || echo "No changes to commit"
git add \*md
git commit -m 'Style *mds' || echo "No changes to commit"
git push origin || echo "No changes to commit"
############################# Render Preview ###################################
Expand Down Expand Up @@ -142,23 +142,32 @@ jobs:
# Run bookdown rendering
- name: Run bookdown render
id: bookdown
if: ${{needs.yaml-check.outputs.toggle_website == 'rmd' }}
run: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"

# Run TOC-less version
# Rendered content for Leanpub and Coursera is very similar.
# This job creates a shared scaffold for both.
- name: Run TOC-less version of render
id: tocless
run: Rscript -e "ottrpal::render_without_toc()"
# Run quarto rendering
- name: Render quarto version
id: quarto
if: ${{needs.yaml-check.outputs.toggle_website == 'quarto' }}
run: Rscript -e "quarto::quarto_render('.')"

# 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.tocless.outcome != 'success'
- name: Check on Rmd render steps
if: ${{needs.yaml-check.outputs.toggle_website == 'rmd' }}
run: |
echo Bookdown status ${{steps.bookdown.outcome}}
echo Toc-less status ${{steps.tocless.outcome}}
exit 1
if [${{steps.bookdown.outcome}} != 'success']; then
exit 1
fi
- name: Check on quarto render steps
if: ${{needs.yaml-check.outputs.toggle_website == 'quarto' }}
run: |
echo Quarto status ${{steps.quarto.outcome}}
if [${{steps.quarto.outcome}} != 'success']; then
exit 1
fi
- name: Website preview for download
run: zip website-preview.zip docs/* -r
Expand All @@ -172,7 +181,7 @@ jobs:
echo "changes=$changes" >> $GITHUB_OUTPUT
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 pull --rebase --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force || echo "No changes to commit"
shell: bash

Expand All @@ -189,12 +198,10 @@ jobs:
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")
tocless_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/no_toc/index.html")
docx_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/docs/$course_name.docx")
zip_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/website-preview.zip")
echo "zip_link=$zip_link" >> $GITHUB_OUTPUT
echo "bookdown_link=$bookdown_link" >> $GITHUB_OUTPUT
echo "tocless_link=$tocless_link" >> $GITHUB_OUTPUT
echo "docx_link=$docx_link" >> $GITHUB_OUTPUT
echo "time=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
pr-comment:
runs-on: ubuntu-latest
steps:
- uses: mshick/add-pr-comment@v1

- uses: mshick/add-pr-comment@v2
if: ${{ github.head_ref == 'repo-sync/OTTR_Template/default' }}
with:
message: |
Expand All @@ -30,6 +31,5 @@ jobs:
You may want to unenroll your repository from the sync GitHub actions by [filing a PR](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) on `OTTR_Template`
to delete [your repo name from this file](https://github.com/jhudsl/OTTR_Template/blob/main/.github/sync.yml) if this will continue to be the case.
repo-token: ${{ secrets.GH_PAT }}
repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub tokens
allow-repeats: false # This is the default
Loading

0 comments on commit 5234a25

Please sign in to comment.