mirror of
https://github.com/actions/setup-node.git
synced 2026-07-08 10:38:22 +00:00
Add cache-primary-key and cache-matched-key as outputs (#1577)
* Add cache-primary-key and cache-matched-key as outputs * Refine cache output descriptions --------- Co-authored-by: gowridurgad <gowridurgad@gmail.com>
This commit is contained in:
@@ -137,6 +137,7 @@ describe('cache-restore', () => {
|
|||||||
] as const)(
|
] as const)(
|
||||||
'restored dependencies for %s',
|
'restored dependencies for %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
|
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
|
||||||
// Set workspace to the appropriate fixture folder
|
// Set workspace to the appropriate fixture folder
|
||||||
setWorkspaceFor(packageManager);
|
setWorkspaceFor(packageManager);
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
@@ -150,12 +151,20 @@ describe('cache-restore', () => {
|
|||||||
await restoreCache(packageManager, '');
|
await restoreCache(packageManager, '');
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
|
`Cache restored from key: ${expectedCacheKey}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
);
|
);
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-primary-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -169,6 +178,7 @@ describe('cache-restore', () => {
|
|||||||
] as const)(
|
] as const)(
|
||||||
'dependencies are changed %s',
|
'dependencies are changed %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
|
const expectedCacheKey = `node-cache-${platform}-${arch}-${packageManager}-${fileHash}`;
|
||||||
// Set workspace to the appropriate fixture folder
|
// Set workspace to the appropriate fixture folder
|
||||||
setWorkspaceFor(packageManager);
|
setWorkspaceFor(packageManager);
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
@@ -186,6 +196,14 @@ describe('cache-restore', () => {
|
|||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
);
|
);
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
|
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-primary-key',
|
||||||
|
expectedCacheKey
|
||||||
|
);
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'cache-matched-key',
|
||||||
|
undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ inputs:
|
|||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit.'
|
description: 'A boolean value to indicate if a cache was hit.'
|
||||||
|
cache-primary-key:
|
||||||
|
description: 'The key used to restore and save the cache.'
|
||||||
|
cache-matched-key:
|
||||||
|
description: 'The key of the cache that was restored. Empty when no cache is found.'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'The installed node version.'
|
description: 'The installed node version.'
|
||||||
runs:
|
runs:
|
||||||
|
|||||||
Vendored
+3
@@ -57021,6 +57021,7 @@ const restoreCache = async (packageManager, cacheDependencyPath) => {
|
|||||||
const primaryKey = `${keyPrefix}-${fileHash}`;
|
const primaryKey = `${keyPrefix}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||||
|
core.setOutput('cache-primary-key', primaryKey);
|
||||||
const isManagedByYarnBerry = await (0, cache_utils_1.repoHasYarnBerryManagedDependencies)(packageManagerInfo, cacheDependencyPath);
|
const isManagedByYarnBerry = await (0, cache_utils_1.repoHasYarnBerryManagedDependencies)(packageManagerInfo, cacheDependencyPath);
|
||||||
let cacheKey;
|
let cacheKey;
|
||||||
if (isManagedByYarnBerry) {
|
if (isManagedByYarnBerry) {
|
||||||
@@ -57031,6 +57032,8 @@ const restoreCache = async (packageManager, cacheDependencyPath) => {
|
|||||||
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
|
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
|
||||||
}
|
}
|
||||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||||
|
core.setOutput('cache-matched-key', cacheKey);
|
||||||
|
core.debug(`cache-matched-key is ${cacheKey}`);
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
core.info(`${packageManager} cache is not found`);
|
core.info(`${packageManager} cache is not found`);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export const restoreCache = async (
|
|||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
core.setOutput('cache-primary-key', primaryKey);
|
||||||
|
|
||||||
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
|
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
|
||||||
packageManagerInfo,
|
packageManagerInfo,
|
||||||
@@ -61,6 +62,8 @@ export const restoreCache = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||||
|
core.setOutput('cache-matched-key', cacheKey);
|
||||||
|
core.debug(`cache-matched-key is ${cacheKey}`);
|
||||||
|
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
core.info(`${packageManager} cache is not found`);
|
core.info(`${packageManager} cache is not found`);
|
||||||
|
|||||||
Reference in New Issue
Block a user