diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index adcf2d4b1..fed07dce9 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60548,7 +60548,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath); const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () { - const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory); + const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory); core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`); return cacheFolderPath; }))); @@ -60594,14 +60594,27 @@ exports.getCacheDirectories = getCacheDirectories; */ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () { const workDir = directory || process.env.GITHUB_WORKSPACE || '.'; + core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`); // if .yarn/cache directory exists the cache is managed by version control system const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache'); - if (fs_1.default.existsSync(yarnCacheFile) && fs_1.default.lstatSync(yarnCacheFile).isDirectory()) + if (fs_1.default.existsSync(yarnCacheFile) && + fs_1.default.lstatSync(yarnCacheFile).isDirectory()) { + core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`); return Promise.resolve(false); + } // NOTE: yarn1 returns 'undefined' with rc = 0 const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir); + core.debug(` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${enableGlobalCache.trim() === 'false'}`); // only local cache is not managed by yarn - return enableGlobalCache === 'false'; + const managed = enableGlobalCache.trim() === 'false'; + if (managed) { + core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`); + return Promise.resolve(true); + } + else { + core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`); + return Promise.resolve(false); + } }); /** * A function to report the repo contains Yarn managed projects diff --git a/dist/setup/index.js b/dist/setup/index.js index 0bbe9052f..4b3fcd45d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71157,9 +71157,15 @@ 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, cacheDependencyPath)) - ? yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix]) - : yield cache.restoreCache(cachePaths, primaryKey); + const isManagedByYarn3 = yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo, cacheDependencyPath); + let cacheKey; + if (isManagedByYarn3) { + core.debug('All dependencies are managed locally by yarn3, the previous cache can be used'); + cacheKey = yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix]); + } + else { + cacheKey = yield cache.restoreCache(cachePaths, primaryKey); + } core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { core.info(`${packageManager} cache is not found`); @@ -71334,7 +71340,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath); const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () { - const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory); + const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory); core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`); return cacheFolderPath; }))); @@ -71380,14 +71386,27 @@ exports.getCacheDirectories = getCacheDirectories; */ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () { const workDir = directory || process.env.GITHUB_WORKSPACE || '.'; + core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`); // if .yarn/cache directory exists the cache is managed by version control system const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache'); - if (fs_1.default.existsSync(yarnCacheFile) && fs_1.default.lstatSync(yarnCacheFile).isDirectory()) + if (fs_1.default.existsSync(yarnCacheFile) && + fs_1.default.lstatSync(yarnCacheFile).isDirectory()) { + core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`); return Promise.resolve(false); + } // NOTE: yarn1 returns 'undefined' with rc = 0 const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir); + core.debug(` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${enableGlobalCache.trim() === 'false'}`); // only local cache is not managed by yarn - return enableGlobalCache === 'false'; + const managed = enableGlobalCache.trim() === 'false'; + if (managed) { + core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`); + return Promise.resolve(true); + } + else { + core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`); + return Promise.resolve(false); + } }); /** * A function to report the repo contains Yarn managed projects diff --git a/src/cache-restore.ts b/src/cache-restore.ts index 3342ddc30..c215c762b 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -44,12 +44,19 @@ export const restoreCache = async ( core.saveState(State.CachePrimaryKey, primaryKey); - const cacheKey = (await repoHasYarn3ManagedCache( + const isManagedByYarn3 = await repoHasYarn3ManagedCache( packageManagerInfo, cacheDependencyPath - )) - ? await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]) - : await cache.restoreCache(cachePaths, primaryKey); + ); + let cacheKey: string | undefined; + if (isManagedByYarn3) { + core.debug( + 'All dependencies are managed locally by yarn3, the previous cache can be used' + ); + cacheKey = await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]); + } else { + cacheKey = await cache.restoreCache(cachePaths, primaryKey); + } core.setOutput('cache-hit', Boolean(cacheKey)); diff --git a/src/cache-utils.ts b/src/cache-utils.ts index c7f55670d..6d1f8b9c1 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -171,8 +171,9 @@ const getCacheDirectoriesFromCacheDependencyPath = async ( ); const cacheFoldersPaths = await Promise.all( projectDirectories.map(async projectDirectory => { - const cacheFolderPath = - packageManagerInfo.getCacheFolderPath(projectDirectory); + const cacheFolderPath = await packageManagerInfo.getCacheFolderPath( + projectDirectory + ); core.debug( `${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"` ); @@ -233,19 +234,39 @@ export const getCacheDirectories = async ( */ const isCacheManagedByYarn3 = async (directory: string): Promise => { const workDir = directory || process.env.GITHUB_WORKSPACE || '.'; + core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`); // if .yarn/cache directory exists the cache is managed by version control system const yarnCacheFile = path.join(workDir, '.yarn', 'cache'); - if (fs.existsSync(yarnCacheFile) && fs.lstatSync(yarnCacheFile).isDirectory()) + if ( + fs.existsSync(yarnCacheFile) && + fs.lstatSync(yarnCacheFile).isDirectory() + ) { + core.debug( + `"${workDir}" has .yarn/cache - dependencies are kept in the repository` + ); return Promise.resolve(false); + } // NOTE: yarn1 returns 'undefined' with rc = 0 const enableGlobalCache = await getCommandOutput( 'yarn config get enableGlobalCache', workDir ); + core.debug( + ` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${ + enableGlobalCache.trim() === 'false' + }` + ); // only local cache is not managed by yarn - return enableGlobalCache === 'false'; + const managed = enableGlobalCache.trim() === 'false'; + if (managed) { + core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`); + return Promise.resolve(true); + } else { + core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`); + return Promise.resolve(false); + } }; /**