Skip to content

Instantly share code, notes, and snippets.

@millerh1
Created August 15, 2021 16:16
Show Gist options
  • Save millerh1/68eec7daa06d649b2e80a6e91b0bd4c3 to your computer and use it in GitHub Desktop.
Save millerh1/68eec7daa06d649b2e80a6e91b0bd4c3 to your computer and use it in GitHub Desktop.
GitHub Actions for R-Shiny + renv + automatic system dependencies
env:
RENV_PATHS_ROOT: ~/.local/share/renv
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
config:
- {os: ubuntu-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}
- name: Install Sys dependencies
shell: bash {0}
run: |
Rscript -e "install.packages('remotes')" -e "remotes::install_github('mdneuzerling/getsysreqs')"
sysreqs=$(Rscript -e "cat(getsysreqs::apt_get_install('renv.lock', distribution = 'ubuntu', release = '20.04'))")
echo $sysreqs
sudo apt-get update
sudo -s eval "$sysreqs"
- name: Cache packages
uses: actions/cache@v1
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: |
${{ runner.os }}-renv-
- name: Restore packages
shell: Rscript {0}
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
options(repos = c(RSPM = "https://packagemanager.rstudio.com/all/latest"))
renv::restore()
- name: Run tests
shell: Rscript {0}
run: |
shiny::runTests(".", assert = TRUE)
@millerh1
Copy link
Author

This gist should probably be optimized. I'm not an expert on github actions but I suspect you could rewrite this so that you automatically substitute the correct OS version on line 33 in the getsysreqs::apt_get_install() call.

Other notes:

  1. This is largely adapted from this article by @mdneuzerling -- who developed the getsysreqs() package.
  2. It is also adapted from this article on renv with CI/CD.
  3. And finally, I found that I needed to change sudo eval to sudo -s eval because I was getting an error referenced here.
  4. I also had to add cat() infront of getsysreqs::apt_get_install() because, otherwise, the default print() would be used and there was a [1] being captured in the sysreqs variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment