Do not ivalidate the cache entirely on lock file change (#744)

* Do not ivalidate the cache entirely on yarn3 lock file change

* Use cache prefix if all sub-projects are yarn managed

* Rename functions & add e2e tests
This commit is contained in:
Sergey Dolin 2023-06-27 13:07:43 +02:00 committed by GitHub
parent c6722d36aa
commit e33196f742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 358 additions and 16 deletions

View file

@ -8,6 +8,7 @@ import {State} from './constants';
import {
getCacheDirectories,
getPackageManagerInfo,
repoHasYarnBerryManagedDependencies,
PackageManagerInfo
} from './cache-utils';
@ -37,12 +38,26 @@ export const restoreCache = async (
);
}
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
const keyPrefix = `node-cache-${platform}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
core.saveState(State.CachePrimaryKey, primaryKey);
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
packageManagerInfo,
cacheDependencyPath
);
let cacheKey: string | undefined;
if (isManagedByYarnBerry) {
core.info(
'All dependencies are managed locally by yarn3, the previous cache can be used'
);
cacheKey = await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]);
} else {
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
}
core.setOutput('cache-hit', Boolean(cacheKey));
if (!cacheKey) {