add support for caching

This commit is contained in:
Dmitry Shibanov 2021-10-27 09:52:29 +03:00
parent feeaa3ba49
commit 952fef3565
14 changed files with 124033 additions and 7678 deletions

View file

@ -0,0 +1,42 @@
import * as glob from '@actions/glob';
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import CacheDistributor from './cache-distributor';
class PipenvCache extends CacheDistributor {
constructor(
private pythonVersion: string,
protected patterns: string = 'Pipfile.lock'
) {
super('pipenv', patterns);
}
private getVirtualenvsPath() {
if (process.platform === 'win32') {
return '.virtualenvs';
} else {
return '.local/share/virtualenvs';
}
}
protected async getCacheGlobalDirectories() {
const cachePath = path.join(os.homedir(), this.getVirtualenvsPath());
core.debug(`Pipenv virtualenvs path is ${cachePath}`);
return [cachePath];
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.toolName}-${hash}`;
const restoreKey = undefined;
return {
primaryKey,
restoreKey
};
}
}
export default PipenvCache;