Use cache prefix if all sub-projects are yarn managed

This commit is contained in:
Sergey Dolin 2023-06-22 17:07:37 +02:00
parent 342f9b87ab
commit 62a8f25abf
4 changed files with 27 additions and 33 deletions

View file

@ -60604,23 +60604,20 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false'; return enableGlobalCache === 'false';
}); });
/** /**
* A function to report either the repo contains at least one Yarn managed directory * A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn * @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/ */
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { const repoHasYarn3ManagedCache = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
if (packageManagerInfo.name !== 'yarn') if (packageManagerInfo.name !== 'yarn')
return false; return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath) ? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: ['']; : [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) { const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
if (yield isCacheManagedByYarn3(dir)) { return isManagedList.every(Boolean);
return true;
}
}
return false;
}); });
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache; exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() { function isGhes() {

19
dist/setup/index.js vendored
View file

@ -71157,7 +71157,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
const primaryKey = `${keyPrefix}-${fileHash}`; const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`); core.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey); core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
const cacheKey = (yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo)) const cacheKey = (yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo, cacheDependencyPath))
? yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix]) ? yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
: yield cache.restoreCache(cachePaths, primaryKey); : yield cache.restoreCache(cachePaths, primaryKey);
core.setOutput('cache-hit', Boolean(cacheKey)); core.setOutput('cache-hit', Boolean(cacheKey));
@ -71390,23 +71390,20 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false'; return enableGlobalCache === 'false';
}); });
/** /**
* A function to report either the repo contains at least one Yarn managed directory * A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn * @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/ */
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () { const repoHasYarn3ManagedCache = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
if (packageManagerInfo.name !== 'yarn') if (packageManagerInfo.name !== 'yarn')
return false; return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath) ? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: ['']; : [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) { const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
if (yield isCacheManagedByYarn3(dir)) { return isManagedList.every(Boolean);
return true;
}
}
return false;
}); });
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache; exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() { function isGhes() {

View file

@ -44,7 +44,10 @@ export const restoreCache = async (
core.saveState(State.CachePrimaryKey, primaryKey); core.saveState(State.CachePrimaryKey, primaryKey);
const cacheKey = (await repoHasYarn3ManagedCache(packageManagerInfo)) const cacheKey = (await repoHasYarn3ManagedCache(
packageManagerInfo,
cacheDependencyPath
))
? await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]) ? await cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
: await cache.restoreCache(cachePaths, primaryKey); : await cache.restoreCache(cachePaths, primaryKey);

View file

@ -249,28 +249,25 @@ const isCacheManagedByYarn3 = async (directory: string): Promise<boolean> => {
}; };
/** /**
* A function to report either the repo contains at least one Yarn managed directory * A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn * @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo * @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/ */
export const repoHasYarn3ManagedCache = async ( export const repoHasYarn3ManagedCache = async (
packageManagerInfo: PackageManagerInfo packageManagerInfo: PackageManagerInfo,
cacheDependencyPath: string
): Promise<boolean> => { ): Promise<boolean> => {
if (packageManagerInfo.name !== 'yarn') return false; if (packageManagerInfo.name !== 'yarn') return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath const yarnDirs = cacheDependencyPath
? await getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath) ? await getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: ['']; : [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) { const isManagedList = await Promise.all(yarnDirs.map(isCacheManagedByYarn3));
if (await isCacheManagedByYarn3(dir)) {
return true;
}
}
return false; return isManagedList.every(Boolean);
}; };
export function isGhes(): boolean { export function isGhes(): boolean {