mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-10 13:22:20 +02:00
Add another pip default dependency file for cache hash (#604)
This commit is contained in:
parent
869e769ec8
commit
7b9ef6fc5a
7 changed files with 98 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
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',
|
||||
|
@ -24,10 +25,14 @@ abstract class CacheDistributor {
|
|||
public async restoreCache() {
|
||||
const {primaryKey, restoreKey} = 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(',');
|
||||
throw new Error(
|
||||
`No file in ${process.cwd()} matched to [${this.cacheDependencyPath
|
||||
.split('\n')
|
||||
.join(',')}], make sure you have checked out the target repository`
|
||||
`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
2
src/cache-distributions/constants.ts
Normal file
2
src/cache-distributions/constants.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
const CACHE_DEPENDENCY_BACKUP_PATH: string = '**/pyproject.toml';
|
||||
export {CACHE_DEPENDENCY_BACKUP_PATH};
|
|
@ -8,8 +8,11 @@ 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;
|
||||
|
||||
constructor(
|
||||
private pythonVersion: string,
|
||||
cacheDependencyPath: string = '**/requirements.txt'
|
||||
|
@ -56,7 +59,9 @@ class PipCache extends CacheDistributor {
|
|||
}
|
||||
|
||||
protected async computeKeys() {
|
||||
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
||||
const hash =
|
||||
(await glob.hashFiles(this.cacheDependencyPath)) ||
|
||||
(await glob.hashFiles(this.cacheDependencyBackupPath));
|
||||
let primaryKey = '';
|
||||
let restoreKey = '';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue