Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove save-always usage #934

Merged
merged 9 commits into from
Nov 6, 2024
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
28 changes: 25 additions & 3 deletions setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down Expand Up @@ -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 }}
8 changes: 5 additions & 3 deletions setup-renv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 27 additions & 3 deletions setup-renv/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -37,15 +42,25 @@ 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: |
${{ 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 }}-
save-always: ${{ inputs.bypass-cache == 'never' }}

- name: Restore Renv package cache
id: cache-packages-restore
if: ${{ inputs.bypass-cache == 'always' || inputs.bypass-cache == 'never' }}
gaborcsardi marked this conversation as resolved.
Show resolved Hide resolved
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()
Expand All @@ -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') }}
gaborcsardi marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/cache/save@v4
with:
path: |
${{ env.RENV_PATHS_ROOT }}
renv/library
key: ${{ steps.cache-packages-restore.outputs.cache-primary-key }}
Loading