mirror of
https://github.com/actions/setup-python
synced 2025-04-07 07:49:45 +00:00
feature: fallback to pre-release when no stable version is found (#414)
This allows to specify version like `3.11` or `pypy3.10` in workflows before those versions are released. This lessen the burden for users of `setup-python` by not having to modify their workflow twice: once when a pre-release is available (e.g. `3.11-dev`) and once when the first stable release is published (e.g. `3.11`)
This commit is contained in:
@ -51,6 +51,12 @@ describe('findRelease', () => {
|
||||
platform: process.platform,
|
||||
download_url: `https://test.download.python.org/pypy/pypy3.6-v7.3.3-${extensionName}`
|
||||
};
|
||||
const filesRC1: IPyPyManifestAsset = {
|
||||
filename: `pypy3.6-v7.4.0rc1-${extensionName}`,
|
||||
arch: architecture,
|
||||
platform: process.platform,
|
||||
download_url: `https://test.download.python.org/pypy/pypy3.6-v7.4.0rc1-${extensionName}`
|
||||
};
|
||||
|
||||
let getBooleanInputSpy: jest.SpyInstance;
|
||||
let warningSpy: jest.SpyInstance;
|
||||
@ -72,7 +78,13 @@ describe('findRelease', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = '7.3.7';
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual(null);
|
||||
});
|
||||
|
||||
@ -80,7 +92,13 @@ describe('findRelease', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = '7.3.3';
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: files,
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
@ -92,7 +110,13 @@ describe('findRelease', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = '7.x';
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: files,
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
@ -104,7 +128,13 @@ describe('findRelease', () => {
|
||||
const pythonVersion = '3.7';
|
||||
const pypyVersion = installer.pypyVersionToSemantic('7.3.3rc2');
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: {
|
||||
filename: `test${extension}`,
|
||||
@ -121,7 +151,13 @@ describe('findRelease', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = 'x';
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: files,
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
@ -129,12 +165,45 @@ describe('findRelease', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Python version and PyPy version matches semver (pre-release)', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = '7.4.x';
|
||||
expect(
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toBeNull();
|
||||
expect(
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: filesRC1,
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
resolvedPyPyVersion: '7.4.0rc1'
|
||||
});
|
||||
});
|
||||
|
||||
it('Nightly release is found', () => {
|
||||
const pythonVersion = '3.6';
|
||||
const pypyVersion = 'nightly';
|
||||
const filename = IS_WINDOWS ? 'filename.zip' : 'filename.tar.bz2';
|
||||
expect(
|
||||
installer.findRelease(releases, pythonVersion, pypyVersion, architecture)
|
||||
installer.findRelease(
|
||||
releases,
|
||||
pythonVersion,
|
||||
pypyVersion,
|
||||
architecture,
|
||||
false
|
||||
)
|
||||
).toEqual({
|
||||
foundAsset: {
|
||||
filename: filename,
|
||||
@ -224,7 +293,7 @@ describe('installPyPy', () => {
|
||||
|
||||
it('throw if release is not found', async () => {
|
||||
await expect(
|
||||
installer.installPyPy('7.3.3', '3.6.17', architecture, undefined)
|
||||
installer.installPyPy('7.3.3', '3.6.17', architecture, false, undefined)
|
||||
).rejects.toThrowError(
|
||||
`PyPy version 3.6.17 (7.3.3) with arch ${architecture} not found`
|
||||
);
|
||||
@ -244,7 +313,7 @@ describe('installPyPy', () => {
|
||||
spyChmodSync.mockImplementation(() => undefined);
|
||||
|
||||
await expect(
|
||||
installer.installPyPy('7.3.x', '3.6.12', architecture, undefined)
|
||||
installer.installPyPy('7.x', '3.6.12', architecture, false, undefined)
|
||||
).resolves.toEqual({
|
||||
installDir: path.join(toolDir, 'PyPy', '3.6.12', architecture),
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
@ -257,4 +326,31 @@ describe('installPyPy', () => {
|
||||
expect(spyCacheDir).toHaveBeenCalled();
|
||||
expect(spyExec).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('found and install PyPy, pre-release fallback', async () => {
|
||||
spyCacheDir = jest.spyOn(tc, 'cacheDir');
|
||||
spyCacheDir.mockImplementation(() =>
|
||||
path.join(toolDir, 'PyPy', '3.6.12', architecture)
|
||||
);
|
||||
|
||||
spyChmodSync = jest.spyOn(fs, 'chmodSync');
|
||||
spyChmodSync.mockImplementation(() => undefined);
|
||||
|
||||
await expect(
|
||||
installer.installPyPy('7.4.x', '3.6.12', architecture, false, undefined)
|
||||
).rejects.toThrowError();
|
||||
await expect(
|
||||
installer.installPyPy('7.4.x', '3.6.12', architecture, true, undefined)
|
||||
).resolves.toEqual({
|
||||
installDir: path.join(toolDir, 'PyPy', '3.6.12', architecture),
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
resolvedPyPyVersion: '7.4.0rc1'
|
||||
});
|
||||
|
||||
expect(spyHttpClient).toHaveBeenCalled();
|
||||
expect(spyDownloadTool).toHaveBeenCalled();
|
||||
expect(spyExistsSync).toHaveBeenCalled();
|
||||
expect(spyCacheDir).toHaveBeenCalled();
|
||||
expect(spyExec).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user