mirror of
https://github.com/actions/setup-python.git
synced 2025-04-20 03:53:30 +00:00
Fix PyPy nightly resolving
Fix for pypy-3-nightly
This commit is contained in:
commit
ac952b19ed
@ -49,23 +49,6 @@ describe('parsePyPyVersion', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateVersion', () => {
|
|
||||||
it.each([
|
|
||||||
['v7.3.3', true],
|
|
||||||
['v7.3.x', true],
|
|
||||||
['v7.x', true],
|
|
||||||
['x', true],
|
|
||||||
['v7.3.3-rc.1', true],
|
|
||||||
['nightly', true],
|
|
||||||
['v7.3.b', false],
|
|
||||||
['3.6', true],
|
|
||||||
['3.b', false],
|
|
||||||
['3', true]
|
|
||||||
])('%s -> %s', (input, expected) => {
|
|
||||||
expect(validateVersion(input)).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getPyPyVersionFromPath', () => {
|
describe('getPyPyVersionFromPath', () => {
|
||||||
it('/fake/toolcache/PyPy/3.6.5/x64 -> 3.6.5', () => {
|
it('/fake/toolcache/PyPy/3.6.5/x64 -> 3.6.5', () => {
|
||||||
expect(getPyPyVersionFromPath('/fake/toolcache/PyPy/3.6.5/x64')).toEqual(
|
expect(getPyPyVersionFromPath('/fake/toolcache/PyPy/3.6.5/x64')).toEqual(
|
||||||
@ -223,6 +206,12 @@ describe('findPyPyVersion', () => {
|
|||||||
).rejects.toThrow();
|
).rejects.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throw on invalid input format pypy3.7-7.3.x', async () => {
|
||||||
|
await expect(
|
||||||
|
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
|
||||||
|
).rejects.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
it('found and install successfully', async () => {
|
it('found and install successfully', async () => {
|
||||||
spyCacheDir = jest.spyOn(tc, 'cacheDir');
|
spyCacheDir = jest.spyOn(tc, 'cacheDir');
|
||||||
spyCacheDir.mockImplementation(() =>
|
spyCacheDir.mockImplementation(() =>
|
||||||
@ -240,9 +229,9 @@ describe('findPyPyVersion', () => {
|
|||||||
|
|
||||||
it('throw if release is not found', async () => {
|
it('throw if release is not found', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
|
finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture)
|
||||||
).rejects.toThrowError(
|
).rejects.toThrowError(
|
||||||
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation."
|
`PyPy version 3.7 (v7.5.x) with arch ${architecture} not found`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
34
__tests__/utils.test.ts
Normal file
34
__tests__/utils.test.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import {
|
||||||
|
validateVersion,
|
||||||
|
validatePythonVersionFormatForPyPy
|
||||||
|
} from '../src/utils';
|
||||||
|
|
||||||
|
describe('validatePythonVersionFormatForPyPy', () => {
|
||||||
|
it.each([
|
||||||
|
['3.6', true],
|
||||||
|
['3.7', true],
|
||||||
|
['3.6.x', false],
|
||||||
|
['3.7.x', false],
|
||||||
|
['3.x', false],
|
||||||
|
['3', false]
|
||||||
|
])('%s -> %s', (input, expected) => {
|
||||||
|
expect(validatePythonVersionFormatForPyPy(input)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('validateVersion', () => {
|
||||||
|
it.each([
|
||||||
|
['v7.3.3', true],
|
||||||
|
['v7.3.x', true],
|
||||||
|
['v7.x', true],
|
||||||
|
['x', true],
|
||||||
|
['v7.3.3-rc.1', true],
|
||||||
|
['nightly', true],
|
||||||
|
['v7.3.b', false],
|
||||||
|
['3.6', true],
|
||||||
|
['3.b', false],
|
||||||
|
['3', true]
|
||||||
|
])('%s -> %s', (input, expected) => {
|
||||||
|
expect(validateVersion(input)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
13
dist/index.js
vendored
13
dist/index.js
vendored
@ -1168,6 +1168,9 @@ function parsePyPyVersion(versionSpec) {
|
|||||||
if (!utils_1.validateVersion(pythonVersion) || !utils_1.validateVersion(pypyVersion)) {
|
if (!utils_1.validateVersion(pythonVersion) || !utils_1.validateVersion(pypyVersion)) {
|
||||||
throw new Error("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.");
|
||||||
}
|
}
|
||||||
|
if (!utils_1.validatePythonVersionFormatForPyPy(pythonVersion)) {
|
||||||
|
throw new Error("Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation.");
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
pypyVersion: pypyVersion,
|
pypyVersion: pypyVersion,
|
||||||
pythonVersion: pythonVersion
|
pythonVersion: pythonVersion
|
||||||
@ -2375,6 +2378,16 @@ function writeExactPyPyVersionFile(installDir, resolvedPyPyVersion) {
|
|||||||
fs_1.default.writeFileSync(pypyFilePath, resolvedPyPyVersion);
|
fs_1.default.writeFileSync(pypyFilePath, resolvedPyPyVersion);
|
||||||
}
|
}
|
||||||
exports.writeExactPyPyVersionFile = writeExactPyPyVersionFile;
|
exports.writeExactPyPyVersionFile = writeExactPyPyVersionFile;
|
||||||
|
/**
|
||||||
|
* Python version should be specified explicitly like "x.y" (2.7, 3.6, 3.7)
|
||||||
|
* "3.x" or "3" are not supported
|
||||||
|
* because it could cause ambiguity when both PyPy version and Python version are not precise
|
||||||
|
*/
|
||||||
|
function validatePythonVersionFormatForPyPy(version) {
|
||||||
|
const re = /^\d+\.\d+$/;
|
||||||
|
return re.test(version);
|
||||||
|
}
|
||||||
|
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -4,7 +4,8 @@ import {
|
|||||||
IS_WINDOWS,
|
IS_WINDOWS,
|
||||||
validateVersion,
|
validateVersion,
|
||||||
getPyPyVersionFromPath,
|
getPyPyVersionFromPath,
|
||||||
readExactPyPyVersionFile
|
readExactPyPyVersionFile,
|
||||||
|
validatePythonVersionFormatForPyPy
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
@ -117,6 +118,12 @@ export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!validatePythonVersionFormatForPyPy(pythonVersion)) {
|
||||||
|
throw new Error(
|
||||||
|
"Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pypyVersion: pypyVersion,
|
pypyVersion: pypyVersion,
|
||||||
pythonVersion: pythonVersion
|
pythonVersion: pythonVersion
|
||||||
|
10
src/utils.ts
10
src/utils.ts
@ -80,3 +80,13 @@ export function writeExactPyPyVersionFile(
|
|||||||
const pypyFilePath = path.join(installDir, PYPY_VERSION_FILE);
|
const pypyFilePath = path.join(installDir, PYPY_VERSION_FILE);
|
||||||
fs.writeFileSync(pypyFilePath, resolvedPyPyVersion);
|
fs.writeFileSync(pypyFilePath, resolvedPyPyVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Python version should be specified explicitly like "x.y" (2.7, 3.6, 3.7)
|
||||||
|
* "3.x" or "3" are not supported
|
||||||
|
* because it could cause ambiguity when both PyPy version and Python version are not precise
|
||||||
|
*/
|
||||||
|
export function validatePythonVersionFormatForPyPy(version: string) {
|
||||||
|
const re = /^\d+\.\d+$/;
|
||||||
|
return re.test(version);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user