mirror of
				https://github.com/actions/cache.git
				synced 2025-10-23 08:56:26 +08:00 
			
		
		
		
	Reverted custom asks implemented and added wrapper
This commit is contained in:
		
							
								
								
									
										55
									
								
								src/restoreImpl.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/restoreImpl.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| import * as cache from "@actions/cache"; | ||||
| import * as core from "@actions/core"; | ||||
|  | ||||
| import { Events, Inputs, State } from "./constants"; | ||||
| import * as utils from "./utils/actionUtils"; | ||||
|  | ||||
| async function run(): Promise<string | undefined> { | ||||
|     try { | ||||
|         if (!utils.isCacheFeatureAvailable()) { | ||||
|             utils.setCacheHitOutput(false); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // Validate inputs, this can cause task failure | ||||
|         if (!utils.isValidEvent()) { | ||||
|             utils.logWarning( | ||||
|                 `Event Validation Error: The event type ${ | ||||
|                     process.env[Events.Key] | ||||
|                 } is not supported because it's not tied to a branch or tag ref.` | ||||
|             ); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         const primaryKey = core.getInput(Inputs.Key, { required: true }); | ||||
|         core.saveState(State.CachePrimaryKey, primaryKey); | ||||
|  | ||||
|         const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys); | ||||
|         const cachePaths = utils.getInputAsArray(Inputs.Path, { | ||||
|             required: true | ||||
|         }); | ||||
|  | ||||
|         const cacheKey = await cache.restoreCache( | ||||
|             cachePaths, | ||||
|             primaryKey, | ||||
|             restoreKeys | ||||
|         ); | ||||
|  | ||||
|         if (!cacheKey) { | ||||
|             core.info( | ||||
|                 `Cache not found for input keys: ${[ | ||||
|                     primaryKey, | ||||
|                     ...restoreKeys | ||||
|                 ].join(", ")}` | ||||
|             ); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         return cacheKey; | ||||
|     } catch (error: unknown) { | ||||
|         core.setFailed((error as Error).message); | ||||
|     } | ||||
| } | ||||
|  | ||||
| export default run; | ||||
		Reference in New Issue
	
	Block a user