@@ -71157,9 +71157,15 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
7115771157 const primaryKey = `${keyPrefix}-${fileHash}`;
7115871158 core.debug(`primary key is ${primaryKey}`);
7115971159 core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
71160- const cacheKey = (yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo, cacheDependencyPath))
71161- ? yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
71162- : yield cache.restoreCache(cachePaths, primaryKey);
71160+ const isManagedByYarn3 = yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo, cacheDependencyPath);
71161+ let cacheKey;
71162+ if (isManagedByYarn3) {
71163+ core.debug('All dependencies are managed locally by yarn3, the previous cache can be used');
71164+ cacheKey = yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix]);
71165+ }
71166+ else {
71167+ cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
71168+ }
7116371169 core.setOutput('cache-hit', Boolean(cacheKey));
7116471170 if (!cacheKey) {
7116571171 core.info(`${packageManager} cache is not found`);
@@ -71334,7 +71340,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
7133471340const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
7133571341 const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
7133671342 const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
71337- const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory);
71343+ const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
7133871344 core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
7133971345 return cacheFolderPath;
7134071346 })));
@@ -71380,14 +71386,43 @@ exports.getCacheDirectories = getCacheDirectories;
7138071386 */
7138171387const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () {
7138271388 const workDir = directory || process.env.GITHUB_WORKSPACE || '.';
71389+ core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`);
7138371390 // if .yarn/cache directory exists the cache is managed by version control system
7138471391 const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache');
71385- if (fs_1.default.existsSync(yarnCacheFile) && fs_1.default.lstatSync(yarnCacheFile).isDirectory())
71392+ if (fs_1.default.existsSync(yarnCacheFile) &&
71393+ fs_1.default.lstatSync(yarnCacheFile).isDirectory()) {
71394+ core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`);
7138671395 return Promise.resolve(false);
71396+ }
7138771397 // NOTE: yarn1 returns 'undefined' with rc = 0
7138871398 const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir);
71399+ core.debug(` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${enableGlobalCache.trim() === 'false'}
71400+ ${enableGlobalCache.length} ${enableGlobalCache.length === 5}
71401+ '${enableGlobalCache[0]}'${enableGlobalCache[0] === 'f'}
71402+ '${enableGlobalCache[1]}'${enableGlobalCache[1] === 'a'}
71403+ '${enableGlobalCache[2]}'${enableGlobalCache[2] === 'l'}
71404+ '${enableGlobalCache[3]}'${enableGlobalCache[3] === 's'}
71405+ '${enableGlobalCache[5]}
71406+ '${enableGlobalCache[6]}
71407+ '${enableGlobalCache[7]}
71408+ '${enableGlobalCache[8]}
71409+ '${enableGlobalCache[9]}
71410+ '${enableGlobalCache[10]}
71411+ '${enableGlobalCache[11]}
71412+ '${enableGlobalCache[12]}
71413+ '${enableGlobalCache[13]}
71414+ '${enableGlobalCache[14]}
71415+ `);
7138971416 // only local cache is not managed by yarn
71390- return enableGlobalCache === 'false';
71417+ const managed = enableGlobalCache.trim() === 'false';
71418+ if (managed) {
71419+ core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
71420+ return Promise.resolve(true);
71421+ }
71422+ else {
71423+ core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
71424+ return Promise.resolve(false);
71425+ }
7139171426});
7139271427/**
7139371428 * A function to report the repo contains Yarn managed projects
0 commit comments