Skip to content

Commit 8170e22

Browse files
authored
Detect cached folders from multiple directories (#735)
* Add project-dir * Fix find lock file * Remove package-dir input * format & resolve conflicts * Add unit tests * build dist * Apply change request fixes * handle non-dir cache-dependency-path * bump cache version * run checks * Handle globs in cacheDependencyPath * refactor, introduce `cacheDependencyPathToProjectsDirectories` it is necessary for the next PR related yarn optimization * Changes requests * Apply fixes * review fixes * add e2e * Add unique * review updates * review updates second stage * Review fixes 3 * imporve e2e tests
1 parent 698d505 commit 8170e22

16 files changed

+3445
-1496
lines changed

.github/workflows/e2e-cache.yml

+27
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,30 @@ jobs:
134134
- name: Verify node and yarn
135135
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
136136
shell: bash
137+
138+
yarn-subprojects:
139+
name: Test yarn subprojects
140+
strategy:
141+
matrix:
142+
node-version: [12, 14, 16]
143+
runs-on: ubuntu-latest
144+
145+
steps:
146+
- uses: actions/checkout@v3
147+
148+
- name: prepare sub-projects
149+
run: __tests__/prepare-subprojects.sh
150+
151+
# expect
152+
# - no errors
153+
# - log
154+
# ##[debug]Cache Paths:
155+
# ##[debug]["sub2/.yarn/cache","sub3/.yarn/cache","../../../.cache/yarn/v6"]
156+
- name: Setup Node
157+
uses: ./
158+
with:
159+
node-version: ${{ matrix.node-version }}
160+
cache: 'yarn'
161+
cache-dependency-path: |
162+
**/*.lock
163+
yarn.lock

__tests__/authutil.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os from 'os';
2-
import * as fs from 'fs';
2+
import fs from 'fs';
33
import * as path from 'path';
44
import * as core from '@actions/core';
55
import * as io from '@actions/io';
66
import * as auth from '../src/authutil';
7+
import * as cacheUtils from '../src/cache-utils';
78

89
let rcFile: string;
910

__tests__/cache-restore.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ describe('cache-restore', () => {
3232

3333
function findCacheFolder(command: string) {
3434
switch (command) {
35-
case utils.supportedPackageManagers.npm.getCacheFolderCommand:
35+
case 'npm config get cache':
3636
return npmCachePath;
37-
case utils.supportedPackageManagers.pnpm.getCacheFolderCommand:
37+
case 'pnpm store path --silent':
3838
return pnpmCachePath;
39-
case utils.supportedPackageManagers.yarn1.getCacheFolderCommand:
39+
case 'yarn cache dir':
4040
return yarn1CachePath;
41-
case utils.supportedPackageManagers.yarn2.getCacheFolderCommand:
41+
case 'yarn config get cacheFolder':
4242
return yarn2CachePath;
4343
default:
4444
return 'packge/not/found';
@@ -108,7 +108,7 @@ describe('cache-restore', () => {
108108
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
109109
'Throw an error because %s is not supported',
110110
async packageManager => {
111-
await expect(restoreCache(packageManager)).rejects.toThrow(
111+
await expect(restoreCache(packageManager, '')).rejects.toThrow(
112112
`Caching for '${packageManager}' is not supported`
113113
);
114114
}
@@ -132,7 +132,7 @@ describe('cache-restore', () => {
132132
}
133133
});
134134

135-
await restoreCache(packageManager);
135+
await restoreCache(packageManager, '');
136136
expect(hashFilesSpy).toHaveBeenCalled();
137137
expect(infoSpy).toHaveBeenCalledWith(
138138
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
@@ -163,7 +163,7 @@ describe('cache-restore', () => {
163163
});
164164

165165
restoreCacheSpy.mockImplementationOnce(() => undefined);
166-
await restoreCache(packageManager);
166+
await restoreCache(packageManager, '');
167167
expect(hashFilesSpy).toHaveBeenCalled();
168168
expect(infoSpy).toHaveBeenCalledWith(
169169
`${packageManager} cache is not found`

0 commit comments

Comments
 (0)