Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('cache-restore', () => {
] as const)(
'restored dependencies for %s',
async (packageManager, toolVersion, fileHash) => {
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
// Set workspace to the appropriate fixture folder
setWorkspaceFor(packageManager);
getCommandOutputSpy.mockImplementation((command: string) => {
Expand All @@ -150,12 +151,20 @@ describe('cache-restore', () => {
await restoreCache(packageManager, '');
expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
`Cache restored from key: ${expectedCacheKey}`
);
expect(infoSpy).not.toHaveBeenCalledWith(
`${packageManager} cache is not found`
);
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
expect(setOutputSpy).toHaveBeenCalledWith(
'cache-primary-key',
expectedCacheKey
);
expect(setOutputSpy).toHaveBeenCalledWith(
'cache-matched-key',
expectedCacheKey
);
}
);
});
Expand All @@ -169,6 +178,7 @@ describe('cache-restore', () => {
] as const)(
'dependencies are changed %s',
async (packageManager, toolVersion, fileHash) => {
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
// Set workspace to the appropriate fixture folder
setWorkspaceFor(packageManager);
getCommandOutputSpy.mockImplementation((command: string) => {
Expand All @@ -186,6 +196,14 @@ describe('cache-restore', () => {
`${packageManager} cache is not found`
);
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
expect(setOutputSpy).toHaveBeenCalledWith(
'cache-primary-key',
expectedCacheKey
);
expect(setOutputSpy).toHaveBeenCalledWith(
'cache-matched-key',
undefined
);
}
);
});
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
outputs:
cache-hit:
description: 'A boolean value to indicate if a cache was hit.'
cache-primary-key:
description: 'The key used for the cache.'
cache-matched-key:
description: 'The key used for the cache that resulted in a cache hit.'
Comment thread
gowridurgad marked this conversation as resolved.
Outdated
node-version:
description: 'The installed node version.'
runs:
Expand Down
3 changes: 3 additions & 0 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57021,6 +57021,7 @@ const restoreCache = async (packageManager, cacheDependencyPath) => {
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
core.setOutput('cache-primary-key', primaryKey);
const isManagedByYarnBerry = await (0, cache_utils_1.repoHasYarnBerryManagedDependencies)(packageManagerInfo, cacheDependencyPath);
let cacheKey;
if (isManagedByYarnBerry) {
Expand All @@ -57031,6 +57032,8 @@ const restoreCache = async (packageManager, cacheDependencyPath) => {
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
}
core.setOutput('cache-hit', Boolean(cacheKey));
core.setOutput('cache-matched-key', cacheKey);
core.debug(`cache-matched-key is ${cacheKey}`);
if (!cacheKey) {
core.info(`${packageManager} cache is not found`);
return;
Expand Down
3 changes: 3 additions & 0 deletions src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const restoreCache = async (
core.debug(`primary key is ${primaryKey}`);

core.saveState(State.CachePrimaryKey, primaryKey);
core.setOutput('cache-primary-key', primaryKey);

const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
packageManagerInfo,
Expand All @@ -61,6 +62,8 @@ export const restoreCache = async (
}

core.setOutput('cache-hit', Boolean(cacheKey));
core.setOutput('cache-matched-key', cacheKey);
core.debug(`cache-matched-key is ${cacheKey}`);
Comment thread
gowridurgad marked this conversation as resolved.

if (!cacheKey) {
core.info(`${packageManager} cache is not found`);
Expand Down
Loading