review updates

This commit is contained in:
Sergey Dolin 2023-06-08 13:44:41 +02:00
parent b8b9502971
commit 6aacde798c
9 changed files with 222 additions and 245 deletions

View file

@ -134,3 +134,78 @@ jobs:
- name: Verify node and yarn - name: Verify node and yarn
run: __tests__/verify-node.sh "${{ matrix.node-version }}" run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash shell: bash
yarn-subprojects:
name: Test yarn subprojects
strategy:
matrix:
node-version: [12, 14, 16]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: prepare sub-projects
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: |
rm package.json
rm package-lock.json
echo "create yarn2 project in the sub2"
mkdir sub2
cd sub2
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 2.4.3
yarn install
echo "create yarn3 project in the sub3"
cd ..
mkdir sub3
cd sub3
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 3.5.1
yarn install
echo "create yarn1 project in the root"
cd ..
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 1.22.19
yarn install
# expect
# - no errors
# - log
# ##[debug]Cache Paths:
# ##[debug]["sub2/.yarn/cache","sub3/.yarn/cache","../../../.cache/yarn/v6"]
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache-dependency-path: |
**/*.lock
yarn.lock

View file

@ -1,81 +0,0 @@
# This is a basic workflow to help you get started with Actions
name: CI
on:
push:
workflow_dispatch:
jobs:
build:
strategy:
matrix:
node-version: [16]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: prepare sub-projects
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: |
echo "create yarn2 project in the sub2"
mkdir sub2
cd sub2
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 2.4.3
yarn install
echo "create yarn3 project in the sub3"
cd ..
mkdir sub3
cd sub3
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 3.5.1
yarn install
echo "create yarn1 project in the root"
cd ..
cat <<EOT >package.json
{
"name": "subproject",
"dependencies": {
"random": "^3.0.6",
"uuid": "^9.0.0"
}
}
EOT
yarn set version 1.22.19
yarn install
# expect
# - no errors
# - log
# ##[debug]Cache Paths:
# ##[debug]["sub2/.yarn/cache","sub3/.yarn/cache","../../../.cache/yarn/v6"]
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache-dependency-path: |
**/*.lock
yarn.lock

View file

