setup-python/src/cache-distributions/pipenv-cache.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-27 06:52:29 +00:00
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() {
2021-11-03 10:10:35 +00:00
const resolvedPath = path.join(os.homedir(), this.getVirtualenvsPath());
core.debug(`global cache directory path is ${resolvedPath}`);
2021-10-27 06:52:29 +00:00
2021-11-03 10:10:35 +00:00
return [resolvedPath];
2021-10-27 06:52:29 +00:00
}
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;