diff --git a/NEWS.md b/NEWS.md index 01c93dd6f..70ee3b614 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,12 @@ * Example check-like workflows now run on all pull requests, not only on pull requests against the `main` branch. +* `[setup-r-dependencies]` and `[setup-renv]` now do not use the + deprecated `save-always` parameter of `actions/cache`. + +* `[setup-renv]` now correctly accepts `bypass-cache: never`, as stated + in the documentation. + # `v2.10.1` (2024-08-08) * `[setup-r-dependencies]` now pins `quarto-dev/quarto-actions/setup` diff --git a/setup-r-dependencies/action.yaml b/setup-r-dependencies/action.yaml index e3d34dd5e..db72419c9 100644 --- a/setup-r-dependencies/action.yaml +++ b/setup-r-dependencies/action.yaml @@ -148,7 +148,7 @@ runs: working-directory: ${{ inputs.working-directory }} - name: R package cache - if: inputs.cache != 'false' + if: inputs.cache == 'true' uses: actions/cache@v4 with: path: | @@ -158,8 +158,19 @@ runs: !${{ env.R_LIBS_USER }}/_cache key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }} restore-keys: ${{ format('{0}-{1}-{2}-', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version) }} - # Used to save package installation on troublesome Actions - save-always: ${{ inputs.cache == 'always' }} + + - name: R package cache restore + id: cache-packages-restore + if: inputs.cache == 'always' + uses: actions/cache/restore@v4 + with: + path: | + ${{ env.R_LIBS_USER }}/* + renv/library + !${{ env.R_LIBS_USER }}/pak + !${{ env.R_LIBS_USER }}/_cache + key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }} + restore-keys: ${{ format('{0}-{1}-{2}-', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version) }} - name: Install dependencies run: | @@ -267,3 +278,14 @@ runs: if command -v /c/Rtools/bin/tar && /c/Rtools/bin/tar --version | grep -q 'tar (GNU tar) 1.30' then echo 'C:/Program Files/Git/usr/bin' >> $GITHUB_PATH fi + + - name: R package cache save + if: ${{ always() && steps.cache-packages-restore.outputs.cache-hit != 'true' && inputs.cache == 'always' }} + uses: actions/cache/save@v4 + with: + path: | + ${{ env.R_LIBS_USER }}/* + renv/library + !${{ env.R_LIBS_USER }}/pak + !${{ env.R_LIBS_USER }}/_cache + key: ${{ steps.cache-packages-restore.outputs.cache-primary-key }} diff --git a/setup-renv/README.md b/setup-renv/README.md index 563282919..aa125050f 100644 --- a/setup-renv/README.md +++ b/setup-renv/README.md @@ -17,9 +17,11 @@ Forwarded to must be an R expression. Note that you often need to quote it, see details below. - `cache-version` - default `1`. If you need to invalidate the existing cache pass any other number and a new cache will be used. -- `bypass-cache` - default `false`. To skip the use of the GitHub cache completely (such as for local testing), set to `true`. - If `"never"` is provided, the package cache will be saved even if the - workflow fails. +- `bypass-cache` - default `false`. Whether attempts to cache should be +completely skipped (for non GitHub testing). Set to `true` to skip. If +`"never"` is provided, the package cache will be saved even if the workflow +fails. (For historical reasons the `"always"` value is equivalent to +`"never"`.) - `working-directory` - default `'.'`. If the `renv.lock` file is not in the root directory of your repository. Example: diff --git a/setup-renv/action.yaml b/setup-renv/action.yaml index 426c5dda9..ecc5ebcf2 100644 --- a/setup-renv/action.yaml +++ b/setup-renv/action.yaml @@ -9,7 +9,12 @@ inputs: required: true default: 1 bypass-cache: - description: 'Whether attempts to cache should be completely skipped (for non GitHub testing). Set to `true` to skip. If `"always"` is provided, the package cache will be saved even if the workflow fails.' + description: | + Whether attempts to cache should be completely skipped (for non + GitHub testing). Set to `true` to skip. If `"never"` is provided, + the package cache will be saved even if the workflow fails. + (For historical reasons the `"always"` value is equivalent to + `"never"`.) default: "false" working-directory: description: 'Using the working-directory keyword, you can specify a subdirectory of the repo where `renv` should be run.' @@ -37,7 +42,7 @@ runs: shell: Rscript {0} - name: Restore Renv package cache - if: ${{ inputs.bypass-cache != 'true' }} + if: ${{ inputs.bypass-cache == 'false' }} uses: actions/cache@v4 with: path: | @@ -45,7 +50,17 @@ runs: renv/library key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-${{ hashFiles(format('{0}/renv.lock', inputs.working-directory)) }} restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}- - save-always: ${{ inputs.bypass-cache == 'never' }} + + - name: Restore Renv package cache + id: cache-packages-restore + if: ${{ inputs.bypass-cache == 'always' || inputs.bypass-cache == 'never' }} + uses: actions/cache/restore@v4 + with: + path: | + ${{ env.RENV_PATHS_ROOT }} + renv/library + key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-${{ hashFiles(format('{0}/renv.lock', inputs.working-directory)) }} + restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}- - name: Install renv dependencies run: renv::restore() @@ -58,3 +73,12 @@ runs: if command -v /c/Rtools/bin/tar && /c/Rtools/bin/tar --version | grep -q 'tar (GNU tar) 1.30' then echo 'C:/Program Files/Git/usr/bin' >> $GITHUB_PATH fi + + - name: Save Renv package cache + if: ${{ always() && steps.cache-packages-restore.outputs.cache-hit != 'true' && (inputs.bypass-cache == 'always' || inputs.bypass-cache == 'never') }} + uses: actions/cache/save@v4 + with: + path: | + ${{ env.RENV_PATHS_ROOT }} + renv/library + key: ${{ steps.cache-packages-restore.outputs.cache-primary-key }}