mirror of
https://github.com/actions/setup-python.git
synced 2025-07-18 17:58:19 +02:00
rebuild all code
This commit is contained in:
parent
262e11fdfd
commit
b68f05c8bb
11 changed files with 550 additions and 267 deletions
|
@ -1,13 +1,51 @@
|
|||
import CacheDistributor from './cache-distributor';
|
||||
import * as glob from '@actions/glob';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
import CacheDistributor, {IPackageManager} from './cache-distributor';
|
||||
|
||||
class PipCache extends CacheDistributor {
|
||||
constructor() {
|
||||
constructor(info: IPackageManager) {
|
||||
super({
|
||||
command: 'pip cache dir',
|
||||
patterns: ['**/requirements.txt'],
|
||||
toolName: 'pip'
|
||||
patterns:
|
||||
info.patterns.length == 0 ? ['**/requirements.txt'] : info.patterns,
|
||||
toolName: info.toolName
|
||||
});
|
||||
}
|
||||
|
||||
protected async getCacheGlobalDirectories() {
|
||||
const {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||
'pip cache dir'
|
||||
);
|
||||
if (stderr) {
|
||||
throw new Error(
|
||||
`failed to procceed with caching with error: ${exitCode}`
|
||||
);
|
||||
}
|
||||
|
||||
let resolvedPath = stdout.trim();
|
||||
|
||||
if (resolvedPath.includes('~')) {
|
||||
resolvedPath = path.join(os.homedir(), resolvedPath.slice(1));
|
||||
}
|
||||
|
||||
core.info(`global cache directory path is ${resolvedPath}`);
|
||||
|
||||
return [resolvedPath];
|
||||
}
|
||||
|
||||
protected async computeKeys() {
|
||||
const hash = await glob.hashFiles(this.packageManager.patterns.join('\n'));
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager.toolName}-${hash}`;
|
||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager.toolName}-`;
|
||||
return {
|
||||
primaryKey,
|
||||
restoreKey
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default PipCache;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue