1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-python synced 2025-06-09 12:52:20 +02: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:
Matthieu Darbois 2023-01-27 22:19:31 +01:00 committed by GitHub
parent a6eba85bba
commit 2652534ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 524 additions and 61 deletions

View file

@ -1,3 +1,4 @@
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
@ -19,6 +20,7 @@ export async function installPyPy(
pypyVersion: string,
pythonVersion: string,
architecture: string,
allowPreReleases: boolean,
releases: IPyPyManifestRelease[] | undefined
) {
let downloadDir;
@ -29,13 +31,31 @@ export async function installPyPy(
throw new Error('No release was found in PyPy version.json');
}
const releaseData = findRelease(
let releaseData = findRelease(
releases,
pythonVersion,
pypyVersion,
architecture
architecture,
false
);
if (allowPreReleases && (!releaseData || !releaseData.foundAsset)) {
// check for pre-release
core.info(
[
`Stable PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`,
`Trying pre-release versions`
].join(os.EOL)
);
releaseData = findRelease(
releases,
pythonVersion,
pypyVersion,
architecture,
true
);
}
if (!releaseData || !releaseData.foundAsset) {
throw new Error(
`PyPy version ${pythonVersion} (${pypyVersion}) with arch ${architecture} not found`
@ -162,8 +182,10 @@ export function findRelease(
releases: IPyPyManifestRelease[],
pythonVersion: string,
pypyVersion: string,
architecture: string
architecture: string,
includePrerelease: boolean
) {
const options = {includePrerelease: includePrerelease};
const filterReleases = releases.filter(item => {
const isPythonVersionSatisfied = semver.satisfies(
semver.coerce(item.python_version)!,
@ -173,7 +195,11 @@ export function findRelease(
isNightlyKeyword(pypyVersion) && isNightlyKeyword(item.pypy_version);
const isPyPyVersionSatisfied =
isPyPyNightly ||
semver.satisfies(pypyVersionToSemantic(item.pypy_version), pypyVersion);
semver.satisfies(
pypyVersionToSemantic(item.pypy_version),
pypyVersion,
options
);
const isArchPresent =
item.files &&
(IS_WINDOWS