mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-10 13:22: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:
parent
a6eba85bba
commit
2652534ead
14 changed files with 524 additions and 61 deletions
|
@ -34,11 +34,15 @@ export async function useCpythonVersion(
|
|||
version: string,
|
||||
architecture: string,
|
||||
updateEnvironment: boolean,
|
||||
checkLatest: boolean
|
||||
checkLatest: boolean,
|
||||
allowPreReleases: boolean
|
||||
): Promise<InstalledVersion> {
|
||||
let manifest: tc.IToolRelease[] | null = null;
|
||||
const desugaredVersionSpec = desugarDevVersion(version);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(
|
||||
desugaredVersionSpec,
|
||||
allowPreReleases
|
||||
);
|
||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||
|
||||
if (checkLatest) {
|
||||
|
@ -178,8 +182,18 @@ interface InstalledVersion {
|
|||
* Python's prelease versions look like `3.7.0b2`.
|
||||
* This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
|
||||
* If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent.
|
||||
*
|
||||
* For easier use of the action, we also map 'x.y' to allow pre-release before 'x.y.0' release if allowPreReleases is true
|
||||
*/
|
||||
export function pythonVersionToSemantic(versionSpec: string) {
|
||||
export function pythonVersionToSemantic(
|
||||
versionSpec: string,
|
||||
allowPreReleases: boolean
|
||||
) {
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc)\d*)/g;
|
||||
return versionSpec.replace(prereleaseVersion, '$1-$2');
|
||||
const majorMinor = /^(\d+)\.(\d+)$/;
|
||||
let result = versionSpec.replace(prereleaseVersion, '$1-$2');
|
||||
if (allowPreReleases) {
|
||||
result = result.replace(majorMinor, '~$1.$2.0-0');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue