Skip to content

Latest commit

 

History

History
86 lines (61 loc) · 8.93 KB

README.md

File metadata and controls

86 lines (61 loc) · 8.93 KB

Save action

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.

Documentation

Inputs

namedescriptiondefaultrequired

primary-key

  • When a non-empty string, the action uses this key for saving a cache.
  • Otherwise, the action fails.

true

nix

  • Can have an effect only when the action runs on a Linux or a macOS runner.
  • When true, the action can do Nix-specific things.
  • Otherwise, the action doesn't do them.

true

false

save

  • When true, the action can save a cache with the primary-key.
  • Otherwise, the action can't save a cache.

true

false

paths

  • When nix: true, the action uses ["/nix", "~/.cache/nix", "~root/.cache/nix"] as default paths, as suggested here. Otherwise, the action uses an empty list as default paths.
  • When a newline-separated non-empty list of non-empty path patterns (see @actions/glob for supported patterns), the action appends it to default paths and uses the resulting list for saving caches.
  • Otherwise, the action uses default paths for saving caches.

''

false

paths-macos

  • Overrides paths.
  • Can have an effect only when the action runs on a macOS runner.

''

false

paths-linux

  • Overrides paths.
  • Can have an effect only when the action runs on a Linux runner.

''

false

gc-max-store-size

  • Can have an effect only when nix: true, save: true.
  • When a number, the action collects garbage until Nix store size (in bytes) is at most this number just before the action tries to save a new cache.
  • Otherwise, this input has no effect.

''

false

gc-max-store-size-macos

  • Overrides gc-max-store-size.
  • Can have an effect only when the action runs on a macOS runner.

''

false

gc-max-store-size-linux

  • Overrides gc-max-store-size.
  • Can have an effect only when the action runs on a Linux runner.

''

false

purge

  • When true, the action purges (possibly zero) caches.
  • Otherwise, this input has no effect.

false

false

purge-primary-key

  • Can have an effect only when purge: true.
  • When always, the action always purges cache with the primary-key.
  • When never, the action never purges cache with the primary-key.
  • Otherwise, this input has no effect..

''

false

purge-prefixes

  • Can have an effect only when purge: true.
  • When a newline-separated non-empty list of non-empty cache key prefixes, the action selects for purging all caches whose keys match some of these prefixes and that are scoped to the current GITHUB_REF.
  • Otherwise, this input has no effect.

''

false

purge-last-accessed

  • Can have an effect only when purge: true.
  • When a number, the action purges selected caches that were last accessed more than this number of seconds ago relative to the start of the Post Restore phase.
  • Otherwise, this input has no effect.

''

false

purge-created

  • Can have an effect only when purge: true.
  • When a number, the action purges caches created more than this number of seconds ago relative to the start of the Post Restore phase.
  • Otherwise, this input has no effect.

''

false

upload-chunk-size

  • When a number, the action uses it as the chunk size (in bytes) to split up large files during upload.
  • Otherwise, the action uses the default value 33554432 (32MB).

''

false

token

The action uses it to communicate with GitHub API.

${{ github.token }}

false

Outputs

This action has no outputs.

Use cases

Only save cache

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@v3

  - 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') }}

Re-evaluate cache key while saving

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.

Restore a cache

uses: actions/cache/restore@v3
id: restore-cache
with:
    key: cache-${{ hashFiles('**/lockfiles') }}

Case 1 - Where a user would want to reuse the key as it is

uses: actions/cache/save@v3
with:
    key: ${{ steps.restore-cache.outputs.cache-primary-key }}

Case 2 - Where the user would want to re-evaluate the key

uses: actions/cache/save@v3
with:
    key: npm-cache-${{hashfiles(package-lock.json)}}

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.

steps:
  - uses: actions/checkout@v3
  .
  . // 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') }}