@ -107,22 +107,20 @@ describe('run', () => {
describe('Validate unchanged cache is not saved', () => { describe('Validate unchanged cache is not saved', () => {
it('should not save cache for yarn1', async () => { it('should not save cache for yarn1', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation(() => yarnFileHash); getStateSpy.mockImplementation(key =>
getCommandOutputSpy key === State.CachePrimaryKey || key === State.CacheMatchedKey
.mockImplementationOnce(() => '1.2.3') ? yarnFileHash
.mockImplementationOnce(() => `${commonPath}/yarn1`); : key === State.CachePaths
? '["/foo/bar"]'
: 'not expected'
);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(2); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
'Consumed yarn version is 1.2.3 (working dir: "")'
);
expect(debugSpy).toHaveBeenCalledWith(
'yarn\'s cache folder "/some/random/path/yarn1" configured for the root directory'
);
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.` `Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
); );
@ -131,22 +129,28 @@ describe('run', () => {
it('should not save cache for yarn2', async () => { it('should not save cache for yarn2', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation(() => yarnFileHash); getStateSpy.mockImplementation(key =>
getCommandOutputSpy key === State.CachePrimaryKey || key === State.CacheMatchedKey
.mockImplementationOnce(() => '2.2.3') ? yarnFileHash
.mockImplementationOnce(() => `${commonPath}/yarn2`); : key === State.CachePaths
? '["/foo/bar"]'
: 'not expected'
);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(2); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0);
/*
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledWith(
'Consumed yarn version is 2.2.3 (working dir: "")' 'Consumed yarn version is 2.2.3 (working dir: "")'
); );
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledWith(
'yarn\'s cache folder "/some/random/path/yarn2" configured for the root directory' 'yarn\'s cache folder "/some/random/path/yarn2" configured for the root directory'
); );
*/
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.` `Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
); );
@ -155,39 +159,40 @@ describe('run', () => {
it('should not save cache for npm', async () => { it('should not save cache for npm', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation(() => npmFileHash); getStateSpy.mockImplementation(key =>
key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash
: key === State.CachePaths
? '["/foo/bar"]'
: 'not expected'
);
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`); getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`npm's cache folder "${commonPath}/npm" configured for the root directory`
);
expect(infoSpy).toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
);
expect(setFailedSpy).not.toHaveBeenCalled(); expect(setFailedSpy).not.toHaveBeenCalled();
}); });
it('should not save cache for pnpm', async () => { it('should not save cache for pnpm', async () => {
inputs['cache'] = 'pnpm'; inputs['cache'] = 'pnpm';
getStateSpy.mockImplementation(() => pnpmFileHash); getStateSpy.mockImplementation(key =>
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/pnpm`); key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash
: key === State.CachePaths
? '["/foo/bar"]'
: 'not expected'
);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`pnpm's cache folder "${commonPath}/pnpm" configured for the root directory`
);
expect(infoSpy).toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${pnpmFileHash}, not saving cache.`
);
expect(setFailedSpy).not.toHaveBeenCalled(); expect(setFailedSpy).not.toHaveBeenCalled();
}); });
}); });
@ -195,28 +200,22 @@ describe('run', () => {
describe('action saves the cache', () => { describe('action saves the cache', () => {
it('saves cache from yarn 1', async () => { it('saves cache from yarn 1', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return yarnFileHash; ? yarnFileHash
} else { : key === State.CachePrimaryKey
return npmFileHash; ? npmFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy : 'not expected'
.mockImplementationOnce(() => '1.2.3') );
.mockImplementationOnce(() => `${commonPath}/yarn1`);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(2); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
'Consumed yarn version is 1.2.3 (working dir: "")'
);
expect(debugSpy).toHaveBeenCalledWith(
'yarn\'s cache folder "/some/random/path/yarn1" configured for the root directory'
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.` `Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
); );
@ -229,28 +228,22 @@ describe('run', () => {
it('saves cache from yarn 2', async () => { it('saves cache from yarn 2', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return yarnFileHash; ? yarnFileHash
} else { : key === State.CachePrimaryKey
return npmFileHash; ? npmFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy : 'not expected'
.mockImplementationOnce(() => '2.2.3') );
.mockImplementationOnce(() => `${commonPath}/yarn2`);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(2); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
'Consumed yarn version is 2.2.3 (working dir: "")'
);
expect(debugSpy).toHaveBeenCalledWith(
'yarn\'s cache folder "/some/random/path/yarn2" configured for the root directory'
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.` `Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
); );
@ -263,23 +256,22 @@ describe('run', () => {
it('saves cache from npm', async () => { it('saves cache from npm', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return npmFileHash; ? npmFileHash
} else { : key === State.CachePrimaryKey
return yarnFileHash; ? yarnFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`); : 'not expected'
);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`npm's cache folder "${commonPath}/npm" configured for the root directory`
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.` `Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
); );
@ -292,23 +284,22 @@ describe('run', () => {
it('saves cache from pnpm', async () => { it('saves cache from pnpm', async () => {
inputs['cache'] = 'pnpm'; inputs['cache'] = 'pnpm';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return pnpmFileHash; ? pnpmFileHash
} else { : key === State.CachePrimaryKey
return npmFileHash; ? npmFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/pnpm`); : 'not expected'
);
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`pnpm's cache folder "${commonPath}/pnpm" configured for the root directory`
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${pnpmFileHash}, not saving cache.` `Cache hit occurred on the primary key ${pnpmFileHash}, not saving cache.`
); );
@ -321,14 +312,15 @@ describe('run', () => {
it('save with -1 cacheId , should not fail workflow', async () => { it('save with -1 cacheId , should not fail workflow', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return npmFileHash; ? npmFileHash
} else { : key === State.CachePrimaryKey
return yarnFileHash; ? yarnFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`); : 'not expected'
);
saveCacheSpy.mockImplementation(() => { saveCacheSpy.mockImplementation(() => {
return -1; return -1;
}); });
@ -336,11 +328,9 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`npm's cache folder "${commonPath}/npm" configured for the root directory`
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.` `Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
); );
@ -353,14 +343,15 @@ describe('run', () => {
it('saves with error from toolkit, should fail workflow', async () => { it('saves with error from toolkit, should fail workflow', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => { getStateSpy.mockImplementation((key: string) =>
if (name === State.CacheMatchedKey) { key === State.CacheMatchedKey
return npmFileHash; ? npmFileHash
} else { : key === State.CachePrimaryKey
return yarnFileHash; ? yarnFileHash
} : key === State.CachePaths
}); ? '["/foo/bar"]'
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`); : 'not expected'
);
saveCacheSpy.mockImplementation(() => { saveCacheSpy.mockImplementation(() => {
throw new cache.ValidationError('Validation failed'); throw new cache.ValidationError('Validation failed');
}); });
@ -368,11 +359,9 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2); expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledWith( expect(debugSpy).toHaveBeenCalledTimes(0);
`npm's cache folder "${commonPath}/npm" configured for the root directory`
);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.` `Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
); );

View file

@ -60370,16 +60370,16 @@ exports.run = run;
const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
const state = core.getState(constants_1.State.CacheMatchedKey); const state = core.getState(constants_1.State.CacheMatchedKey);
const primaryKey = core.getState(constants_1.State.CachePrimaryKey); const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
if (!packageManagerInfo) { if (!packageManagerInfo) {
core.debug(`Caching for '${packageManager}' is not supported`); core.debug(`Caching for '${packageManager}' is not supported`);
return; return;
} }
if (cachePaths.length === 0) {
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
// export declare function getInput(name: string, options?: InputOptions): string; // export declare function getInput(name: string, options?: InputOptions): string;
const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath);
if (cachePaths.length === 0) {
throw new Error(`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`); throw new Error(`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`);
} }
if (primaryKey === state) { if (primaryKey === state) {
@ -60524,19 +60524,18 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
} }
else { else {
const globber = yield glob.create(cacheDependencyPath); const globber = yield glob.create(cacheDependencyPath);
cacheDependenciesPaths = (yield globber.glob()) || ['']; cacheDependenciesPaths = yield globber.glob();
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths; exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
} }
const existingDirectories = cacheDependenciesPaths const existingDirectories = cacheDependenciesPaths
.map(path_1.default.dirname) .map(path_1.default.dirname)
.filter(path => path != null)
.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 // 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 // not he wanted, thus we should throw an error not trying to workaround with unexpected
// result to the whole build // result to the whole build
if (existingDirectories.length === 0) if (!existingDirectories.length)
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'); throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
return existingDirectories; return existingDirectories;
}); });
@ -60549,9 +60548,8 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
*/ */
const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath); const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => packageManagerInfo const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
.getCacheFolderPath(projectDirectory) const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory);
.then(cacheFolderPath => {
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`); core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
return cacheFolderPath; return cacheFolderPath;
}))); })));
@ -60622,6 +60620,7 @@ var State;
(function (State) { (function (State) {
State["CachePrimaryKey"] = "CACHE_KEY"; State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT"; State["CacheMatchedKey"] = "CACHE_RESULT";
State["CachePaths"] = "CACHE_PATHS";
})(State = exports.State || (exports.State = {})); })(State = exports.State || (exports.State = {}));
var Outputs; var Outputs;
(function (Outputs) { (function (Outputs) {

12
dist/setup/index.js vendored
View file

@ -71145,6 +71145,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
} }
const platform = process.env.RUNNER_OS; const platform = process.env.RUNNER_OS;
const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath); const cachePaths = yield cache_utils_1.getCacheDirectories(packageManagerInfo, cacheDependencyPath);
core.saveState(constants_1.State.CachePaths, cachePaths);
const lockFilePath = cacheDependencyPath const lockFilePath = cacheDependencyPath
? cacheDependencyPath ? cacheDependencyPath
: findLockFile(packageManagerInfo); : findLockFile(packageManagerInfo);
@ -71306,19 +71307,18 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
} }
else { else {
const globber = yield glob.create(cacheDependencyPath); const globber = yield glob.create(cacheDependencyPath);
cacheDependenciesPaths = (yield globber.glob()) || ['']; cacheDependenciesPaths = yield globber.glob();
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths; exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
} }
const existingDirectories = cacheDependenciesPaths const existingDirectories = cacheDependenciesPaths
.map(path_1.default.dirname) .map(path_1.default.dirname)
.filter(path => path != null)
.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 // 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 // not he wanted, thus we should throw an error not trying to workaround with unexpected
// result to the whole build // result to the whole build
if (existingDirectories.length === 0) if (!existingDirectories.length)
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'); throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
return existingDirectories; return existingDirectories;
}); });
@ -71331,9 +71331,8 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
*/ */
const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath); const projectDirectories = yield getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => packageManagerInfo const cacheFoldersPaths = yield Promise.all(projectDirectories.map((projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
.getCacheFolderPath(projectDirectory) const cacheFolderPath = packageManagerInfo.getCacheFolderPath(projectDirectory);
.then(cacheFolderPath => {
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`); core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
return cacheFolderPath; return cacheFolderPath;
}))); })));
@ -71404,6 +71403,7 @@ var State;
(function (State) { (function (State) {
State["CachePrimaryKey"] = "CACHE_KEY"; State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT"; State["CacheMatchedKey"] = "CACHE_RESULT";
State["CachePaths"] = "CACHE_PATHS";
})(State = exports.State || (exports.State = {})); })(State = exports.State || (exports.State = {}));
var Outputs; var Outputs;
(function (Outputs) { (function (Outputs) {

View file

@ -25,6 +25,7 @@ export const restoreCache = async (
packageManagerInfo, packageManagerInfo,
cacheDependencyPath cacheDependencyPath
); );
core.saveState(State.CachePaths, cachePaths);
const lockFilePath = cacheDependencyPath const lockFilePath = cacheDependencyPath
? cacheDependencyPath ? cacheDependencyPath
: findLockFile(packageManagerInfo); : findLockFile(packageManagerInfo);

View file

@ -1,7 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import {State} from './constants'; 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 // 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 // @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 cachePackages = async (packageManager: string) => {
const state = core.getState(State.CacheMatchedKey); const state = core.getState(State.CacheMatchedKey);
const primaryKey = core.getState(State.CachePrimaryKey); const primaryKey = core.getState(State.CachePrimaryKey);
const cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]');
const packageManagerInfo = await getPackageManagerInfo(packageManager); const packageManagerInfo = await getPackageManagerInfo(packageManager);
if (!packageManagerInfo) { if (!packageManagerInfo) {
@ -30,15 +31,10 @@ const cachePackages = async (packageManager: string) => {
return; return;
} }
if (cachePaths.length === 0) {
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
// export declare function getInput(name: string, options?: InputOptions): string; // export declare function getInput(name: string, options?: InputOptions): string;
const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
const cachePaths = await getCacheDirectories(
packageManagerInfo,
cacheDependencyPath
);
if (cachePaths.length === 0) {
throw new Error( throw new Error(
`Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}` `Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`
); );

View file

@ -133,13 +133,12 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
cacheDependenciesPaths = memoized; cacheDependenciesPaths = memoized;
} else { } else {
const globber = await glob.create(cacheDependencyPath); const globber = await glob.create(cacheDependencyPath);
cacheDependenciesPaths = (await globber.glob()) || ['']; cacheDependenciesPaths = await globber.glob();
memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths; memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
} }
const existingDirectories: string[] = cacheDependenciesPaths const existingDirectories: string[] = cacheDependenciesPaths
.map(path.dirname) .map(path.dirname)
.filter(path => path != null)
.filter(unique()) .filter(unique())
.filter(fs.existsSync) .filter(fs.existsSync)
.filter(directory => fs.lstatSync(directory).isDirectory()); .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 // 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 // not he wanted, thus we should throw an error not trying to workaround with unexpected
// result to the whole build // result to the whole build
if (existingDirectories.length === 0) if (!existingDirectories.length)
throw Error( throw Error(
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"' 'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
); );
@ -170,16 +169,14 @@ const getCacheDirectoriesFromCacheDependencyPath = async (
cacheDependencyPath cacheDependencyPath
); );
const cacheFoldersPaths = await Promise.all( const cacheFoldersPaths = await Promise.all(
projectDirectories.map(projectDirectory => projectDirectories.map(async projectDirectory => {
packageManagerInfo const cacheFolderPath =
.getCacheFolderPath(projectDirectory) packageManagerInfo.getCacheFolderPath(projectDirectory);
.then(cacheFolderPath => {
core.debug( core.debug(
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"` `${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
); );
return cacheFolderPath; return cacheFolderPath;
}) })
)
); );
// uniq in order to do not cache the same directories twice // uniq in order to do not cache the same directories twice
return cacheFoldersPaths.filter(unique()); return cacheFoldersPaths.filter(unique());

View file

@ -6,7 +6,8 @@ export enum LockType {
export enum State { export enum State {
CachePrimaryKey = 'CACHE_KEY', CachePrimaryKey = 'CACHE_KEY',
CacheMatchedKey = 'CACHE_RESULT' CacheMatchedKey = 'CACHE_RESULT',
CachePaths = 'CACHE_PATHS'
} }
export enum Outputs { export enum Outputs {