mirror of
https://github.com/actions/setup-node.git
synced 2025-06-30 14:43:48 +00:00
review updates
This commit is contained in:
parent
b8b9502971
commit
6aacde798c
9 changed files with 222 additions and 245 deletions
|
@ -25,6 +25,7 @@ export const restoreCache = async (
|
|||
packageManagerInfo,
|
||||
cacheDependencyPath
|
||||
);
|
||||
core.saveState(State.CachePaths, cachePaths);
|
||||
const lockFilePath = cacheDependencyPath
|
||||
? cacheDependencyPath
|
||||
: findLockFile(packageManagerInfo);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
import {State} from './constants';
|
||||
import {getCacheDirectories, getPackageManagerInfo} from './cache-utils';
|
||||
import {getPackageManagerInfo} from './cache-utils';
|
||||
|
||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
||||
|
@ -23,6 +23,7 @@ export async function run() {
|
|||
const cachePackages = async (packageManager: string) => {
|
||||
const state = core.getState(State.CacheMatchedKey);
|
||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
||||
const cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]');
|
||||
|
||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||
if (!packageManagerInfo) {
|
||||
|
@ -30,15 +31,10 @@ const cachePackages = async (packageManager: string) => {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
|
||||
// export declare function getInput(name: string, options?: InputOptions): string;
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
||||
const cachePaths = await getCacheDirectories(
|
||||
packageManagerInfo,
|
||||
cacheDependencyPath
|
||||
);
|
||||
|
||||
if (cachePaths.length === 0) {
|
||||
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
|
||||
// export declare function getInput(name: string, options?: InputOptions): string;
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
||||
throw new Error(
|
||||
`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`
|
||||
);
|
||||
|
|
|
@ -133,13 +133,12 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
|
|||
cacheDependenciesPaths = memoized;
|
||||
} else {
|
||||
const globber = await glob.create(cacheDependencyPath);
|
||||
cacheDependenciesPaths = (await globber.glob()) || [''];
|
||||
cacheDependenciesPaths = await globber.glob();
|
||||
memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
|
||||
}
|
||||
|
||||
const existingDirectories: string[] = cacheDependenciesPaths
|
||||
.map(path.dirname)
|
||||
.filter(path => path != null)
|
||||
.filter(unique())
|
||||
.filter(fs.existsSync)
|
||||
.filter(directory => fs.lstatSync(directory).isDirectory());
|
||||
|
@ -147,7 +146,7 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
|
|||
// 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 === 0)
|
||||
if (!existingDirectories.length)
|
||||
throw Error(
|
||||
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
|
||||
);
|
||||
|
@ -170,16 +169,14 @@ const getCacheDirectoriesFromCacheDependencyPath = async (
|
|||
cacheDependencyPath
|
||||
);
|
||||
const cacheFoldersPaths = await Promise.all(
|
||||
projectDirectories.map(projectDirectory =>
|
||||
packageManagerInfo
|
||||
.getCacheFolderPath(projectDirectory)
|
||||
.then(cacheFolderPath => {
|
||||
core.debug(
|
||||
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
|
||||
);
|
||||
return cacheFolderPath;
|
||||
})
|
||||
)
|
||||
projectDirectories.map(async projectDirectory => {
|
||||
const cacheFolderPath =
|
||||
packageManagerInfo.getCacheFolderPath(projectDirectory);
|
||||
core.debug(
|
||||
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
|
||||
);
|
||||
return cacheFolderPath;
|
||||
})
|
||||
);
|
||||
// uniq in order to do not cache the same directories twice
|
||||
return cacheFoldersPaths.filter(unique());
|
||||
|
|
|
@ -6,7 +6,8 @@ export enum LockType {
|
|||
|
||||
export enum State {
|
||||
CachePrimaryKey = 'CACHE_KEY',
|
||||
CacheMatchedKey = 'CACHE_RESULT'
|
||||
CacheMatchedKey = 'CACHE_RESULT',
|
||||
CachePaths = 'CACHE_PATHS'
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue