mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2024-11-26 03:50:56 -05:00
feat(cache): change key to match actions/cache documentation
Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
This commit is contained in:
parent
25316bbc1f
commit
117e7f56a1
3 changed files with 20 additions and 16 deletions
|
@ -135,10 +135,10 @@ 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}-${packageManager}-${fileHash}`
|
`Cache restored from key: ${platform}-setup-node-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -165,7 +165,7 @@ describe('cache-restore', () => {
|
||||||
await restoreCache(packageManager);
|
await restoreCache(packageManager);
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
9
dist/setup/index.js
vendored
9
dist/setup/index.js
vendored
|
@ -44663,6 +44663,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
|
||||||
}
|
}
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo, packageManager);
|
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo, packageManager);
|
||||||
|
const paths = [cachePath];
|
||||||
const lockFilePath = cacheDependencyPath
|
const lockFilePath = cacheDependencyPath
|
||||||
? cacheDependencyPath
|
? cacheDependencyPath
|
||||||
: findLockFile(packageManagerInfo);
|
: findLockFile(packageManagerInfo);
|
||||||
|
@ -44670,12 +44671,14 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
|
||||||
if (!fileHash) {
|
if (!fileHash) {
|
||||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
||||||
}
|
}
|
||||||
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
|
const keyPrefix = `${platform}-setup-node-`;
|
||||||
|
const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`;
|
||||||
|
const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix];
|
||||||
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);
|
||||||
const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
|
const cacheKey = yield cache.restoreCache(paths, primaryKey, restoreKeys);
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
core.info(`${packageManager} cache is not found`);
|
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
|
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
|
||||||
|
|
|
@ -3,8 +3,7 @@ import * as core from '@actions/core';
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import {State} from './constants';
|
||||||
import {State, Outputs} from './constants';
|
|
||||||
import {
|
import {
|
||||||
getCacheDirectoryPath,
|
getCacheDirectoryPath,
|
||||||
getPackageManagerInfo,
|
getPackageManagerInfo,
|
||||||
|
@ -25,6 +24,7 @@ export const restoreCache = async (
|
||||||
packageManagerInfo,
|
packageManagerInfo,
|
||||||
packageManager
|
packageManager
|
||||||
);
|
);
|
||||||
|
const paths = [cachePath];
|
||||||
const lockFilePath = cacheDependencyPath
|
const lockFilePath = cacheDependencyPath
|
||||||
? cacheDependencyPath
|
? cacheDependencyPath
|
||||||
: findLockFile(packageManagerInfo);
|
: findLockFile(packageManagerInfo);
|
||||||
|
@ -35,19 +35,20 @@ export const restoreCache = async (
|
||||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
'Some specified paths were not resolved, unable to cache dependencies.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const keyPrefix = `${platform}-setup-node-`;
|
||||||
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
|
const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`;
|
||||||
|
const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix];
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
const cacheKey = await cache.restoreCache(paths, primaryKey, restoreKeys);
|
||||||
const cacheKey = await cache.restoreCache([cachePath], primaryKey);
|
|
||||||
|
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
core.info(`${packageManager} cache is not found`);
|
core.info(
|
||||||
|
`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.saveState(State.CacheMatchedKey, cacheKey);
|
core.saveState(State.CacheMatchedKey, cacheKey);
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue