@@ -71157,9 +71157,15 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
71157
71157
const primaryKey = `${keyPrefix}-${fileHash}`;
71158
71158
core.debug(`primary key is ${primaryKey}`);
71159
71159
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
+ }
71163
71169
core.setOutput('cache-hit', Boolean(cacheKey));
71164
71170
if (!cacheKey) {
71165
71171
core.info(`${packageManager} cache is not found`);
@@ -71220,7 +71226,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
71220
71226
return (mod && mod.__esModule) ? mod : { "default": mod };
71221
71227
};
71222
71228
Object.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;
71224
71230
const core = __importStar(__nccwpck_require__(2186));
71225
71231
const exec = __importStar(__nccwpck_require__(1514));
71226
71232
const cache = __importStar(__nccwpck_require__(7799));
@@ -71334,7 +71340,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
71334
71340
const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
71335
71341
const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
71336
71342
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);
71338
71344
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
71339
71345
return cacheFolderPath;
71340
71346
})));
@@ -71378,16 +71384,28 @@ exports.getCacheDirectories = getCacheDirectories;
71378
71384
* - if local cache is not explicitly enabled (not yarn3), return false
71379
71385
* - return true otherwise
71380
71386
*/
71381
- const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () {
71387
+ const projectHasYarnBerryManagedDependencies = (directory) => __awaiter(void 0, void 0, void 0, function* () {
71382
71388
const workDir = directory || process.env.GITHUB_WORKSPACE || '.';
71389
+ core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`);
71383
71390
// if .yarn/cache directory exists the cache is managed by version control system
71384
71391
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`);
71386
71395
return Promise.resolve(false);
71387
- // NOTE: yarn1 returns 'undefined' with rc = 0
71396
+ }
71397
+ // NOTE: yarn1 returns 'undefined' with return code = 0
71388
71398
const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir);
71389
71399
// 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
+ }
71391
71409
});
71392
71410
/**
71393
71411
* 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
71396
71414
* expected to be the result of `core.getInput('cache-dependency-path')`
71397
71415
* @return - true if all project directories configured to be Yarn managed
71398
71416
*/
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* () {
71400
71418
if (packageManagerInfo.name !== 'yarn')
71401
71419
return false;
71402
71420
const yarnDirs = cacheDependencyPath
71403
71421
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
71404
71422
: [''];
71405
- const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3 ));
71423
+ const isManagedList = yield Promise.all(yarnDirs.map(projectHasYarnBerryManagedDependencies ));
71406
71424
return isManagedList.every(Boolean);
71407
71425
});
71408
- exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache ;
71426
+ exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies ;
71409
71427
function isGhes() {
71410
71428
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
71411
71429
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
0 commit comments