mirror of
				https://github.com/Swatinem/rust-cache.git
				synced 2025-10-31 16:03:48 +00:00 
			
		
		
		
	restore from secondary branch
This commit is contained in:
		
							parent
							
								
									8c044fe7cc
								
							
						
					
					
						commit
						af6c167d5d
					
				| @ -52,6 +52,10 @@ inputs: | ||||
|     description: "Determines whether to cache incremental builds - speeding up builds for more disk usage. Defaults to false." | ||||
|     required: false | ||||
|     default: "false" | ||||
|   incremental-key: | ||||
|     description: "The key to use for incremental builds. Used on a per-branch basis" | ||||
|     required: false | ||||
|     default: ${{ github.ref }} | ||||
| outputs: | ||||
|   cache-hit: | ||||
|     description: "A boolean value that indicates an exact match was found." | ||||
|  | ||||
| @ -21,8 +21,16 @@ const HASH_LENGTH = 8; | ||||
| export class CacheConfig { | ||||
|   /** All the paths we want to cache */ | ||||
|   public cachePaths: Array<string> = []; | ||||
| 
 | ||||
|   /** All the paths we want to cache for incremental builds */ | ||||
|   public incrementalPaths: Array<string> = []; | ||||
| 
 | ||||
|   /** The primary cache key */ | ||||
|   public cacheKey = ""; | ||||
| 
 | ||||
|   /** The primary cache key for incremental builds */ | ||||
|   public incrementalKey = ""; | ||||
| 
 | ||||
|   /** | ||||
|    *  The secondary (restore) key that only contains the prefix and environment | ||||
|    *  This should be used if the primary cacheKey is not available - IE pulling from main on a branch | ||||
| @ -255,15 +263,16 @@ export class CacheConfig { | ||||
|     keyFiles.push(...parsedKeyFiles); | ||||
|     self.keyFiles = sort_and_uniq(keyFiles); | ||||
| 
 | ||||
|     // todo(jon): make sure we differentiate incrementals on different branches
 | ||||
|     // we can use just a single cache per incremental branch
 | ||||
|     if (self.incremental) { | ||||
|       key += `-incremental`; | ||||
|     } | ||||
| 
 | ||||
|     key += `-${lockHash}`; | ||||
|     self.cacheKey = key; | ||||
| 
 | ||||
|     if (self.incremental) { | ||||
|       // wire the incremental key to be just for this branch
 | ||||
|       const branchName = core.getInput("incremental-key") || "-shared"; | ||||
|       const incrementalKey = key + `-incremental` + branchName; | ||||
|       self.incrementalKey = incrementalKey; | ||||
|     } | ||||
| 
 | ||||
|     self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")]; | ||||
|     if (self.cacheBin) { | ||||
|       self.cachePaths = [ | ||||
| @ -286,7 +295,7 @@ export class CacheConfig { | ||||
|     if (self.incremental) { | ||||
|       if (cacheTargets === "true") { | ||||
|         for (const target of self.workspaces.map((ws) => ws.target)) { | ||||
|           self.cachePaths.push(path.join(target, "incremental")); | ||||
|           self.incrementalPaths.push(path.join(target, "incremental")); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
| @ -39,20 +39,24 @@ async function run() { | ||||
| 
 | ||||
|     core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`); | ||||
|     const key = config.cacheKey; | ||||
| 
 | ||||
|     // Pass a copy of cachePaths to avoid mutating the original array as reported by:
 | ||||
|     // https://github.com/actions/toolkit/pull/1378
 | ||||
|     // TODO: remove this once the underlying bug is fixed.
 | ||||
|     const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { | ||||
|       lookupOnly, | ||||
|     }); | ||||
|     const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly }); | ||||
| 
 | ||||
|     if (restoreKey) { | ||||
|       const match = restoreKey === key; | ||||
|       core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); | ||||
| 
 | ||||
|       if (config.incremental) { | ||||
|         core.debug("restoring incremental builds"); | ||||
|         for (const workspace of config.workspaces) { | ||||
|           await restoreIncremental(workspace.target); | ||||
|         const incrementalKey = await cacheProvider.cache.restoreCache(config.incrementalPaths.slice(), config.incrementalKey, [config.restoreKey], { lookupOnly }); | ||||
|         core.debug(`restoring incremental builds from ${incrementalKey}`); | ||||
| 
 | ||||
|         if (incrementalKey) { | ||||
|           for (const workspace of config.workspaces) { | ||||
|             await restoreIncremental(workspace.target); | ||||
|           } | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user