forked from actions/setup-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipenv-cache.ts
56 lines (46 loc) · 1.96 KB
/
pipenv-cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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';
import { getLinuxOSReleaseInfo, IS_LINUX } from '../utils';
class PipenvCache extends CacheDistributor {
constructor(
private pythonVersion: string,
protected patterns: string = '**/Pipfile.lock'
) {
super('pipenv', patterns);
}
protected async getCacheGlobalDirectories() {
let virtualEnvRelativePath;
// Default virtualenv directories are hardcoded,
// because pipenv is not preinstalled on hosted images and virtualenv is not created:
// https://github.com/pypa/pipenv/blob/1daaa0de9a0b00d386c6baeb809d8d4ee6795cfd/pipenv/utils.py#L1990-L2002
if (process.platform === 'win32') {
virtualEnvRelativePath = '.virtualenvs';
} else {
virtualEnvRelativePath = '.local/share/virtualenvs';
}
const resolvedPath = path.join(os.homedir(), virtualEnvRelativePath);
core.debug(`global cache directory path is ${resolvedPath}`);
return [resolvedPath];
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.cacheDependencyPath);
let primaryKey = ''
let restoreKey = ''
if(IS_LINUX) {
const osRelease = await getLinuxOSReleaseInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`;
} else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
}
return {
primaryKey,
restoreKey: [restoreKey]
};
}
}
export default PipenvCache;