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';
});
/**
* 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
* @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')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
return true;
}
}
return false;
const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
return isManagedList.every(Boolean);
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
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}`;
core.debug(`primary key is ${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);
core.setOutput('cache-hit', Boolean(cacheKey));
@ -71390,23 +71390,20 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
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
* @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')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
return true;
}
}
return false;
const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
return isManagedList.every(Boolean);
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() {

View File

@ -44,7 +44,10 @@ export const restoreCache = async (
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);

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
* @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 (
packageManagerInfo: PackageManagerInfo
packageManagerInfo: PackageManagerInfo,
cacheDependencyPath: string
): Promise<boolean> => {
if (packageManagerInfo.name !== 'yarn') return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath
? await getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (await isCacheManagedByYarn3(dir)) {
return true;
}
}
const isManagedList = await Promise.all(yarnDirs.map(isCacheManagedByYarn3));
return false;
return isManagedList.every(Boolean);
};
export function isGhes(): boolean {