mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
review updates second stage
This commit is contained in:
parent
6aacde798c
commit
3ef527264a
6 changed files with 25 additions and 83 deletions
|
@ -135,7 +135,7 @@ 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}-v2-${fileHash}`
|
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
|
|
|
@ -6,8 +6,7 @@ import {
|
||||||
PackageManagerInfo,
|
PackageManagerInfo,
|
||||||
isCacheFeatureAvailable,
|
isCacheFeatureAvailable,
|
||||||
supportedPackageManagers,
|
supportedPackageManagers,
|
||||||
getCommandOutput,
|
getCommandOutput
|
||||||
memoizedCacheDependencies
|
|
||||||
} from '../src/cache-utils';
|
} from '../src/cache-utils';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
import * as cacheUtils from '../src/cache-utils';
|
||||||
|
@ -104,10 +103,6 @@ describe('cache-utils', () => {
|
||||||
(pattern: string): Promise<Globber> =>
|
(pattern: string): Promise<Globber> =>
|
||||||
MockGlobber.create(['/foo', '/bar'])
|
MockGlobber.create(['/foo', '/bar'])
|
||||||
);
|
);
|
||||||
|
|
||||||
Object.keys(memoizedCacheDependencies).forEach(
|
|
||||||
key => delete memoizedCacheDependencies[key]
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -175,25 +170,23 @@ describe('cache-utils', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[supportedPackageManagers.npm, ''],
|
|
||||||
[supportedPackageManagers.npm, '/dir/file.lock'],
|
|
||||||
[supportedPackageManagers.npm, '/**/file.lock'],
|
|
||||||
[supportedPackageManagers.pnpm, ''],
|
|
||||||
[supportedPackageManagers.pnpm, '/dir/file.lock'],
|
|
||||||
[supportedPackageManagers.pnpm, '/**/file.lock'],
|
|
||||||
[supportedPackageManagers.yarn, ''],
|
|
||||||
[supportedPackageManagers.yarn, '/dir/file.lock'],
|
[supportedPackageManagers.yarn, '/dir/file.lock'],
|
||||||
[supportedPackageManagers.yarn, '/**/file.lock']
|
[supportedPackageManagers.yarn, '/**/file.lock']
|
||||||
])(
|
])(
|
||||||
'getCacheDirectoriesPaths should throw in case of having not directories',
|
'getCacheDirectoriesPaths should nothrow in case of having not directories',
|
||||||
async (packageManagerInfo, cacheDependency) => {
|
async (packageManagerInfo, cacheDependency) => {
|
||||||
lstatSpy.mockImplementation(arg => ({
|
lstatSpy.mockImplementation(arg => ({
|
||||||
isDirectory: () => false
|
isDirectory: () => false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await expect(
|
await cacheUtils.getCacheDirectories(
|
||||||
cacheUtils.getCacheDirectories(packageManagerInfo, cacheDependency)
|
packageManagerInfo,
|
||||||
).rejects.toThrow(); //'Could not get cache folder path for /dir');
|
cacheDependency
|
||||||
|
);
|
||||||
|
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
`No existing directories found containing cache-dependency-path="${cacheDependency}"`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
23
dist/cache-save/index.js
vendored
23
dist/cache-save/index.js
vendored
|
@ -60434,7 +60434,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.memoizedCacheDependencies = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const cache = __importStar(__nccwpck_require__(7799));
|
const cache = __importStar(__nccwpck_require__(7799));
|
||||||
|
@ -60503,11 +60503,6 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||||
/**
|
|
||||||
* glob expanding memoized because it involves potentially very deep
|
|
||||||
* traversing through the directories tree
|
|
||||||
*/
|
|
||||||
exports.memoizedCacheDependencies = {};
|
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
|
@ -60516,27 +60511,15 @@ exports.memoizedCacheDependencies = {};
|
||||||
* @return list of directories and possible
|
* @return list of directories and possible
|
||||||
*/
|
*/
|
||||||
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let cacheDependenciesPaths;
|
|
||||||
// memoize unglobbed paths to avoid traversing FS
|
|
||||||
const memoized = exports.memoizedCacheDependencies[cacheDependencyPath];
|
|
||||||
if (memoized) {
|
|
||||||
cacheDependenciesPaths = memoized;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const globber = yield glob.create(cacheDependencyPath);
|
const globber = yield glob.create(cacheDependencyPath);
|
||||||
cacheDependenciesPaths = yield globber.glob();
|
const cacheDependenciesPaths = yield globber.glob();
|
||||||
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
|
|
||||||
}
|
|
||||||
const existingDirectories = cacheDependenciesPaths
|
const existingDirectories = cacheDependenciesPaths
|
||||||
.map(path_1.default.dirname)
|
.map(path_1.default.dirname)
|
||||||
.filter(util_1.unique())
|
.filter(util_1.unique())
|
||||||
.filter(fs_1.default.existsSync)
|
.filter(fs_1.default.existsSync)
|
||||||
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
|
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
|
||||||
// if user explicitly pointed out some file, but it does not exist it is definitely
|
|
||||||
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
|
||||||
// result to the whole build
|
|
||||||
if (!existingDirectories.length)
|
if (!existingDirectories.length)
|
||||||
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`);
|
||||||
return existingDirectories;
|
return existingDirectories;
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
|
25
dist/setup/index.js
vendored
25
dist/setup/index.js
vendored
|
@ -71153,7 +71153,7 @@ const 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}-v2-${fileHash}`;
|
const primaryKey = `node-cache-${platform}-${packageManager}-${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);
|
||||||
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
|
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
|
||||||
|
@ -71217,7 +71217,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.memoizedCacheDependencies = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const cache = __importStar(__nccwpck_require__(7799));
|
const cache = __importStar(__nccwpck_require__(7799));
|
||||||
|
@ -71286,11 +71286,6 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||||
/**
|
|
||||||
* glob expanding memoized because it involves potentially very deep
|
|
||||||
* traversing through the directories tree
|
|
||||||
*/
|
|
||||||
exports.memoizedCacheDependencies = {};
|
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
|
@ -71299,27 +71294,15 @@ exports.memoizedCacheDependencies = {};
|
||||||
* @return list of directories and possible
|
* @return list of directories and possible
|
||||||
*/
|
*/
|
||||||
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let cacheDependenciesPaths;
|
|
||||||
// memoize unglobbed paths to avoid traversing FS
|
|
||||||
const memoized = exports.memoizedCacheDependencies[cacheDependencyPath];
|
|
||||||
if (memoized) {
|
|
||||||
cacheDependenciesPaths = memoized;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const globber = yield glob.create(cacheDependencyPath);
|
const globber = yield glob.create(cacheDependencyPath);
|
||||||
cacheDependenciesPaths = yield globber.glob();
|
const cacheDependenciesPaths = yield globber.glob();
|
||||||
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
|
|
||||||
}
|
|
||||||
const existingDirectories = cacheDependenciesPaths
|
const existingDirectories = cacheDependenciesPaths
|
||||||
.map(path_1.default.dirname)
|
.map(path_1.default.dirname)
|
||||||
.filter(util_1.unique())
|
.filter(util_1.unique())
|
||||||
.filter(fs_1.default.existsSync)
|
.filter(fs_1.default.existsSync)
|
||||||
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
|
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
|
||||||
// if user explicitly pointed out some file, but it does not exist it is definitely
|
|
||||||
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
|
||||||
// result to the whole build
|
|
||||||
if (!existingDirectories.length)
|
if (!existingDirectories.length)
|
||||||
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`);
|
||||||
return existingDirectories;
|
return existingDirectories;
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,7 @@ export const restoreCache = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKey = `node-cache-${platform}-${packageManager}-v2-${fileHash}`;
|
const primaryKey = `node-cache-${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);
|
||||||
|
|
|
@ -110,11 +110,6 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* glob expanding memoized because it involves potentially very deep
|
|
||||||
* traversing through the directories tree
|
|
||||||
*/
|
|
||||||
export const memoizedCacheDependencies: Record<string, string[]> = {};
|
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
|
@ -125,17 +120,8 @@ export const memoizedCacheDependencies: Record<string, string[]> = {};
|
||||||
const getProjectDirectoriesFromCacheDependencyPath = async (
|
const getProjectDirectoriesFromCacheDependencyPath = async (
|
||||||
cacheDependencyPath: string
|
cacheDependencyPath: string
|
||||||
): Promise<string[]> => {
|
): Promise<string[]> => {
|
||||||
let cacheDependenciesPaths: string[];
|
|
||||||
|
|
||||||
// memoize unglobbed paths to avoid traversing FS
|
|
||||||
const memoized = memoizedCacheDependencies[cacheDependencyPath];
|
|
||||||
if (memoized) {
|
|
||||||
cacheDependenciesPaths = memoized;
|
|
||||||
} else {
|
|
||||||
const globber = await glob.create(cacheDependencyPath);
|
const globber = await glob.create(cacheDependencyPath);
|
||||||
cacheDependenciesPaths = await globber.glob();
|
const cacheDependenciesPaths = await globber.glob();
|
||||||
memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingDirectories: string[] = cacheDependenciesPaths
|
const existingDirectories: string[] = cacheDependenciesPaths
|
||||||
.map(path.dirname)
|
.map(path.dirname)
|
||||||
|
@ -143,12 +129,9 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
|
||||||
.filter(fs.existsSync)
|
.filter(fs.existsSync)
|
||||||
.filter(directory => fs.lstatSync(directory).isDirectory());
|
.filter(directory => fs.lstatSync(directory).isDirectory());
|
||||||
|
|
||||||
// if user explicitly pointed out some file, but it does not exist it is definitely
|
|
||||||
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
|
||||||
// result to the whole build
|
|
||||||
if (!existingDirectories.length)
|
if (!existingDirectories.length)
|
||||||
throw Error(
|
core.warning(
|
||||||
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
|
`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`
|
||||||
);
|
);
|
||||||
|
|
||||||
return existingDirectories;
|
return existingDirectories;
|
||||||
|
|
Loading…
Add table
Reference in a new issue