Compare commits

...

5 commits

Author SHA1 Message Date
Nikolai Laevskii
8cd066d2e7 Update build 2023-09-25 16:34:23 +02:00
Nikolai Laevskii
fc5dc8bbe4 Update build 2023-09-25 16:02:26 +02:00
Nikolai Laevskii
8819aae165 Fix typo 2023-09-25 16:02:26 +02:00
Nikolai Laevskii
ba2f076a9c Update license 2023-09-25 16:02:26 +02:00
Nikolai Laevskii
d5f102c3e3 Update memoization to lodash implementation 2023-09-25 16:02:26 +02:00
7 changed files with 3131 additions and 1751 deletions

BIN
.licenses/npm/lodash.memoize.dep.yml generated Normal file

Binary file not shown.

View file

@ -6,8 +6,7 @@ import {
PackageManagerInfo,
isCacheFeatureAvailable,
supportedPackageManagers,
getCommandOutput,
resetProjectDirectoriesMemoized
getProjectDirectoriesFromCacheDependencyPath
} from '../src/cache-utils';
import fs from 'fs';
import * as cacheUtils from '../src/cache-utils';
@ -123,7 +122,7 @@ describe('cache-utils', () => {
MockGlobber.create(['/foo', '/bar'])
);
resetProjectDirectoriesMemoized();
getProjectDirectoriesFromCacheDependencyPath.cache.clear?.();
});
afterEach(() => {

1574
dist/cache-save/index.js vendored

File diff suppressed because it is too large Load diff

3198
dist/setup/index.js vendored

File diff suppressed because it is too large Load diff

42
package-lock.json generated
View file

@ -17,10 +17,12 @@
"@actions/http-client": "^1.0.11",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.4",
"lodash.memoize": "^4.1.2",
"semver": "^6.3.1"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/lodash.memoize": "^4.1.7",
"@types/node": "^16.11.25",
"@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
@ -1648,6 +1650,21 @@
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
"dev": true
},
"node_modules/@types/lodash": {
"version": "4.14.197",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.197.tgz",
"integrity": "sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==",
"dev": true
},
"node_modules/@types/lodash.memoize": {
"version": "4.1.7",
"resolved": "https://registry.npmjs.org/@types/lodash.memoize/-/lodash.memoize-4.1.7.tgz",
"integrity": "sha512-lGN7WeO4vO6sICVpf041Q7BX/9k1Y24Zo3FY0aUezr1QlKznpjzsDk3T3wvH8ofYzoK0QupN9TWcFAFZlyPwQQ==",
"dev": true,
"dependencies": {
"@types/lodash": "*"
}
},
"node_modules/@types/node": {
"version": "16.11.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.25.tgz",
@ -4972,6 +4989,11 @@
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"node_modules/lodash.memoize": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
"integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag=="
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
@ -7780,6 +7802,21 @@
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
"dev": true
},
"@types/lodash": {
"version": "4.14.197",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.197.tgz",
"integrity": "sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==",
"dev": true
},
"@types/lodash.memoize": {
"version": "4.1.7",
"resolved": "https://registry.npmjs.org/@types/lodash.memoize/-/lodash.memoize-4.1.7.tgz",
"integrity": "sha512-lGN7WeO4vO6sICVpf041Q7BX/9k1Y24Zo3FY0aUezr1QlKznpjzsDk3T3wvH8ofYzoK0QupN9TWcFAFZlyPwQQ==",
"dev": true,
"requires": {
"@types/lodash": "*"
}
},
"@types/node": {
"version": "16.11.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.25.tgz",
@ -10244,6 +10281,11 @@
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.memoize": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
"integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag=="
},
"lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",

View file

@ -33,10 +33,12 @@
"@actions/http-client": "^1.0.11",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.4",
"lodash.memoize": "^4.1.2",
"semver": "^6.3.1"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/lodash.memoize": "^4.1.7",
"@types/node": "^16.11.25",
"@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",

View file

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as cache from '@actions/cache';
import * as glob from '@actions/glob';
import memoize from 'lodash.memoize';
import path from 'path';
import fs from 'fs';
import {unique} from './util';
@ -111,50 +112,38 @@ export const getPackageManagerInfo = async (packageManager: string) => {
};
/**
* Expands (converts) the string input `cache-dependency-path` to list of directories that
* may be project roots
*
* getProjectDirectoriesFromCacheDependencyPath is called twice during `restoreCache`
* - first through `getCacheDirectories`
* - second from `repoHasYarn3ManagedCache`
*
* it contains expensive IO operation and thus should be memoized
*/
let projectDirectoriesMemoized: string[] | null = null;
/**
* unit test must reset memoized variables
*/
export const resetProjectDirectoriesMemoized = () =>
(projectDirectoriesMemoized = null);
/**
* Expands (converts) the string input `cache-dependency-path` to list of directories that
* may be project roots
* it contains expensive IO operation and thus should be memoized
*
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
* expected to be the result of `core.getInput('cache-dependency-path')`
* @return list of directories and possible
* @return list of directories
*/
const getProjectDirectoriesFromCacheDependencyPath = async (
cacheDependencyPath: string
): Promise<string[]> => {
if (projectDirectoriesMemoized !== null) {
return projectDirectoriesMemoized;
export const getProjectDirectoriesFromCacheDependencyPath = memoize(
async (cacheDependencyPath: string): Promise<string[]> => {
const globber = await glob.create(cacheDependencyPath);
const cacheDependenciesPaths = await globber.glob();
const existingDirectories: string[] = cacheDependenciesPaths
.map(path.dirname)
.filter(unique())
.map(dirName => fs.realpathSync(dirName))
.filter(directory => fs.lstatSync(directory).isDirectory());
if (!existingDirectories.length)
core.warning(
`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`
);
return existingDirectories;
}
const globber = await glob.create(cacheDependencyPath);
const cacheDependenciesPaths = await globber.glob();
const existingDirectories: string[] = cacheDependenciesPaths
.map(path.dirname)
.filter(unique())
.map(dirName => fs.realpathSync(dirName))
.filter(directory => fs.lstatSync(directory).isDirectory());
if (!existingDirectories.length)
core.warning(
`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`
);
projectDirectoriesMemoized = existingDirectories;
return existingDirectories;
};
);
/**
* Finds the cache directories configured for the repo if cache-dependency-path is not empty