mirror of
				https://github.com/actions/cache.git
				synced 2025-10-30 22:10:55 +00:00 
			
		
		
		
	Renamed variables and added tests
This commit is contained in:
		
					parent
					
						
							
								d91f5bd2fd
							
						
					
				
			
			
				commit
				
					
						3d4af52c52
					
				
			
		
					 16 changed files with 810 additions and 988 deletions
				
			
		|  | @ -1,15 +1,14 @@ | |||
| export enum Inputs { | ||||
|     Key = "key", // Input from cache, restore, save action
 | ||||
|     Path = "path", // Input from cache, restore, save action
 | ||||
|     RestoreKeys = "restore-keys", // Input from cache, restore action
 | ||||
|     UploadChunkSize = "upload-chunk-size", // Input from cache, save action
 | ||||
|     RestoredKey = "restored-key" // Input from save action
 | ||||
|     Key = "key", // Input for cache, restore, save action
 | ||||
|     Path = "path", // Input for cache, restore, save action
 | ||||
|     RestoreKeys = "restore-keys", // Input for cache, restore action
 | ||||
|     UploadChunkSize = "upload-chunk-size" // Input for cache, save action
 | ||||
| } | ||||
| 
 | ||||
| export enum Outputs { | ||||
|     CacheHit = "cache-hit", // Output from cache, restore action
 | ||||
|     InputtedKey = "inputted-key", // Output from restore action
 | ||||
|     MatchedKey = "matched-key" // Output from restore action
 | ||||
|     CachePrimaryKey = "cache-primary-key", // Output from restore action
 | ||||
|     CacheRestoreKey = "cache-restore-key" // Output from restore action
 | ||||
| } | ||||
| 
 | ||||
| export enum State { | ||||
|  | @ -24,3 +23,8 @@ export enum Events { | |||
| } | ||||
| 
 | ||||
| export const RefKey = "GITHUB_REF"; | ||||
| 
 | ||||
| export const stateToOutputMap = new Map<string, string>([ | ||||
|     [State.CacheMatchedKey, Outputs.CacheRestoreKey], | ||||
|     [State.CachePrimaryKey, Outputs.CachePrimaryKey] | ||||
| ]); | ||||
|  |  | |||
|  | @ -25,11 +25,7 @@ async function restoreImpl( | |||
|         } | ||||
| 
 | ||||
|         const primaryKey = core.getInput(Inputs.Key, { required: true }); | ||||
|         stateProvider.setState( | ||||
|             State.CachePrimaryKey, | ||||
|             primaryKey, | ||||
|             Outputs.InputtedKey | ||||
|         ); | ||||
|         stateProvider.setState(State.CachePrimaryKey, primaryKey); | ||||
| 
 | ||||
|         const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys); | ||||
|         const cachePaths = utils.getInputAsArray(Inputs.Path, { | ||||
|  | @ -54,11 +50,7 @@ async function restoreImpl( | |||
|         } | ||||
| 
 | ||||
|         // Store the matched cache key in states
 | ||||
|         stateProvider.setState( | ||||
|             State.CacheMatchedKey, | ||||
|             cacheKey, | ||||
|             Outputs.MatchedKey | ||||
|         ); | ||||
|         stateProvider.setState(State.CacheMatchedKey, cacheKey); | ||||
| 
 | ||||
|         const isExactKeyMatch = utils.isExactKeyMatch( | ||||
|             core.getInput(Inputs.Key, { required: true }), | ||||
|  |  | |||
|  | @ -42,8 +42,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<void> { | |||
| 
 | ||||
|         // If matched restore key is same as primary key, then do not save cache
 | ||||
|         // NO-OP in case of SaveOnly action
 | ||||
|         const restoredKey = | ||||
|             stateProvider.getCacheState() || core.getInput(Inputs.RestoredKey); | ||||
|         const restoredKey = stateProvider.getCacheState(); | ||||
| 
 | ||||
|         if (utils.isExactKeyMatch(primaryKey, restoredKey)) { | ||||
|             core.info( | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| import * as core from "@actions/core"; | ||||
| 
 | ||||
| import { State } from "./constants"; | ||||
| import { State, stateToOutputMap } from "./constants"; | ||||
| 
 | ||||
| export interface IStateProvider { | ||||
|     setState(key: string, value: string, outputKey?: string): void; | ||||
|     setState(key: string, value: string): void; | ||||
|     getState(key: string): string; | ||||
| 
 | ||||
|     getCacheState(): string | undefined; | ||||
|  | @ -21,7 +21,7 @@ class StateProviderBase implements IStateProvider { | |||
|     } | ||||
| 
 | ||||
|     // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
 | ||||
|     setState = (key: string, value: string, outputKey?: string) => {}; | ||||
|     setState = (key: string, value: string) => {}; | ||||
| 
 | ||||
|     // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | ||||
|     getState = (key: string) => ""; | ||||
|  | @ -33,10 +33,8 @@ export class StateProvider extends StateProviderBase { | |||
| } | ||||
| 
 | ||||
| export class NullStateProvider extends StateProviderBase { | ||||
|     setState = (key: string, value: string, outputKey?: string) => { | ||||
|         if (outputKey) { | ||||
|             core.setOutput(outputKey, value); | ||||
|         } | ||||
|     setState = (key: string, value: string) => { | ||||
|         core.setOutput(stateToOutputMap.get(key) as string, value); | ||||
|     }; | ||||
|     // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | ||||
|     getState = (key: string) => ""; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue