mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 16:14:00 +08:00 
			
		
		
		
	Support caching for mono repos and repositories with complex structure
This commit is contained in:
		| @@ -11,7 +11,10 @@ import { | ||||
|   PackageManagerInfo | ||||
| } from './cache-utils'; | ||||
|  | ||||
| export const restoreCache = async (packageManager: string) => { | ||||
| export const restoreCache = async ( | ||||
|   packageManager: string, | ||||
|   cacheDependencyPath?: string | ||||
| ) => { | ||||
|   const packageManagerInfo = await getPackageManagerInfo(packageManager); | ||||
|   if (!packageManagerInfo) { | ||||
|     throw new Error(`Caching for '${packageManager}' is not supported`); | ||||
| @@ -22,9 +25,17 @@ export const restoreCache = async (packageManager: string) => { | ||||
|     packageManagerInfo, | ||||
|     packageManager | ||||
|   ); | ||||
|   const lockFilePath = findLockFile(packageManagerInfo); | ||||
|   const lockFilePath = cacheDependencyPath | ||||
|     ? cacheDependencyPath | ||||
|     : findLockFile(packageManagerInfo); | ||||
|   const fileHash = await glob.hashFiles(lockFilePath); | ||||
|  | ||||
|   if (!fileHash) { | ||||
|     throw new Error( | ||||
|       'Some specified paths were not resolved, unable to cache dependencies.' | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`; | ||||
|   core.debug(`primary key is ${primaryKey}`); | ||||
|  | ||||
|   | ||||
| @@ -51,7 +51,8 @@ export async function run() { | ||||
|       if (isGhes()) { | ||||
|         throw new Error('Caching is not supported on GHES'); | ||||
|       } | ||||
|       await restoreCache(cache); | ||||
|       const cacheDependencyPath = core.getInput('cache-dependency-path'); | ||||
|       await restoreCache(cache, cacheDependencyPath); | ||||
|     } | ||||
|  | ||||
|     const matchersPath = path.join(__dirname, '../..', '.github'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MaksimZhukov
					MaksimZhukov