Skip to content

Commit

Permalink
Use cache prefix if all sub-projects are yarn managed
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jun 22, 2023
1 parent 342f9b8 commit 62a8f25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
17 changes: 7 additions & 10 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60604,23 +60604,20 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false';
});
/**
* A function to report either the repo contains at least one Yarn managed directory
* A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const repoHasYarn3ManagedCache = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
if (packageManagerInfo.name !== 'yarn')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
return true;
}
}
return false;
const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
return isManagedList.every(Boolean);
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() {
Expand Down
19 changes: 8 additions & 11 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71157,7 +71157,7 @@ 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))
const cacheKey = (yield cache_utils_1.repoHasYarn3ManagedCache(packageManagerInfo, cacheDependencyPath))
? yield cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
: yield cache.restoreCache(cachePaths, primaryKey);
core.setOutput('cache-hit', Boolean(cacheKey));
Expand Down Expand Up @@ -71390,23 +71390,20 @@ const isCacheManagedByYarn3 = (directory) => __awaiter(void 0, void 0, void 0, f
return enableGlobalCache === 'false';
});
/**
* A function to report either the repo contains at least one Yarn managed directory
* A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/
const repoHasYarn3ManagedCache = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const repoHasYarn3ManagedCache = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
if (packageManagerInfo.name !== 'yarn')
return false;
const cacheDependencyPath = core.getInput('cache-dependency-path');
const yarnDirs = cacheDependencyPath
? yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];
for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (yield isCacheManagedByYarn3(dir)) {
return true;
}
}
return false;
const isManagedList = yield Promise.all(yarnDirs.map(isCacheManagedByYarn3));
return isManagedList.every(Boolean);
});
exports.repoHasYarn3ManagedCache = repoHasYarn3ManagedCache;
function isGhes() {
Expand Down
5 changes: 4 additions & 1 deletion src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const restoreCache = async (

core.saveState(State.CachePrimaryKey, primaryKey);

const cacheKey = (await repoHasYarn3ManagedCache(packageManagerInfo))
const cacheKey = (await repoHasYarn3ManagedCache(
packageManagerInfo,
cacheDependencyPath
))
? await cache.restoreCache(cachePaths, primaryKey, [keyPrefix])
: await cache.restoreCache(cachePaths, primaryKey);

Expand Down
19 changes: 8 additions & 11 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,28 +249,25 @@ const isCacheManagedByYarn3 = async (directory: string): Promise<boolean> => {
};

/**
* A function to report either the repo contains at least one Yarn managed directory
* A function to report the repo contains Yarn managed projects
* @param packageManagerInfo - used to make sure current package manager is yarn
* @return - true if there's at least one Yarn managed directory in the repo
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return - true if all project directories configured to be Yarn managed
*/
export const repoHasYarn3ManagedCache = async (
packageManagerInfo: PackageManagerInfo
packageManagerInfo: PackageManagerInfo,
cacheDependencyPath: string
): Promise<boolean> => {
if (packageManagerInfo.name !== 'yarn') return false;

const cacheDependencyPath = core.getInput('cache-dependency-path');

const yarnDirs = cacheDependencyPath
? await getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath)
: [''];

for (const dir of yarnDirs.length === 0 ? [''] : yarnDirs) {
if (await isCacheManagedByYarn3(dir)) {
return true;
}
}
const isManagedList = await Promise.all(yarnDirs.map(isCacheManagedByYarn3));

return false;
return isManagedList.every(Boolean);
};

export function isGhes(): boolean {
Expand Down

0 comments on commit 62a8f25

Please sign in to comment.