mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-11-05 02:02:53 +01:00
Deprecate save-always
input (#1452)
The `save-always` input added in v4 is not working as intended due to `post-if` expressions not supporting the input context. To avoid breaking users who have already added this input to their workflows, it is being deprecated now and will be removed in the next major version (v5). See https://github.com/actions/cache/issues/1315 for more details.
This commit is contained in:
parent
f8a7ab490b
commit
c74ca4022c
4 changed files with 46 additions and 34 deletions
|
@ -17,7 +17,6 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
|||
### v4
|
||||
|
||||
* Updated to node 20
|
||||
* Added a `save-always` flag to save the cache even if a prior step fails
|
||||
|
||||
### v3
|
||||
|
||||
|
|
|
@ -29,7 +29,11 @@ inputs:
|
|||
save-always:
|
||||
description: 'Run the post step to save the cache even if another step before fails'
|
||||
default: 'false'
|
||||
required: false
|
||||
required: false
|
||||
deprecationMessage: |
|
||||
save-always does not work as intended and will be removed in a future release.
|
||||
A separate `actions/cache/restore` step should be used instead.
|
||||
See https://github.com/actions/cache/tree/main/save#always-save-cache for more details.
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
|
@ -37,7 +41,7 @@ runs:
|
|||
using: 'node20'
|
||||
main: 'dist/restore/index.js'
|
||||
post: 'dist/save/index.js'
|
||||
post-if: "success() || github.event.inputs.save-always"
|
||||
post-if: "success()"
|
||||
branding:
|
||||
icon: 'archive'
|
||||
color: 'gray-dark'
|
||||
|
|
|
@ -243,24 +243,7 @@ with:
|
|||
|
||||
### Saving cache even if the build fails
|
||||
|
||||
There can be cases where a cache should be saved even if the build job fails. For example, a job can fail due to flaky tests but the caches can still be re-used. You can use `actions/cache/save` action to save the cache by using `if: always()` condition.
|
||||
|
||||
Similarly, `actions/cache/save` action can be conditionally used based on the output of the previous steps. This way you get more control on when to save the cache.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
.
|
||||
. // restore if need be
|
||||
.
|
||||
- name: Build
|
||||
run: /build.sh
|
||||
- uses: actions/cache/save@v4
|
||||
if: always() // or any other condition to invoke the save action
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
||||
```
|
||||
See [Always save cache](./save/README.md#always-save-cache).
|
||||
|
||||
### Saving cache once and reusing in multiple workflows
|
||||
|
||||
|
|
|
@ -70,19 +70,45 @@ with:
|
|||
|
||||
### Always save cache
|
||||
|
||||
There are instances where some flaky test cases would fail the entire workflow and users would get frustrated because the builds would run for hours and the cache couldn't be saved as the workflow failed in between. For such use-cases, users now have the ability to use the `actions/cache/save` action to save the cache by using an `if: always()` condition. This way the cache will always be saved if generated, or a warning will be generated that nothing is found on the cache path. Users can also use the `if` condition to only execute the `actions/cache/save` action depending on the output of previous steps. This way they get more control of when to save the cache.
|
||||
There are instances where some flaky test cases would fail the entire workflow and users would get frustrated because the builds would run for hours and the cache couldn't be saved as the workflow failed in between.
|
||||
For such use-cases, users now have the ability to use the `actions/cache/save` action to save the cache by using an [`always()`](https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/expressions#always) condition.
|
||||
This way the cache will always be saved if generated, or a warning will be generated that nothing is found on the cache path. Users can also use the `if` condition to only execute the `actions/cache/save` action depending on the output of previous steps. This way they get more control of when to save the cache.
|
||||
|
||||
To avoid saving a cache that already exists, the `cache-hit` output from a restore step should be checked.
|
||||
|
||||
The `cache-primary-key` output from the restore step should also be used to ensure
|
||||
the cache key does not change during the build if it's calculated based on file contents.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
.
|
||||
. // restore if need be
|
||||
.
|
||||
- name: Build
|
||||
run: /build.sh
|
||||
- uses: actions/cache/save@v4
|
||||
if: always() // or any other condition to invoke the save action
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
||||
name: Always Caching Primes
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Restore cached Primes
|
||||
id: cache-primes-restore
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
key: ${{ runner.os }}-primes
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
|
||||
# Intermediate workflow steps
|
||||
|
||||
- name: Always Save Primes
|
||||
id: cache-primes-save
|
||||
if: always() && steps.cache-primes-restore.outputs.cache-hit != 'true'
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue