@@ -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 isManagedByYarnBerry = yield cache_utils_1.repoHasYarnBerryManagedDependencies(packageManagerInfo, cacheDependencyPath);
71161+ let cacheKey;
71162+ if (isManagedByYarnBerry) {
71163+ core.info('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`);
@@ -71220,7 +71226,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7122071226 return (mod && mod.__esModule) ? mod : { "default": mod };
7122171227};
7122271228Object.defineProperty(exports, "__esModule", ({ value: true }));
71223- exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarn3ManagedCache = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
71229+ exports.isCacheFeatureAvailable = exports.isGhes = exports.repoHasYarnBerryManagedDependencies = exports.getCacheDirectories = exports.resetProjectDirectoriesMemoized = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
7122471230const core = __importStar(__nccwpck_require__(2186));
7122571231const exec = __importStar(__nccwpck_require__(1514));
7122671232const cache = __importStar(__nccwpck_require__(7799));
@@ -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 })));
@@ -71378,16 +71384,28 @@ exports.getCacheDirectories = getCacheDirectories;
7137871384 * - if local cache is not explicitly enabled (not yarn3), return false
7137971385 * - return true otherwise
7138071386 */
71381- const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () {
71387+ const projectHasYarnBerryManagedDependencies = (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);
71387- // NOTE: yarn1 returns 'undefined' with rc = 0
71396+ }
71397+ // NOTE: yarn1 returns 'undefined' with return code = 0
7138871398 const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir);
7138971399 // only local cache is not managed by yarn
71390- return enableGlobalCache === 'false';
71400+ const managed = enableGlobalCache.includes('false');
71401+ if (managed) {
71402+ core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
71403+ return true;
71404+ }
71405+ else {
71406+ core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
71407+ return false;
71408+ }
7139171409});
7139271410/**
7139371411 * A function to report the repo contains Yarn managed projects
@@ -71396,16 +71414,16 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
7139671414 * expected to be the result of `core.getInput('cache-dependency-path')`
7139771415 * @return - true if all project directories configured to be Yarn managed
7139871416 */
71399- const repoHasYarn3ManagedCache = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
71417+ const repoHasYarnBerryManagedDependencies = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
7140071418 if (packageManagerInfo.name !== 'yarn')
7140171419 return false;
7140271420 const yarnDirs = cacheDependencyPath
7140371421 ? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
7140471422 : [''];
71405- const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3 ));
71423+ const isManagedList = yield Promise.all(yarnDirs.map(projectHasYarnBerryManagedDependencies ));
7140671424 return isManagedList.every(Boolean);
7140771425});
71408- exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache ;
71426+ exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies ;
7140971427function isGhes() {
7141071428 const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
7141171429 return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
0 commit comments