Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Node version to cache key #1172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('cache-restore', () => {
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
'Throw an error because %s is not supported',
async packageManager => {
await expect(restoreCache(packageManager, '')).rejects.toThrow(
await expect(restoreCache(packageManager, '', '')).rejects.toThrow(
`Caching for '${packageManager}' is not supported`
);
}
Expand All @@ -124,13 +124,13 @@ describe('cache-restore', () => {

describe('Restore dependencies', () => {
it.each([
['yarn', '2.1.2', yarnFileHash],
['yarn', '1.2.3', yarnFileHash],
['npm', '', npmFileHash],
['pnpm', '', pnpmFileHash]
['yarn', '2.1.2', yarnFileHash, '22'],
['yarn', '1.2.3', yarnFileHash, '20.17'],
['npm', '', npmFileHash, '22.12'],
['pnpm', '', pnpmFileHash, '18']
])(
'restored dependencies for %s',
async (packageManager, toolVersion, fileHash) => {
async (packageManager, toolVersion, fileHash, nodeVersion) => {
getCommandOutputSpy.mockImplementation((command: string) => {
if (command.includes('version')) {
return toolVersion;
Expand All @@ -139,10 +139,10 @@ describe('cache-restore', () => {
}
});

await restoreCache(packageManager, '');
await restoreCache(packageManager, '', nodeVersion);
expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
`Cache restored from key: node-cache-${platform}-${arch}-${nodeVersion}-${packageManager}-${fileHash}`
);
expect(infoSpy).not.toHaveBeenCalledWith(
`${packageManager} cache is not found`
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('cache-restore', () => {
});

restoreCacheSpy.mockImplementationOnce(() => undefined);
await restoreCache(packageManager, '');
await restoreCache(packageManager, '', '');
expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`${packageManager} cache is not found`
Expand Down
6 changes: 3 additions & 3 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93306,7 +93306,7 @@ const fs_1 = __importDefault(__nccwpck_require__(7147));
const os_1 = __importDefault(__nccwpck_require__(2037));
const constants_1 = __nccwpck_require__(9042);
const cache_utils_1 = __nccwpck_require__(1678);
const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const restoreCache = (packageManager, cacheDependencyPath, nodeVersion) => __awaiter(void 0, void 0, void 0, function* () {
const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager);
if (!packageManagerInfo) {
throw new Error(`Caching for '${packageManager}' is not supported`);
Expand All @@ -93322,7 +93322,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
}
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
const keyPrefix = `node-cache-${platform}-${arch}-${nodeVersion}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
Expand Down Expand Up @@ -94472,7 +94472,7 @@ function run() {
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) {
core.saveState(constants_1.State.CachePackageManager, cache);
const cacheDependencyPath = core.getInput('cache-dependency-path');
yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath);
yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath, version);
}
const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
Expand Down
5 changes: 3 additions & 2 deletions src/cache-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {

export const restoreCache = async (
packageManager: string,
cacheDependencyPath: string
cacheDependencyPath: string,
nodeVersion: string
) => {
const packageManagerInfo = await getPackageManagerInfo(packageManager);
if (!packageManagerInfo) {
Expand All @@ -40,7 +41,7 @@ export const restoreCache = async (
);
}

const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
const keyPrefix = `node-cache-${platform}-${arch}-${nodeVersion}-${packageManager}`;
const primaryKey = `${keyPrefix}-${fileHash}`;
core.debug(`primary key is ${primaryKey}`);

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function run() {
if (cache && isCacheFeatureAvailable()) {
core.saveState(State.CachePackageManager, cache);
const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(cache, cacheDependencyPath);
await restoreCache(cache, cacheDependencyPath, version);
}

const matchersPath = path.join(__dirname, '../..', '.github');
Expand Down