Skip to content

Commit 5c6f97e

Browse files
committed
Add debug info
1 parent 62a8f25 commit 5c6f97e

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

dist/cache-save/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60548,7 +60548,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
6054860548
const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
6054960549
const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
6055060550
const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
60551-
const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory);
60551+
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
6055260552
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
6055360553
return cacheFolderPath;
6055460554
})));
@@ -60594,14 +60594,27 @@ exports.getCacheDirectories = getCacheDirectories;
6059460594
*/
6059560595
const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, function* () {
6059660596
const workDir = directory || process.env.GITHUB_WORKSPACE || '.';
60597+
core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`);
6059760598
// if .yarn/cache directory exists the cache is managed by version control system
6059860599
const yarnCacheFile = path_1.default.join(workDir, '.yarn', 'cache');
60599-
if (fs_1.default.existsSync(yarnCacheFile) && fs_1.default.lstatSync(yarnCacheFile).isDirectory())
60600+
if (fs_1.default.existsSync(yarnCacheFile) &&
60601+
fs_1.default.lstatSync(yarnCacheFile).isDirectory()) {
60602+
core.debug(`"${workDir}" has .yarn/cache - dependencies are kept in the repository`);
6060060603
return Promise.resolve(false);
60604+
}
6060160605
// NOTE: yarn1 returns 'undefined' with rc = 0
6060260606
const enableGlobalCache = yield exports.getCommandOutput('yarn config get enableGlobalCache', workDir);
60607+
core.debug(` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${enableGlobalCache.trim() === 'false'}`);
6060360608
// only local cache is not managed by yarn
60604-
return enableGlobalCache === 'false';
60609+
const managed = enableGlobalCache.trim() === 'false';
60610+
if (managed) {
60611+
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
60612+
return Promise.resolve(true);
60613+
}
60614+
else {
60615+
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
60616+
return Promise.resolve(false);
60617+
}
6060560618
});
6060660619
/**
6060760620
* A function to report the repo contains Yarn managed projects

dist/setup/index.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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) => __
7133471340
const 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
*/
7138171387
const 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

src/cache-restore.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ export const restoreCache = async (
4444

4545
core.saveState(State.CachePrimaryKey, primaryKey);
4646

47-
const cacheKey = (await repoHasYarn3ManagedCache(
47+
const isManagedByYarn3 = await repoHasYarn3ManagedCache(
4848
packageManagerInfo,
4949
cacheDependencyPath
50-
))
51-
? await cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
52-
: await cache.restoreCache(cachePaths, primaryKey);
50+
);
51+
let cacheKey: string | undefined;
52+
if (isManagedByYarn3) {
53+
core.debug(
54+
'All dependencies are managed locally by yarn3, the previous cache can be used'
55+
);
56+
cacheKey = await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]);
57+
} else {
58+
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
59+
}
5360

5461
core.setOutput('cache-hit', Boolean(cacheKey));
5562

src/cache-utils.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ const getCacheDirectoriesFromCacheDependencyPath = async (
171171
);
172172
const cacheFoldersPaths = await Promise.all(
173173
projectDirectories.map(async projectDirectory => {
174-
const cacheFolderPath =
175-
packageManagerInfo.getCacheFolderPath(projectDirectory);
174+
const cacheFolderPath = await packageManagerInfo.getCacheFolderPath(
175+
projectDirectory
176+
);
176177
core.debug(
177178
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
178179
);
@@ -233,19 +234,39 @@ export const getCacheDirectories = async (
233234
*/
234235
const isCacheManagedByYarn3 = async (directory: string): Promise<boolean> => {
235236
const workDir = directory || process.env.GITHUB_WORKSPACE || '.';
237+
core.debug(`check if "${workDir}" has locally managed yarn3 dependencies`);
236238

237239
// if .yarn/cache directory exists the cache is managed by version control system
238240
const yarnCacheFile = path.join(workDir, '.yarn', 'cache');
239-
if (fs.existsSync(yarnCacheFile) && fs.lstatSync(yarnCacheFile).isDirectory())
241+
if (
242+
fs.existsSync(yarnCacheFile) &&
243+
fs.lstatSync(yarnCacheFile).isDirectory()
244+
) {
245+
core.debug(
246+
`"${workDir}" has .yarn/cache - dependencies are kept in the repository`
247+
);
240248
return Promise.resolve(false);
249+
}
241250

242251
// NOTE: yarn1 returns 'undefined' with rc = 0
243252
const enableGlobalCache = await getCommandOutput(
244253
'yarn config get enableGlobalCache',
245254
workDir
246255
);
256+
core.debug(
257+
` ===> output "${enableGlobalCache}" ${enableGlobalCache === 'false'} ${
258+
enableGlobalCache.trim() === 'false'
259+
}`
260+
);
247261
// only local cache is not managed by yarn
248-
return enableGlobalCache === 'false';
262+
const managed = enableGlobalCache.trim() === 'false';
263+
if (managed) {
264+
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
265+
return Promise.resolve(true);
266+
} else {
267+
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
268+
return Promise.resolve(false);
269+
}
249270
};
250271

251272
/**

0 commit comments

Comments
 (0)