resolve throw error

This commit is contained in:
Dmitry Shibanov 2020-12-15 20:36:35 +03:00
parent 3d613a97df
commit ef9020329d
4 changed files with 29 additions and 36 deletions

30
dist/index.js vendored
View file

@ -1137,7 +1137,7 @@ function findPyPyToolCache(pythonVersion, pypyVersion, architecture) {
if (installDir) {
// 'tc.find' finds tool based on Python version but we also need to check
// whether PyPy version satisfies requested version.
resolvedPythonVersion = getPyPyVersionFromPath(installDir);
resolvedPythonVersion = utils_1.getPyPyVersionFromPath(installDir);
resolvedPyPyVersion = pypyInstall.readExactPyPyVersion(installDir);
const isPyPyVersionSatisfies = semver.satisfies(resolvedPyPyVersion, pypyVersion);
if (!isPyPyVersionSatisfies) {
@ -1151,11 +1151,11 @@ function findPyPyToolCache(pythonVersion, pypyVersion, architecture) {
}
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
}
exports.findPyPyToolCache = findPyPyToolCache;
function parsePyPyVersion(versionSpec) {
const versions = versionSpec.split('-').filter(item => !!item);
if (versions.length < 2) {
core.setFailed("Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation.");
process.exit();
if (versions.length < 2 || versions[0] != 'pypy') {
throw new Error("Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation.");
}
const pythonVersion = versions[1];
let pypyVersion;
@ -1166,17 +1166,14 @@ function parsePyPyVersion(versionSpec) {
pypyVersion = 'x';
}
if (!utils_1.validateVersion(pythonVersion) || !utils_1.validateVersion(pypyVersion)) {
core.setFailed("Invalid 'version' property for PyPy. Both Python version and PyPy versions should satisfy SemVer notation. See README for examples and documentation.");
process.exit();
throw new Error("Invalid 'version' property for PyPy. Both Python version and PyPy versions should satisfy SemVer notation. See README for examples and documentation.");
}
return {
pypyVersion: pypyVersion,
pythonVersion: pythonVersion
};
}
function getPyPyVersionFromPath(installDir) {
return path.basename(path.dirname(installDir));
}
exports.parsePyPyVersion = parsePyPyVersion;
/***/ }),
@ -2348,6 +2345,10 @@ function isNightlyKeyword(pypyVersion) {
return pypyVersion === 'nightly';
}
exports.isNightlyKeyword = isNightlyKeyword;
function getPyPyVersionFromPath(installDir) {
return path.basename(path.dirname(installDir));
}
exports.getPyPyVersionFromPath = getPyPyVersionFromPath;
/***/ }),
@ -2781,13 +2782,11 @@ function installPyPy(pypyVersion, pythonVersion, architecture) {
let downloadDir;
const releases = yield getAvailablePyPyVersions();
if (!releases || releases.length === 0) {
core.setFailed('No release was found in PyPy version.json');
process.exit();
throw new Error('No release was found in PyPy version.json');
}
const releaseData = findRelease(releases, pythonVersion, pypyVersion, architecture);
if (!releaseData || !releaseData.foundAsset) {
core.setFailed(`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`);
process.exit();
throw new Error(`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`);
}
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
let downloadUrl = `${foundAsset.download_url}`;
@ -2822,8 +2821,7 @@ function getAvailablePyPyVersions() {
const http = new httpm.HttpClient('tool-cache');
const response = yield http.getJson(url);
if (!response.result) {
core.setFailed(`Unable to retrieve the list of available PyPy versions from '${url}'`);
process.exit();
throw new Error(`Unable to retrieve the list of available PyPy versions from '${url}'`);
}
return response.result;
});
@ -2844,7 +2842,6 @@ function installPip(pythonLocation) {
core.info('Installing and updating pip');
const pythonBinary = path.join(pythonLocation, 'python');
yield exec.exec(`${pythonBinary} -m ensurepip`);
// TO-DO should we skip updating of pip ?
yield exec.exec(`${pythonLocation}/python -m pip install --ignore-installed pip`);
});
}
@ -2873,6 +2870,7 @@ function findRelease(releases, pythonVersion, pypyVersion, architecture) {
resolvedPyPyVersion: foundRelease.pypy_version
};
}
exports.findRelease = findRelease;
// helper functions
/**
* In tool-cache, we put PyPy to '<toolcache_root>/PyPy/<python_version>/x64'