Support caching for mono repos and repositories with complex structure

This commit is contained in:
MaksimZhukov 2021-08-02 20:44:59 +03:00
parent aa759c6c94
commit 9f31dbbbc4
7 changed files with 727 additions and 674 deletions

View file

@ -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}`);