The save action saves a cache. It works similarly to the cache
action except that it doesn't first do a restore. This action provides granular ability to save a cache without having to restore it, or to do a save at any stage of the workflow job -- not only in post phase.
name | description | required | default |
---|---|---|---|
primary-key |
|
true |
"" |
nix |
|
false |
true |
save |
|
false |
true |
paths |
|
false |
"" |
paths-macos |
|
false |
"" |
paths-linux |
|
false |
"" |
gc-max-store-size |
|
false |
"" |
gc-max-store-size-macos |
|
false |
"" |
gc-max-store-size-linux |
|
false |
"" |
purge |
|
false |
false |
purge-primary-key |
|
false |
"" |
purge-prefixes |
|
false |
"" |
purge-last-accessed |
|
false |
"" |
purge-created |
|
false |
"" |
upload-chunk-size |
|
false |
"" |
save-always |
Run the post step to save the cache even if another step before fails. |
false |
false |
token |
The action uses it to communicate with GitHub API. |
false |
${{ github.token }} |
This action has no outputs.
If you are using separate jobs for generating common artifacts and sharing them across jobs, this action will take care of your cache saving needs.
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: /install.sh
- name: Build artifacts
run: /build.sh
- uses: actions/cache/save@v3
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
With this save action, the key can now be re-evaluated while executing the action. This helps in cases where lockfiles are generated during the build.
Let's say we have a restore step that computes a key at runtime.
uses: actions/cache/restore@v3
id: restore-cache
with:
key: cache-${{ hashFiles('**/lockfiles') }}
uses: actions/cache/save@v3
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
uses: actions/cache/save@v3
with:
key: npm-cache-${{hashfiles(package-lock.json)}}
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.
steps:
- uses: actions/checkout@v4
.
. // restore if need be
.
- name: Build
run: /build.sh
- uses: actions/cache/save@v3
if: always() // or any other condition to invoke the save action
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}