mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
fix: cache key should include node version
This commit is contained in:
parent
969bd26639
commit
2792b3f52b
3 changed files with 12 additions and 8 deletions
|
@ -108,7 +108,7 @@ describe('cache-restore', () => {
|
||||||
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
|
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
|
||||||
'Throw an error because %s is not supported',
|
'Throw an error because %s is not supported',
|
||||||
async packageManager => {
|
async packageManager => {
|
||||||
await expect(restoreCache(packageManager)).rejects.toThrowError(
|
await expect(restoreCache('v16.17.1', packageManager)).rejects.toThrowError(
|
||||||
`Caching for '${packageManager}' is not supported`
|
`Caching for '${packageManager}' is not supported`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -132,10 +132,10 @@ describe('cache-restore', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await restoreCache(packageManager);
|
await restoreCache('v16.17.1', packageManager);
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
|
`Cache restored from key: node-cache-v16-${platform}-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
|
@ -163,7 +163,7 @@ describe('cache-restore', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
restoreCacheSpy.mockImplementationOnce(() => undefined);
|
restoreCacheSpy.mockImplementationOnce(() => undefined);
|
||||||
await restoreCache(packageManager);
|
await restoreCache('v16.17.1', packageManager);
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
} from './cache-utils';
|
} from './cache-utils';
|
||||||
|
|
||||||
export const restoreCache = async (
|
export const restoreCache = async (
|
||||||
|
nodeVersion: string,
|
||||||
packageManager: string,
|
packageManager: string,
|
||||||
cacheDependencyPath?: string
|
cacheDependencyPath?: string
|
||||||
) => {
|
) => {
|
||||||
|
@ -36,7 +37,8 @@ export const restoreCache = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
|
const nodeMajor = nodeVersion.split('.')[0];
|
||||||
|
const primaryKey = `node-cache-${nodeMajor}-${platform}-${packageManager}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
|
|
@ -40,14 +40,16 @@ export async function run() {
|
||||||
await installer.getNode(version, stable, checkLatest, auth, arch);
|
await installer.getNode(version, stable, checkLatest, auth, arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let installedVersion = version
|
||||||
// Output version of node is being used
|
// Output version of node is being used
|
||||||
try {
|
try {
|
||||||
const {stdout: installedVersion} = await exec.getExecOutput(
|
const {stdout} = await exec.getExecOutput(
|
||||||
'node',
|
'node',
|
||||||
['--version'],
|
['--version'],
|
||||||
{ignoreReturnCode: true, silent: true}
|
{ignoreReturnCode: true, silent: true}
|
||||||
);
|
);
|
||||||
core.setOutput('node-version', installedVersion.trim());
|
installedVersion = stdout.trim();
|
||||||
|
core.setOutput('node-version', installedVersion);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.setOutput('node-version', '');
|
core.setOutput('node-version', '');
|
||||||
}
|
}
|
||||||
|
@ -60,7 +62,7 @@ export async function run() {
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
await restoreCache(cache, cacheDependencyPath);
|
await restoreCache(cache, cacheDependencyPath, installedVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||||
|
|
Loading…
Add table
Reference in a new issue