From 92f67a482915a145e9372ed84b9e7f13538ecc69 Mon Sep 17 00:00:00 2001 From: Manuel Roth Date: Fri, 22 Oct 2021 16:22:58 +0200 Subject: [PATCH] (R renv) Fix Renv package cache location in examples (#660) * (R renv) Fix Renv package cache location in examples * (R env) Update getting Renv package cache location * (R env) Set renv package cache location using RENV_PATHS_ROOT environment variable --- examples.md | 70 ++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/examples.md b/examples.md index 1f6ecef..14a677a 100644 --- a/examples.md +++ b/examples.md @@ -450,53 +450,35 @@ jobs: ## R - renv -For renv, the cache directory will vary by OS. Look at https://rstudio.github.io/renv/articles/renv.html#cache - -Locations: - -- Ubuntu: `~/.local/share/renv` -- macOS: `~/Library/Application Support/renv` -- Windows: `%LOCALAPPDATA%/renv` - -### Simple example +For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment variable is used to set the cache location. Have a look at https://rstudio.github.io/renv/reference/paths.html#details for more details. ```yaml -- uses: actions/cache@v2 +- name: Set RENV_PATHS_ROOT + shell: bash + run: | + echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV +- name: Install and activate renv + run: | + install.packages("renv") + renv::activate() + shell: Rscript {0} +- name: Get R and OS version + id: get-version + run: | + cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "") + cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "") + shell: Rscript {0} +- name: Get renv cache path + id: get-renv-cache-path + run: | + cat("##[set-output name=renv-cache-path;]", renv::paths$cache(), sep = "") + shell: Rscript {0} +- name: Restore Renv package cache + uses: actions/cache@v2 with: - path: ~/.local/share/renv - key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} - restore-keys: | - ${{ runner.os }}-renv- -``` - -Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu. - -### Multiple OS's in a workflow - -```yaml -- uses: actions/cache@v2 - if: startsWith(runner.os, 'Linux') - with: - path: ~/.local/share/renv - key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} - restore-keys: | - ${{ runner.os }}-renv- - -- uses: actions/cache@v2 - if: startsWith(runner.os, 'macOS') - with: - path: ~/Library/Application Support/renv - key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} - restore-keys: | - ${{ runner.os }}-renv- - -- uses: actions/cache@v2 - if: startsWith(runner.os, 'Windows') - with: - path: ~\AppData\Local\renv - key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} - restore-keys: | - ${{ runner.os }}-renv- + path: ${{ env.RENV_PATHS_ROOT }} + key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }} + restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}- ``` ## Ruby - Bundler