Skip to content

Commit

Permalink
Detect cached folders from multiple directories (#735)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dsame authored Jun 21, 2023
1 parent 698d505 commit 8170e22
Show file tree
Hide file tree
Showing 16 changed files with 3,445 additions and 1,496 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/e2e-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,30 @@ jobs:
- name: Verify node and yarn
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
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
run: __tests__/prepare-subprojects.sh

# 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
3 changes: 2 additions & 1 deletion __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os from 'os';
import * as fs from 'fs';
import fs from 'fs';
import * as path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as auth from '../src/authutil';
import * as cacheUtils from '../src/cache-utils';

let rcFile: string;

Expand Down
14 changes: 7 additions & 7 deletions __tests__/cache-restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe('cache-restore', () => {

function findCacheFolder(command: string) {
switch (command) {
case utils.supportedPackageManagers.npm.getCacheFolderCommand:
case 'npm config get cache':
return npmCachePath;
case utils.supportedPackageManagers.pnpm.getCacheFolderCommand:
case 'pnpm store path --silent':
return pnpmCachePath;
case utils.supportedPackageManagers.yarn1.getCacheFolderCommand:
case 'yarn cache dir':
return yarn1CachePath;
case utils.supportedPackageManagers.yarn2.getCacheFolderCommand:
case 'yarn config get cacheFolder':
return yarn2CachePath;
default:
return 'packge/not/found';
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('cache-restore', () => {
it.each([['npm7'], ['npm6'], ['pnpm6'], ['yarn1'], ['yarn2'], ['random']])(
'Throw an error because %s is not supported',
async packageManager => {
await expect(restoreCache(packageManager)).rejects.toThrow(
await expect(restoreCache(packageManager, '')).rejects.toThrow(
`Caching for '${packageManager}' is not supported`
);
}
Expand All @@ -132,7 +132,7 @@ describe('cache-restore', () => {
}
});

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

restoreCacheSpy.mockImplementationOnce(() => undefined);
await restoreCache(packageManager);
await restoreCache(packageManager, '');
expect(hashFilesSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`${packageManager} cache is not found`
Expand Down
Loading

0 comments on commit 8170e22

Please sign in to comment.