@@ -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,27 @@ 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'}`);
7138971400 // only local cache is not managed by yarn
71390- return enableGlobalCache === 'false';
71401+ const managed = enableGlobalCache.trim() === 'false';
71402+ if (managed) {
71403+ core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
71404+ return Promise.resolve(true);
71405+ }
71406+ else {
71407+ core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
71408+ return Promise.resolve(false);
71409+ }
7139171410});
7139271411/**
7139371412 * A function to report the repo contains Yarn managed projects
0 commit comments