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
This commit is contained in:
Sergey Dolin 2023-06-21 17:52:17 +02:00 committed by GitHub
parent 698d50532e
commit 8170e22e8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 3445 additions and 1496 deletions

View file

@ -6,14 +6,14 @@ import fs from 'fs';
import {State} from './constants';
import {
getCacheDirectoryPath,
getCacheDirectories,
getPackageManagerInfo,
PackageManagerInfo
} from './cache-utils';
export const restoreCache = async (
packageManager: string,
cacheDependencyPath?: string
cacheDependencyPath: string
) => {
const packageManagerInfo = await getPackageManagerInfo(packageManager);
if (!packageManagerInfo) {
@ -21,10 +21,11 @@ export const restoreCache = async (
}
const platform = process.env.RUNNER_OS;
const cachePath = await getCacheDirectoryPath(
const cachePaths = await getCacheDirectories(
packageManagerInfo,
packageManager
cacheDependencyPath
);
core.saveState(State.CachePaths, cachePaths);
const lockFilePath = cacheDependencyPath
? cacheDependencyPath
: findLockFile(packageManagerInfo);
@ -41,7 +42,7 @@ export const restoreCache = async (
core.saveState(State.CachePrimaryKey, primaryKey);
const cacheKey = await cache.restoreCache([cachePath], primaryKey);
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
core.setOutput('cache-hit', Boolean(cacheKey));
if (!cacheKey) {
@ -56,6 +57,7 @@ export const restoreCache = async (
const findLockFile = (packageManager: PackageManagerInfo) => {
const lockFiles = packageManager.lockFilePatterns;
const workspace = process.env.GITHUB_WORKSPACE!;
const rootContent = fs.readdirSync(workspace);
const lockFile = lockFiles.find(item => rootContent.includes(item));