mirror of
https://github.com/actions/setup-python.git
synced 2025-07-05 00:53:46 +00:00
add check-latest for pypy
This commit is contained in:
parent
58a8109aea
commit
8723b8aa5a
8 changed files with 165 additions and 31 deletions
|
@ -6,7 +6,8 @@ import {
|
|||
validateVersion,
|
||||
getPyPyVersionFromPath,
|
||||
readExactPyPyVersionFile,
|
||||
validatePythonVersionFormatForPyPy
|
||||
validatePythonVersionFormatForPyPy,
|
||||
IPyPyManifestRelease
|
||||
} from './utils';
|
||||
|
||||
import * as semver from 'semver';
|
||||
|
@ -20,14 +21,36 @@ interface IPyPyVersionSpec {
|
|||
|
||||
export async function findPyPyVersion(
|
||||
versionSpec: string,
|
||||
architecture: string
|
||||
architecture: string,
|
||||
checkLatest: boolean
|
||||
): Promise<{resolvedPyPyVersion: string; resolvedPythonVersion: string}> {
|
||||
let resolvedPyPyVersion = '';
|
||||
let resolvedPythonVersion = '';
|
||||
let installDir: string | null;
|
||||
let releases: IPyPyManifestRelease[] | undefined;
|
||||
|
||||
const pypyVersionSpec = parsePyPyVersion(versionSpec);
|
||||
|
||||
if (checkLatest) {
|
||||
releases = await pypyInstall.getAvailablePyPyVersions();
|
||||
if (releases && releases.length > 0) {
|
||||
const releaseData = pypyInstall.findRelease(
|
||||
releases,
|
||||
pypyVersionSpec.pythonVersion,
|
||||
pypyVersionSpec.pypyVersion,
|
||||
architecture
|
||||
);
|
||||
|
||||
if(releaseData) {
|
||||
core.info(`Resolved as PyPy ${releaseData.resolvedPyPyVersion} with Python (${releaseData.resolvedPythonVersion})`);
|
||||
pypyVersionSpec.pythonVersion = releaseData.resolvedPythonVersion;
|
||||
pypyVersionSpec.pypyVersion = releaseData.resolvedPyPyVersion;
|
||||
} else {
|
||||
core.info(`Failed to resolve PyPy ${pypyVersionSpec.pypyVersion} with Python (${pypyVersionSpec.pythonVersion}) from manifest`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
({installDir, resolvedPythonVersion, resolvedPyPyVersion} = findPyPyToolCache(
|
||||
pypyVersionSpec.pythonVersion,
|
||||
pypyVersionSpec.pypyVersion,
|
||||
|
@ -42,7 +65,8 @@ export async function findPyPyVersion(
|
|||
} = await pypyInstall.installPyPy(
|
||||
pypyVersionSpec.pypyVersion,
|
||||
pypyVersionSpec.pythonVersion,
|
||||
architecture
|
||||
architecture,
|
||||
releases
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -32,15 +32,14 @@ function binDir(installDir: string): string {
|
|||
|
||||
export async function useCpythonVersion(
|
||||
version: string,
|
||||
architecture: string
|
||||
architecture: string,
|
||||
checkLatest: boolean
|
||||
): Promise<InstalledVersion> {
|
||||
let manifest: tc.IToolRelease[] | null = null;
|
||||
const desugaredVersionSpec = desugarDevVersion(version);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
|
||||
if (checkLatest) {
|
||||
manifest = await installer.getManifest();
|
||||
const resolvedVersion = (await installer.findReleaseFromManifest(semanticVersionSpec, architecture, manifest))?.version;
|
||||
|
|
|
@ -19,11 +19,12 @@ import {
|
|||
export async function installPyPy(
|
||||
pypyVersion: string,
|
||||
pythonVersion: string,
|
||||
architecture: string
|
||||
architecture: string,
|
||||
releases: IPyPyManifestRelease[] | undefined
|
||||
) {
|
||||
let downloadDir;
|
||||
|
||||
const releases = await getAvailablePyPyVersions();
|
||||
releases ??= await getAvailablePyPyVersions();
|
||||
if (!releases || releases.length === 0) {
|
||||
throw new Error('No release was found in PyPy version.json');
|
||||
}
|
||||
|
@ -78,7 +79,7 @@ export async function installPyPy(
|
|||
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
|
||||
}
|
||||
|
||||
async function getAvailablePyPyVersions() {
|
||||
export async function getAvailablePyPyVersions() {
|
||||
const url = 'https://downloads.python.org/pypy/versions.json';
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
|
||||
|
||||
|
|
|
@ -34,17 +34,18 @@ async function run() {
|
|||
}
|
||||
try {
|
||||
const version = core.getInput('python-version');
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
if (version) {
|
||||
let pythonVersion: string;
|
||||
const arch: string = core.getInput('architecture') || os.arch();
|
||||
if (isPyPyVersion(version)) {
|
||||
const installed = await finderPyPy.findPyPyVersion(version, arch);
|
||||
const installed = await finderPyPy.findPyPyVersion(version, arch, checkLatest);
|
||||
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`;
|
||||
core.info(
|
||||
`Successfully set up PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
|
||||
);
|
||||
} else {
|
||||
const installed = await finder.useCpythonVersion(version, arch);
|
||||
const installed = await finder.useCpythonVersion(version, arch, checkLatest);
|
||||
pythonVersion = installed.version;
|
||||
core.info(`Successfully set up ${installed.impl} (${pythonVersion})`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue