mirror of
https://github.com/actions/setup-python.git
synced 2025-07-05 00:53:46 +00:00
rebuild all code
This commit is contained in:
parent
262e11fdfd
commit
b68f05c8bb
11 changed files with 550 additions and 267 deletions
183
dist/setup/index.js
vendored
183
dist/setup/index.js
vendored
|
@ -6007,9 +6007,6 @@ exports.NoopTracerProvider = NoopTracerProvider;
|
|||
|
||||
"use strict";
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
|
@ -6017,7 +6014,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const fs_1 = __importDefault(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const semver = __importStar(__webpack_require__(876));
|
||||
|
@ -6086,6 +6087,14 @@ function validatePythonVersionFormatForPyPy(version) {
|
|||
return re.test(version);
|
||||
}
|
||||
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;
|
||||
function getInputAsArray(name, options) {
|
||||
return core
|
||||
.getInput(name, options)
|
||||
.split('\n')
|
||||
.map(s => s.trim())
|
||||
.filter(x => x !== '');
|
||||
}
|
||||
exports.getInputAsArray = getInputAsArray;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
@ -6454,6 +6463,7 @@ const finderPyPy = __importStar(__webpack_require__(50));
|
|||
const path = __importStar(__webpack_require__(622));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const cache_factory_1 = __webpack_require__(633);
|
||||
const utils_1 = __webpack_require__(163);
|
||||
function isPyPyVersion(versionSpec) {
|
||||
return versionSpec.startsWith('pypy-');
|
||||
}
|
||||
|
@ -6475,8 +6485,14 @@ function run() {
|
|||
core.info(`Successfully setup ${installed.impl} (${installed.version})`);
|
||||
}
|
||||
const cache = core.getInput('cache');
|
||||
const patterns = utils_1.getInputAsArray('cache-dependency-path');
|
||||
if (cache) {
|
||||
const cacheDistributor = cache_factory_1.getCache(cache, pythonVersion);
|
||||
const packageManager = cache_factory_1.getPackageManagerInfo(cache);
|
||||
const cacheDistributor = yield cache_factory_1.getCache({
|
||||
toolName: cache,
|
||||
patterns: patterns,
|
||||
pythonVersion: pythonVersion
|
||||
});
|
||||
cacheDistributor.restoreCache();
|
||||
}
|
||||
}
|
||||
|
@ -6935,22 +6951,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const glob = __importStar(__webpack_require__(281));
|
||||
const cache_distributor_1 = __importDefault(__webpack_require__(435));
|
||||
class PipenvCache extends cache_distributor_1.default {
|
||||
constructor(pythonVersion) {
|
||||
constructor(cacheManager) {
|
||||
super({
|
||||
patterns: ['Pipfile.lock'],
|
||||
toolName: 'pipenv'
|
||||
});
|
||||
this.pythonVersion = pythonVersion;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
getCacheGlobalDirectory() {
|
||||
getCacheGlobalDirectories() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return ['~/.local/share/virtualenvs'];
|
||||
});
|
||||
}
|
||||
computePrimaryKey() {
|
||||
computeKeys() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const hash = yield glob.hashFiles('Pipfile.lock');
|
||||
return `setup-python-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-pipenv-${hash}`;
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.cacheManager.pythonVersion}-${this.packageManager.toolName}-${hash}`;
|
||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.cacheManager.pythonVersion}-${this.packageManager.toolName}`;
|
||||
return {
|
||||
primaryKey,
|
||||
restoreKey
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -35860,17 +35881,62 @@ exports.PrefixSecurityEnum = PrefixSecurityEnum;
|
|||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const glob = __importStar(__webpack_require__(281));
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const cache_distributor_1 = __importDefault(__webpack_require__(435));
|
||||
class PipCache extends cache_distributor_1.default {
|
||||
constructor() {
|
||||
constructor(info) {
|
||||
super({
|
||||
command: 'pip cache dir',
|
||||
patterns: ['**/requirements.txt'],
|
||||
toolName: 'pip'
|
||||
patterns: info.patterns.length == 0 ? ['**/requirements.txt'] : info.patterns,
|
||||
toolName: info.toolName
|
||||
});
|
||||
}
|
||||
getCacheGlobalDirectories() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { stdout, stderr, exitCode } = yield 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];
|
||||
});
|
||||
}
|
||||
computeKeys() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const hash = yield 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
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -36800,13 +36866,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const cache = __importStar(__webpack_require__(692));
|
||||
const glob = __importStar(__webpack_require__(281));
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
class CacheDistributor {
|
||||
constructor(packageManager) {
|
||||
this.packageManager = packageManager;
|
||||
|
@ -36814,27 +36876,6 @@ class CacheDistributor {
|
|||
this.STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||
this.CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||
}
|
||||
getCacheGlobalDirectory() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { stdout, stderr, exitCode } = yield exec.getExecOutput((_a = this.packageManager.command) !== null && _a !== void 0 ? _a : '');
|
||||
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];
|
||||
});
|
||||
}
|
||||
computePrimaryKey() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const hash = yield glob.hashFiles(this.packageManager.patterns.join('\n'));
|
||||
return `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager.toolName}-${hash}`;
|
||||
});
|
||||
}
|
||||
isCacheDirectoryExists(cacheDirectory) {
|
||||
const result = cacheDirectory.reduce((previousValue, currentValue) => {
|
||||
return previousValue || fs.existsSync(currentValue);
|
||||
|
@ -36843,7 +36884,7 @@ class CacheDistributor {
|
|||
}
|
||||
saveCache() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const cachePath = yield this.getCacheGlobalDirectory();
|
||||
const cachePath = yield this.getCacheGlobalDirectories();
|
||||
if (!this.isCacheDirectoryExists(cachePath)) {
|
||||
throw new Error('No one cache directory exists');
|
||||
}
|
||||
|
@ -36875,15 +36916,15 @@ class CacheDistributor {
|
|||
}
|
||||
restoreCache() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const primaryKey = yield this.computePrimaryKey();
|
||||
const cachePath = yield this.getCacheGlobalDirectory();
|
||||
const { primaryKey, restoreKey } = yield this.computeKeys();
|
||||
const cachePath = yield this.getCacheGlobalDirectories();
|
||||
core.saveState(this.STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
if (primaryKey.endsWith('-')) {
|
||||
throw new Error(`No file in ${process.cwd()} matched to [${this.packageManager.patterns}], make sure you have checked out the target repository`);
|
||||
}
|
||||
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, [
|
||||
`${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager.toolName}`
|
||||
]);
|
||||
restoreKey
|
||||
]); // `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager.toolName}`
|
||||
if (matchedKey) {
|
||||
core.saveState(this.CACHE_MATCHED_KEY, matchedKey);
|
||||
core.info(`Cache restored from key: ${matchedKey}`);
|
||||
|
@ -45268,6 +45309,15 @@ module.exports = require("net");
|
|||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
|
@ -45279,15 +45329,46 @@ var Caches;
|
|||
Caches["Pip"] = "pip";
|
||||
Caches["Pipenv"] = "pipenv";
|
||||
})(Caches = exports.Caches || (exports.Caches = {}));
|
||||
function getCache(cacheType, pythonVersion) {
|
||||
switch (cacheType) {
|
||||
case Caches.Pip:
|
||||
return new pip_cache_1.default();
|
||||
case Caches.Pipenv:
|
||||
return new pipenv_cache_1.default(pythonVersion);
|
||||
default:
|
||||
throw new Error('No cache distributor');
|
||||
exports.supportedPackageManagers = {
|
||||
pip: {
|
||||
patterns: ['**/requirements.txt'],
|
||||
toolName: 'pip'
|
||||
},
|
||||
pipenv: {
|
||||
patterns: ['pnpm-lock.yaml'],
|
||||
toolName: 'pipenv'
|
||||
}
|
||||
};
|
||||
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (packageManager === 'pip') {
|
||||
return exports.supportedPackageManagers.pip;
|
||||
}
|
||||
else if (packageManager === 'pipenv') {
|
||||
return exports.supportedPackageManagers.pipenv;
|
||||
}
|
||||
else {
|
||||
throw new Error('package manager is not supported');
|
||||
}
|
||||
});
|
||||
function getCache(cacheManager) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const info = yield exports.getPackageManagerInfo(cacheManager.toolName);
|
||||
if (!info) {
|
||||
throw new Error('No cache distributor');
|
||||
}
|
||||
info.pythonVersion = cacheManager.pythonVersion;
|
||||
if (cacheManager.patterns.length) {
|
||||
info.patterns = cacheManager.patterns;
|
||||
}
|
||||
switch (cacheManager.toolName) {
|
||||
case Caches.Pip:
|
||||
return new pip_cache_1.default(info);
|
||||
case Caches.Pipenv:
|
||||
return new pipenv_cache_1.default(info);
|
||||
default:
|
||||
throw new Error('No cache distributor');
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.getCache = getCache;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue