1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-python synced 2025-06-08 20:38:19 +02:00

Code improvemnt: Rm CacheDistributor.cacheDependencyPath field and pass back from computeKeys instead, simplifying CacheDistributor.restoreCache error check. Rm now uneeded constant.ts file.

This commit is contained in:
Sam Pinkus 2025-01-08 16:37:25 +10:00
parent 0024ce0d14
commit d99639b3c5
5 changed files with 16 additions and 18 deletions

View file

@ -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<string[]>;
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`
);