Render html #968
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It was adapted by Candace Savonen for the OTTR_template https://github.com/jhudsl/OTTR_Template. | |
# This code was adapted by Carrie Wright to enable automated rendering of the site associated with this repository | |
# +---------------- minute (0 - 59) | |
# | +------------- hour (0 - 23) | |
# | | +---------- day of month (1 - 31) | |
# | | | +------- month (1 - 12) | |
# | | | | +---- day of week (0 - 6) (Sunday=0 or 7) | |
# | | | | | | |
# * * * * * command to be executed | |
name: Render html | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 3 * * 0" | |
push: | |
branches: | |
- main | |
paths: | |
- '**.Rmd' | |
- collection.tsv | |
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/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_bookdown: "${{ env.RENDER_BOOKDOWN }}" | |
toggle_coursera: "${{ env.RENDER_COURSERA }}" | |
toggle_leanpub: "${{ env.RENDER_LEANPUB }}" | |
make_book_txt: "${{ env.MAKE_BOOK_TXT }}" | |
rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}" | |
toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" | |
build-collection: | |
name: Build Collection | |
needs: yaml-check | |
uses: ./.github/workflows/build-collection.yml | |
with: | |
render-type: 'main' | |
repository: $GITHUB_REPOSITORY | |
image-name: ${{needs.yaml-check.outputs.rendering_docker_image}} | |
secrets: | |
gh_pat: ${{ secrets.GH_PAT }} | |
render-main: | |
runs-on: ubuntu-latest | |
# install.packages("remotes") # in case we decide not to go with the container... | |
# remotes::install_cran("rmarkdown") | |
# remotes::install_deps(dependencies = TRUE) | |
needs: [yaml-check, build-collection] | |
container: | |
image: ${{needs.yaml-check.outputs.rendering_docker_image}} | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
# get the full repo | |
fetch-depth: 0 | |
# use github PAT | |
token: ${{ secrets.GH_PAT }} | |
# We want a fresh run of the renders each time | |
- name: Delete old docs/* | |
run: rm -rf docs/* | |
# Now we want to render Rmd -> html | |
- name: Convert Rmd to html | |
id: bookdown | |
run: | | |
Rscript scripts/build.R | |
# 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 "devtools::install_github('jhudsl/ottrpal', upgrade = 'never'); ottrpal::render_without_toc()" | |
env: | |
GITHUB_PAT: ${{ secrets.gh_pat }} | |
# Commit the rendered site files - html files and site_libs files | |
- name: Commit rendered site files | |
run: | | |
git config --global --add safe.directory ${GITHUB_WORKSPACE} | |
git config --local user.email "actions@github.com" | |
git config --local user.name "GitHub Actions" | |
git config --global pull.ff true | |
git add . --force | |
git commit -m 'Render site' || echo "No changes to commit" | |
git pull --allow-unrelated-histories --strategy-option=ours | |
git push origin main || echo "No changes to push" |