Skip to content

Commit

Permalink
Add debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jun 26, 2023
1 parent 62a8f25 commit 22005da
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 17 deletions.
27 changes: 24 additions & 3 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})));
Expand Down Expand Up @@ -60594,14 +60594,35 @@ 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'}
${typeof enableGlobalCache}
${enableGlobalCache.length === 5}
${enableGlobalCache[0] === 'f'}
${enableGlobalCache[1] === 'a'}
${enableGlobalCache[2] === 'l'}
${enableGlobalCache[3] === 's'}
${enableGlobalCache[4] === 'e'}
`);
// 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
Expand Down
39 changes: 33 additions & 6 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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;
})));
Expand Down Expand Up @@ -71380,14 +71386,35 @@ 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'}
${typeof enableGlobalCache}
${enableGlobalCache.length === 5}
${enableGlobalCache[0] === 'f'}
${enableGlobalCache[1] === 'a'}
${enableGlobalCache[2] === 'l'}
${enableGlobalCache[3] === 's'}
${enableGlobalCache[4] === 'e'}
`);
// 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
Expand Down
15 changes: 11 additions & 4 deletions src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
37 changes: 33 additions & 4 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`
);
Expand Down Expand Up @@ -233,19 +234,47 @@ export const getCacheDirectories = async (
*/
const isCacheManagedByYarn3 = async (directory: string): Promise<boolean> => {
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'
}
${typeof enableGlobalCache}
${enableGlobalCache.length === 5}
${enableGlobalCache[0] === 'f'}
${enableGlobalCache[1] === 'a'}
${enableGlobalCache[2] === 'l'}
${enableGlobalCache[3] === 's'}
${enableGlobalCache[4] === 'e'}
`
);
// 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);
}
};

/**
Expand Down

0 comments on commit 22005da

Please sign in to comment.