Skip to content

Render README

Render README #690

# MIT License
# Copyright (c) 2021 Eli Lilly and Company
# Author: William Michael Landau (will.landau at gmail)
# Written with help from public domain (CC0 1.0 Universal) workflow files by Jim Hester:
# * https://github.com/r-lib/actions/blob/master/examples/check-full.yaml
# * https://github.com/r-lib/actions/blob/master/examples/blogdown.yaml
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
on:
schedule:
- cron: '0 0 * * *'
push:
branches: [main, master]
paths:
- data/ratings.csv
- data/theatres.csv
- README.Rmd
workflow_dispatch:
name: Render README
jobs:
readme-targets:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::rmarkdown
any::targets
any::here
any::data.table
any::lubridate
any::showtext
any::ggplot2
any::scales
any::ggtext
any::gganimate
any::patchwork
any::xml2
any::rvest
any::glue
any::svglite
any::gifski
any::tweenr
any::transformr
any::ragg
- name: Check if previous runs exists
id: runs-exist
run: git ls-remote --exit-code --heads origin targets-runs
continue-on-error: true
- name: Checkout previous run
if: steps.runs-exist.outcome == 'success'
uses: actions/checkout@v3
with:
ref: targets-runs
fetch-depth: 1
path: .targets-runs
- name: Restore output files from the previous run
if: steps.runs-exist.outcome == 'success'
run: |
for (dest in scan(".targets-runs/.targets-files", what = character())) {
source <- file.path(".targets-runs", dest)
if (!file.exists(dirname(dest))) dir.create(dirname(dest), recursive = TRUE)
if (file.exists(source)) file.rename(source, dest)
}
shell: Rscript {0}
- name: Run targets pipeline
run: rmarkdown::render('README.Rmd', output_options = list(html_preview = FALSE))
shell: Rscript {0}
- name: Commit results
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add media/* README.md data/*
git commit -m 'ci: re-build README.Rmd' || echo "No changes to commit"
git push origin || echo "No changes to commit"
- name: Identify files that the targets pipeline produced
run: git ls-files -mo > .targets-files
- name: Create the runs branch if it does not already exist
if: steps.runs-exist.outcome != 'success'
run: git checkout --orphan targets-runs
- name: Put the worktree in the runs branch if the latter already exists
if: steps.runs-exist.outcome == 'success'
run: |
rm -r .git
mv .targets-runs/.git .
rm -r .targets-runs
- name: Upload latest run
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
rm -rf .gitignore .github/workflows
git add --force --all
for file in $(git ls-files -mo)
do
git add --force $file
done
git commit -am "ci: targets workflow update"
git push origin targets-runs
- name: Prepare failure artifact
if: failure()
run: rm -rf .git .github .targets-files .targets-runs
- name: Post failure artifact
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: .