Skip to content

Commit 71e53d3

Browse files
committed
Add debug info
1 parent 62a8f25 commit 71e53d3

File tree

4 files changed

+125
-17
lines changed

4 files changed

+125
-17
lines changed

dist/cache-save/index.js

Lines changed: 32 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,43 @@ 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'}
60608+
${enableGlobalCache.length} ${enableGlobalCache.length === 5}
60609+
'${enableGlobalCache[0]}'${enableGlobalCache[0] === 'f'}
60610+
'${enableGlobalCache[1]}'${enableGlobalCache[1] === 'a'}
60611+
'${enableGlobalCache[2]}'${enableGlobalCache[2] === 'l'}
60612+
'${enableGlobalCache[3]}'${enableGlobalCache[3] === 's'}
60613+
'${enableGlobalCache[5]}
60614+
'${enableGlobalCache[6]}
60615+
'${enableGlobalCache[7]}
60616+
'${enableGlobalCache[8]}
60617+
'${enableGlobalCache[9]}
60618+
'${enableGlobalCache[10]}
60619+
'${enableGlobalCache[11]}
60620+
'${enableGlobalCache[12]}
60621+
'${enableGlobalCache[13]}
60622+
'${enableGlobalCache[14]}
60623+
`);
6060360624
// only local cache is not managed by yarn
60604-
return enableGlobalCache === 'false';
60625+
const managed = enableGlobalCache.trim() === 'false';
60626+
if (managed) {
60627+
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
60628+
return Promise.resolve(true);
60629+
}
60630+
else {
60631+
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
60632+
return Promise.resolve(false);
60633+
}
6060560634
});
6060660635
/**
6060760636
* A function to report the repo contains Yarn managed projects

dist/setup/index.js

Lines changed: 41 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,43 @@ 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'}
71400+
${enableGlobalCache.length} ${enableGlobalCache.length === 5}
71401+
'${enableGlobalCache[0]}'${enableGlobalCache[0] === 'f'}
71402+
'${enableGlobalCache[1]}'${enableGlobalCache[1] === 'a'}
71403+
'${enableGlobalCache[2]}'${enableGlobalCache[2] === 'l'}
71404+
'${enableGlobalCache[3]}'${enableGlobalCache[3] === 's'}
71405+
'${enableGlobalCache[5]}
71406+
'${enableGlobalCache[6]}
71407+
'${enableGlobalCache[7]}
71408+
'${enableGlobalCache[8]}
71409+
'${enableGlobalCache[9]}
71410+
'${enableGlobalCache[10]}
71411+
'${enableGlobalCache[11]}
71412+
'${enableGlobalCache[12]}
71413+
'${enableGlobalCache[13]}
71414+
'${enableGlobalCache[14]}
71415+
`);
7138971416
// only local cache is not managed by yarn
71390-
return enableGlobalCache === 'false';
71417+
const managed = enableGlobalCache.trim() === 'false';
71418+
if (managed) {
71419+
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
71420+
return Promise.resolve(true);
71421+
}
71422+
else {
71423+
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
71424+
return Promise.resolve(false);
71425+
}
7139171426
});
7139271427
/**
7139371428
* 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: 41 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,55 @@ 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+
${enableGlobalCache.length} ${enableGlobalCache.length === 5}
261+
'${enableGlobalCache[0]}'${enableGlobalCache[0] === 'f'}
262+
'${enableGlobalCache[1]}'${enableGlobalCache[1] === 'a'}
263+
'${enableGlobalCache[2]}'${enableGlobalCache[2] === 'l'}
264+
'${enableGlobalCache[3]}'${enableGlobalCache[3] === 's'}
265+
'${enableGlobalCache[5]}
266+
'${enableGlobalCache[6]}
267+
'${enableGlobalCache[7]}
268+
'${enableGlobalCache[8]}
269+
'${enableGlobalCache[9]}
270+
'${enableGlobalCache[10]}
271+
'${enableGlobalCache[11]}
272+
'${enableGlobalCache[12]}
273+
'${enableGlobalCache[13]}
274+
'${enableGlobalCache[14]}
275+
`
276+
);
247277
// only local cache is not managed by yarn
248-
return enableGlobalCache === 'false';
278+
const managed = enableGlobalCache.trim() === 'false';
279+
if (managed) {
280+
core.debug(`"${workDir}" dependencies are managed by yarn 3 locally`);
281+
return Promise.resolve(true);
282+
} else {
283+
core.debug(`"${workDir}" dependencies are not managed by yarn 3 locally`);
284+
return Promise.resolve(false);
285+
}
249286
};
250287

251288
/**

0 commit comments

Comments
 (0)