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'

View File

@ -1,6 +1,6 @@
import * as path from 'path';
import * as pypyInstall from './install-pypy';
import {IS_WINDOWS, validateVersion} from './utils';
import {IS_WINDOWS, validateVersion, getPyPyVersionFromPath} from './utils';
import * as semver from 'semver';
import * as core from '@actions/core';
@ -54,7 +54,7 @@ export async function findPyPyVersion(
return {resolvedPyPyVersion, resolvedPythonVersion};
}
function findPyPyToolCache(
export function findPyPyToolCache(
pythonVersion: string,
pypyVersion: string,
architecture: string
@ -89,14 +89,13 @@ function findPyPyToolCache(
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
}
function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
const versions = versionSpec.split('-').filter(item => !!item);
if (versions.length < 2) {
core.setFailed(
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."
);
process.exit();
}
const pythonVersion = versions[1];
@ -108,10 +107,9 @@ function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
}
if (!validateVersion(pythonVersion) || !validateVersion(pypyVersion)) {
core.setFailed(
throw new Error(
"Invalid 'version' property for PyPy. Both Python version and PyPy versions should satisfy SemVer notation. See README for examples and documentation."
);
process.exit();
}
return {
@ -119,7 +117,3 @@ function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
pythonVersion: pythonVersion
};
}
function getPyPyVersionFromPath(installDir: string) {
return path.basename(path.dirname(installDir));
}

View File

@ -24,8 +24,7 @@ export async function installPyPy(
const releases = await 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(
@ -36,10 +35,9 @@ export async function installPyPy(
);
if (!releaseData || !releaseData.foundAsset) {
core.setFailed(
throw new Error(
`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`
);
process.exit();
}
const {foundAsset, resolvedPythonVersion, resolvedPyPyVersion} = releaseData;
@ -85,10 +83,9 @@ async function getAvailablePyPyVersions() {
const response = await http.getJson<IPyPyManifestRelease[]>(url);
if (!response.result) {
core.setFailed(
throw new Error(
`Unable to retrieve the list of available PyPy versions from '${url}'`
);
process.exit();
}
return response.result;
@ -123,13 +120,13 @@ async function installPip(pythonLocation: string) {
core.info('Installing and updating pip');
const pythonBinary = path.join(pythonLocation, 'python');
await exec.exec(`${pythonBinary} -m ensurepip`);
// TO-DO should we skip updating of pip ?
await exec.exec(
`${pythonLocation}/python -m pip install --ignore-installed pip`
);
}
function findRelease(
export function findRelease(
releases: IPyPyManifestRelease[],
pythonVersion: string,
pypyVersion: string,

View File

@ -49,3 +49,7 @@ export function validateVersion(version: string) {
export function isNightlyKeyword(pypyVersion: string) {
return pypyVersion === 'nightly';
}
export function getPyPyVersionFromPath(installDir: string) {
return path.basename(path.dirname(installDir));
}