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,47 @@
import * as glob from '@actions/glob';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as path from 'path';
import os from 'os';
import CacheDistributor from './cache-distributor';
class PipCache extends CacheDistributor {
constructor(patterns: string = '**/requirements.txt') {
super('pip', patterns);
}
protected async getCacheGlobalDirectories() {
const {stdout, stderr, exitCode} = await exec.getExecOutput(
'pip cache dir'
);
if (stderr) {
throw new Error(
`Could not get cache folder path for pip package manager`
);
}
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.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.toolName}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.toolName}-`;
return {
primaryKey,
restoreKey: [restoreKey]
};
}
}
export default PipCache;