mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 05:19:10 +08:00 
			
		
		
		
	Add fail-on-cache-miss option (#1036)
				
					
				
			* Add fail-on-cache-miss option * Small improvements * Changes after rebase * Update description * Only fail if no cache entry is found * Code review * Update readme * Add additional test case * Bump version + changelog * Update package-lock.json * Update Readme
This commit is contained in:
		@@ -7,6 +7,7 @@ The restore action, as the name suggest, restores a cache. It acts similar to th
 | 
			
		||||
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns.
 | 
			
		||||
* `key` - String used while saving cache for restoring the cache
 | 
			
		||||
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.
 | 
			
		||||
* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: false
 | 
			
		||||
 | 
			
		||||
## Outputs
 | 
			
		||||
 | 
			
		||||
@@ -95,7 +96,7 @@ steps:
 | 
			
		||||
 | 
			
		||||
### Exit workflow on cache miss
 | 
			
		||||
 | 
			
		||||
You can use the output of this action to exit the workflow on cache miss. This way you can restrict your workflow to only initiate the build when `cache-hit` occurs, in other words, cache with exact key is found.
 | 
			
		||||
You can use `fail-on-cache-miss: true` to exit the workflow on a cache miss. This way you can restrict your workflow to only initiate the build when a cache is matched. Also, if you want to fail if cache did not match primary key, additionally leave `restore-keys` empty!
 | 
			
		||||
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
@@ -106,10 +107,7 @@ steps:
 | 
			
		||||
    with:
 | 
			
		||||
      path: path/to/dependencies
 | 
			
		||||
      key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
 | 
			
		||||
 | 
			
		||||
  - name: Check cache hit
 | 
			
		||||
    if: steps.cache.outputs.cache-hit != 'true'
 | 
			
		||||
    run: exit 1
 | 
			
		||||
      fail-on-cache-miss: true
 | 
			
		||||
 | 
			
		||||
  - name: Build
 | 
			
		||||
    run: /build.sh
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,10 @@ inputs:
 | 
			
		||||
    description: 'An optional boolean when enabled, allows windows runners to restore caches that were saved on other platforms'
 | 
			
		||||
    default: 'false'
 | 
			
		||||
    required: false
 | 
			
		||||
  fail-on-cache-miss:
 | 
			
		||||
    description: 'Fail the workflow if cache entry is not found'
 | 
			
		||||
    default: 'false'
 | 
			
		||||
    required: false
 | 
			
		||||
outputs:
 | 
			
		||||
  cache-hit:
 | 
			
		||||
    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
			
		||||
@@ -27,4 +31,4 @@ runs:
 | 
			
		||||
  main: '../dist/restore-only/index.js'
 | 
			
		||||
branding:
 | 
			
		||||
  icon: 'archive'
 | 
			
		||||
  color: 'gray-dark'
 | 
			
		||||
  color: 'gray-dark'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user