Skip to content

Copy over from main template to _Quizzes repo #363

Copy over from main template to _Quizzes repo

Copy over from main template to _Quizzes repo #363

# This code was adapted from code written by Josh Shapiro
# for the Childhood Cancer Data Lab, an initiative of Alexs Lemonade Stand Foundation.
# https://github.com/AlexsLemonade/exercise-notebook-answers
# Adapted for this jhudsl repository by Candace Savonen Apr 2021
name: Copy over from main template to _Quizzes repo
on:
workflow_dispatch:
workflow_run:
workflows: [ "Render all output courses" ]
branches: [ main, staging ]
types:
- completed
jobs:
yaml-check:
name: Load user automation choices
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Use the yaml-env-action action.
- name: Load environment from YAML
uses: doughepi/[email protected]
with:
files: config_automation.yml # Pass a space-separated list of configuration files. Rightmost files take precedence.
outputs:
toggle_coursera: "${{ env.RENDER_COURSERA }}"
toggle_leanpub: "${{ env.RENDER_LEANPUB }}"
file-quizzes-pr:
name: File _Quizzes Transfer PR
runs-on: ubuntu-latest
container:
image: jhudsl/ottrpal:main
needs: [yaml-check]
if: ${{needs.yaml-check.outputs.toggle_coursera == 'yes' || needs.yaml-check.outputs.toggle_leanpub == 'yes'}}
steps:
- name: Checkout from Bookdown Repo
uses: actions/checkout@v4
with:
path: bookdown
token: ${{ secrets.GH_PAT }}
- name: Run git repo check
id: git_repo_check
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
# What's the Quizzes repository's name?
QUIZ_REPO=$(echo ${GITHUB_REPOSITORY} | sed "s/_Bookdown/ /g" | sed "s/_Template/ /g" | awk '{print $1"_Quizzes"}')
echo $QUIZ_REPO
# Run repo check script
curl -o git_repo_check.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/git_repo_check.R
results=$(Rscript --vanilla git_repo_check.R --repo "$GITHUB_REPOSITORY" --git_pat "$GH_PAT")
echo $QUIZ_REPO exists: $results
echo "git_results=$results" >> $GITHUB_OUTPUT
echo "leanpub_repo=$QUIZ_REPO" >> $GITHUB_OUTPUT
- name: Checkout code from Leanpub repo
if: ${{ steps.git_repo_check.outputs.git_results == 'TRUE' }}
uses: actions/checkout@v4
with:
path: quizzes
repository: ${{ steps.git_repo_check.outputs.leanpub_repo }}
token: ${{ secrets.GH_PAT }}
- name: Get files from Bookdown repo
if: ${{ steps.git_repo_check.outputs.git_results == 'TRUE' }}
shell: bash
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
# Copy over images folder (from bookdown to quizzes repo)
mkdir -p quizzes/resources/chapt_screen_images
cp bookdown/resources/chapt_screen_images/* quizzes/resources/chapt_screen_images
# Copy over _bookdown.yml (from bookdown to quizzes repo)
cp bookdown/_bookdown.yml quizzes/_bookdown.yml
- name: Create PR with resources files
if: ${{ steps.git_repo_check.outputs.git_results == 'TRUE' }}
uses: peter-evans/create-pull-request@v3
id: cpr
with:
path: quizzes # Must create the PR in the Quizzes Repo
token: ${{ secrets.GH_PAT }}
commit-message: Copy files from Bookdown repository
signoff: false
branch: auto_copy_rendered_files
delete-branch: true
title: 'GHA: Automated transfer of ottrpal-needed files from Bookdown repository'
body: |
### Description:
This PR was initiated by transfer-rendered.yml in the Bookdown repository.
It copies over the ottrpal-needed folder (for the `bookdown_to_embed_leanpub(render = FALSE)` function
to run properly.
- resources/chapt_screen_images/*
- _bookdown.yml
labels: |
automated
reviewers: $GITHUB_ACTOR
# Write out PR info
- name: Check outputs
if: ${{ steps.git_repo_check.outputs.git_results == 'TRUE' }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"