mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 15:32:13 +00:00
resolve throw error
This commit is contained in:
parent
3d613a97df
commit
ef9020329d
4 changed files with 29 additions and 36 deletions
30
dist/index.js
vendored
30
dist/index.js
vendored
|
@ -1137,7 +1137,7 @@ function findPyPyToolCache(pythonVersion, pypyVersion, architecture) {
|
||||||
if (installDir) {
|
if (installDir) {
|
||||||
// 'tc.find' finds tool based on Python version but we also need to check
|
// 'tc.find' finds tool based on Python version but we also need to check
|
||||||
// whether PyPy version satisfies requested version.
|
// whether PyPy version satisfies requested version.
|
||||||
resolvedPythonVersion = getPyPyVersionFromPath(installDir);
|
resolvedPythonVersion = utils_1.getPyPyVersionFromPath(installDir);
|
||||||
resolvedPyPyVersion = pypyInstall.readExactPyPyVersion(installDir);
|
resolvedPyPyVersion = pypyInstall.readExactPyPyVersion(installDir);
|
||||||
const isPyPyVersionSatisfies = semver.satisfies(resolvedPyPyVersion, pypyVersion);
|
const isPyPyVersionSatisfies = semver.satisfies(resolvedPyPyVersion, pypyVersion);
|
||||||
if (!isPyPyVersionSatisfies) {
|
if (!isPyPyVersionSatisfies) {
|
||||||
|
@ -1151,11 +1151,11 @@ function findPyPyToolCache(pythonVersion, pypyVersion, architecture) {
|
||||||
}
|
}
|
||||||
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
|
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
|
||||||
}
|
}
|
||||||
|
exports.findPyPyToolCache = findPyPyToolCache;
|
||||||
function parsePyPyVersion(versionSpec) {
|
function parsePyPyVersion(versionSpec) {
|
||||||
const versions = versionSpec.split('-').filter(item => !!item);
|
const versions = versionSpec.split('-').filter(item => !!item);
|
||||||
if (versions.length < 2) {
|
if (versions.length < 2 || versions[0] != 'pypy') {
|
||||||
core.setFailed("Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation.");
|
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];
|
const pythonVersion = versions[1];
|
||||||
let pypyVersion;
|
let pypyVersion;
|
||||||
|
@ -1166,17 +1166,14 @@ function parsePyPyVersion(versionSpec) {
|
||||||
pypyVersion = 'x';
|
pypyVersion = 'x';
|
||||||
}
|
}
|
||||||
if (!utils_1.validateVersion(pythonVersion) || !utils_1.validateVersion(pypyVersion)) {
|
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.");
|
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 {
|
return {
|
||||||
pypyVersion: pypyVersion,
|
pypyVersion: pypyVersion,
|
||||||
pythonVersion: pythonVersion
|
pythonVersion: pythonVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getPyPyVersionFromPath(installDir) {
|
exports.parsePyPyVersion = parsePyPyVersion;
|
||||||
return path.basename(path.dirname(installDir));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -2348,6 +2345,10 @@ function isNightlyKeyword(pypyVersion) {
|
||||||
return pypyVersion === 'nightly';
|
return pypyVersion === 'nightly';
|
||||||
}
|
}
|
||||||
exports.isNightlyKeyword = isNightlyKeyword;
|
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;
|
let downloadDir;
|
||||||
const releases = yield getAvailablePyPyVersions();
|
const releases = yield getAvailablePyPyVersions();
|
||||||
if (!releases || releases.length === 0) {
|
if (!releases || releases.length === 0) {
|
||||||
core.setFailed('No release was found in PyPy version.json');
|
throw new Error('No release was found in PyPy version.json');
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
const releaseData = findRelease(releases, pythonVersion, pypyVersion, architecture);
|
const releaseData = findRelease(releases, pythonVersion, pypyVersion, architecture);
|
||||||
if (!releaseData || !releaseData.foundAsset) {
|
if (!releaseData || !releaseData.foundAsset) {
|
||||||
core.setFailed(`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`);
|
throw new Error(`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
|
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
|
||||||
let downloadUrl = `${foundAsset.download_url}`;
|
let downloadUrl = `${foundAsset.download_url}`;
|
||||||
|
@ -2822,8 +2821,7 @@ function getAvailablePyPyVersions() {
|
||||||
const http = new httpm.HttpClient('tool-cache');
|
const http = new httpm.HttpClient('tool-cache');
|
||||||
const response = yield http.getJson(url);
|
const response = yield http.getJson(url);
|
||||||
if (!response.result) {
|
if (!response.result) {
|
||||||
core.setFailed(`Unable to retrieve the list of available PyPy versions from '${url}'`);
|
throw new Error(`Unable to retrieve the list of available PyPy versions from '${url}'`);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
return response.result;
|
return response.result;
|
||||||
});
|
});
|
||||||
|
@ -2844,7 +2842,6 @@ function installPip(pythonLocation) {
|
||||||
core.info('Installing and updating pip');
|
core.info('Installing and updating pip');
|
||||||
const pythonBinary = path.join(pythonLocation, 'python');
|
const pythonBinary = path.join(pythonLocation, 'python');
|
||||||
yield exec.exec(`${pythonBinary} -m ensurepip`);
|
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`);
|
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
|
resolvedPyPyVersion: foundRelease.pypy_version
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
exports.findRelease = findRelease;
|
||||||
// helper functions
|
// helper functions
|
||||||
/**
|
/**
|
||||||
* In tool-cache, we put PyPy to '<toolcache_root>/PyPy/<python_version>/x64'
|
* In tool-cache, we put PyPy to '<toolcache_root>/PyPy/<python_version>/x64'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as pypyInstall from './install-pypy';
|
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 semver from 'semver';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
@ -54,7 +54,7 @@ export async function findPyPyVersion(
|
||||||
return {resolvedPyPyVersion, resolvedPythonVersion};
|
return {resolvedPyPyVersion, resolvedPythonVersion};
|
||||||
}
|
}
|
||||||
|
|
||||||
function findPyPyToolCache(
|
export function findPyPyToolCache(
|
||||||
pythonVersion: string,
|
pythonVersion: string,
|
||||||
pypyVersion: string,
|
pypyVersion: string,
|
||||||
architecture: string
|
architecture: string
|
||||||
|
@ -89,14 +89,13 @@ function findPyPyToolCache(
|
||||||
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
|
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
||||||
const versions = versionSpec.split('-').filter(item => !!item);
|
const versions = versionSpec.split('-').filter(item => !!item);
|
||||||
|
|
||||||
if (versions.length < 2) {
|
if (versions.length < 2 || versions[0] != 'pypy') {
|
||||||
core.setFailed(
|
throw new Error(
|
||||||
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation."
|
"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];
|
const pythonVersion = versions[1];
|
||||||
|
@ -108,10 +107,9 @@ function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateVersion(pythonVersion) || !validateVersion(pypyVersion)) {
|
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."
|
"Invalid 'version' property for PyPy. Both Python version and PyPy versions should satisfy SemVer notation. See README for examples and documentation."
|
||||||
);
|
);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -119,7 +117,3 @@ function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
||||||
pythonVersion: pythonVersion
|
pythonVersion: pythonVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPyPyVersionFromPath(installDir: string) {
|
|
||||||
return path.basename(path.dirname(installDir));
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ export async function installPyPy(
|
||||||
|
|
||||||
const releases = await getAvailablePyPyVersions();
|
const releases = await getAvailablePyPyVersions();
|
||||||
if (!releases || releases.length === 0) {
|
if (!releases || releases.length === 0) {
|
||||||
core.setFailed('No release was found in PyPy version.json');
|
throw new Error('No release was found in PyPy version.json');
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseData = findRelease(
|
const releaseData = findRelease(
|
||||||
|
@ -36,10 +35,9 @@ export async function installPyPy(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!releaseData || !releaseData.foundAsset) {
|
if (!releaseData || !releaseData.foundAsset) {
|
||||||
core.setFailed(
|
throw new Error(
|
||||||
`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`
|
`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`
|
||||||
);
|
);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {foundAsset, resolvedPythonVersion, resolvedPyPyVersion} = releaseData;
|
const {foundAsset, resolvedPythonVersion, resolvedPyPyVersion} = releaseData;
|
||||||
|
@ -85,10 +83,9 @@ async function getAvailablePyPyVersions() {
|
||||||
|
|
||||||
const response = await http.getJson<IPyPyManifestRelease[]>(url);
|
const response = await http.getJson<IPyPyManifestRelease[]>(url);
|
||||||
if (!response.result) {
|
if (!response.result) {
|
||||||
core.setFailed(
|
throw new Error(
|
||||||
`Unable to retrieve the list of available PyPy versions from '${url}'`
|
`Unable to retrieve the list of available PyPy versions from '${url}'`
|
||||||
);
|
);
|
||||||
process.exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.result;
|
return response.result;
|
||||||
|
@ -123,13 +120,13 @@ async function installPip(pythonLocation: string) {
|
||||||
core.info('Installing and updating pip');
|
core.info('Installing and updating pip');
|
||||||
const pythonBinary = path.join(pythonLocation, 'python');
|
const pythonBinary = path.join(pythonLocation, 'python');
|
||||||
await exec.exec(`${pythonBinary} -m ensurepip`);
|
await exec.exec(`${pythonBinary} -m ensurepip`);
|
||||||
// TO-DO should we skip updating of pip ?
|
|
||||||
await exec.exec(
|
await exec.exec(
|
||||||
`${pythonLocation}/python -m pip install --ignore-installed pip`
|
`${pythonLocation}/python -m pip install --ignore-installed pip`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findRelease(
|
export function findRelease(
|
||||||
releases: IPyPyManifestRelease[],
|
releases: IPyPyManifestRelease[],
|
||||||
pythonVersion: string,
|
pythonVersion: string,
|
||||||
pypyVersion: string,
|
pypyVersion: string,
|
||||||
|
|
|
@ -49,3 +49,7 @@ export function validateVersion(version: string) {
|
||||||
export function isNightlyKeyword(pypyVersion: string) {
|
export function isNightlyKeyword(pypyVersion: string) {
|
||||||
return pypyVersion === 'nightly';
|
return pypyVersion === 'nightly';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPyPyVersionFromPath(installDir: string) {
|
||||||
|
return path.basename(path.dirname(installDir));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue