Skip to content
Search

GitHub:Actions:actions/cache

lastmod 2022-12-06created 2022-12-062 edits

Cache dependencies and build outputs in GitHub Actions

hashFiles

Example with a single pattern

Matches any package-lock.json file in the repository.

hashFiles('**/package-lock.json')

Example with multiple patterns

Creates a hash for any package-lock.json and Gemfile.lock files in the repository.

hashFiles('**/package-lock.json', '**/Gemfile.lock')

Matching a cache key

In restore-keys you can specify a list of alternate restore keys to use when there is a cache miss. You can create multiple restore keys ordered from the most specific to the least specific. The action searches them in sequential order. When a restore-keys key doesn't match directly, the action searches for keys prefixed with the restore key. If there are multiple partial matches for a restore key, the action returns the most recently created cache.

Example

restore-keys: |
  npm-feature-${{ hashFiles('package-lock.json') }}
  npm-feature-
  npm-

The runner evaluates the expressions, which resolve to:

restore-keys: |
  npm-feature-d5ea0750
  npm-feature-
  npm-

The restore key npm-feature- matches any key that starts with the same string. For example, both keys npm-feature-fd3052de and npm-feature-a9b253ff match the restore key. The cache with the most recent creation date is used.

The keys in this example are searched in the following order.

  • npm-feature-d5ea0750 matches a specific hash.
  • npm-feature- matches cache keys prefixed with npm-feature-.
  • npm- matches any keys prefixed with npm-.

See also

Favorite site

author Zer0 sitemap