Created
August 15, 2021 16:16
-
-
Save millerh1/68eec7daa06d649b2e80a6e91b0bd4c3 to your computer and use it in GitHub Desktop.
GitHub Actions for R-Shiny + renv + automatic system dependencies
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
getsysreqs()
package.renv
with CI/CD.sudo eval
tosudo -s eval
because I was getting an error referenced here.cat()
infront ofgetsysreqs::apt_get_install()
because, otherwise, the defaultprint()
would be used and there was a[1]
being captured in thesysreqs
variable.