diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index 55a5a3d..efc9eee 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -1,6 +1,5 @@ import * as cache from '@actions/cache'; import * as core from '@actions/core'; -import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants'; export enum State { STATE_CACHE_PRIMARY_KEY = 'cache-primary-key', @@ -11,24 +10,19 @@ export enum State { abstract class CacheDistributor { protected CACHE_KEY_PREFIX = 'setup-python'; protected abstract readonly packageManager: string; - protected abstract readonly cacheDependencyPath: string; protected abstract getCacheGlobalDirectories(): Promise; protected abstract computeKeys(): Promise<{ primaryKey: string; restoreKey: string[] | undefined; + cacheDependencyPath: string; }>; protected async handleLoadedCache() {} public async restoreCache() { - const {primaryKey, restoreKey} = await this.computeKeys(); + const {primaryKey, restoreKey, cacheDependencyPath} = await this.computeKeys(); if (primaryKey.endsWith('-')) { - const file = - this.packageManager === 'pip' - ? `${this.cacheDependencyPath - .split('\n') - .join(',')} or ${CACHE_DEPENDENCY_BACKUP_PATH}` - : this.cacheDependencyPath.split('\n').join(','); + const file = cacheDependencyPath.split('\n').join(','); throw new Error( `No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository` ); diff --git a/src/cache-distributions/constants.ts b/src/cache-distributions/constants.ts deleted file mode 100644 index 08dc745..0000000 --- a/src/cache-distributions/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const CACHE_DEPENDENCY_BACKUP_PATH = '**/pyproject.toml'; diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index c1c9d02..16450c6 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -8,10 +8,9 @@ import os from 'os'; import CacheDistributor from './cache-distributor'; import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils'; -import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants'; class PipCache extends CacheDistributor { - private cacheDependencyBackupPath: string = CACHE_DEPENDENCY_BACKUP_PATH; + private cacheDependencyBackupPath = '**/pyproject.toml'; protected readonly packageManager = 'pip'; constructor( @@ -60,9 +59,12 @@ class PipCache extends CacheDistributor { } protected async computeKeys() { - const hash = - (await glob.hashFiles(this.cacheDependencyPath)) || - (await glob.hashFiles(this.cacheDependencyBackupPath)); + let cacheDependencyPath = this.cacheDependencyPath; + let hash = await glob.hashFiles(this.cacheDependencyPath); + if(!hash) { + hash = await glob.hashFiles(this.cacheDependencyBackupPath); + cacheDependencyPath = this.cacheDependencyBackupPath; + } let primaryKey = ''; let restoreKey = ''; @@ -77,7 +79,8 @@ class PipCache extends CacheDistributor { return { primaryKey, - restoreKey: [restoreKey] + restoreKey: [restoreKey], + cacheDependencyPath, }; } } diff --git a/src/cache-distributions/pipenv-cache.ts b/src/cache-distributions/pipenv-cache.ts index 978f63f..66627ca 100644 --- a/src/cache-distributions/pipenv-cache.ts +++ b/src/cache-distributions/pipenv-cache.ts @@ -38,7 +38,8 @@ class PipenvCache extends CacheDistributor { const restoreKey = undefined; return { primaryKey, - restoreKey + restoreKey, + cacheDependencyPath: this.cacheDependencyPath, }; } } diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 1baffaf..b8b83a2 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -54,7 +54,8 @@ class PoetryCache extends CacheDistributor { const restoreKey = undefined; return { primaryKey, - restoreKey + restoreKey, + cacheDependencyPath: this.cacheDependencyPath, }; }