output installed version number after setup (#51)
* output installed version number after setup * set output for the installed version
This commit is contained in:
parent
ebe4d7eb5f
commit
f8fb48e9f7
|
@ -9,6 +9,9 @@ inputs:
|
||||||
architecture:
|
architecture:
|
||||||
description: 'The target architecture (x86, x64) of the Python interpreter.'
|
description: 'The target architecture (x86, x64) of the Python interpreter.'
|
||||||
default: 'x64'
|
default: 'x64'
|
||||||
|
outputs:
|
||||||
|
python-version:
|
||||||
|
description: "The installed python version. Useful when given a version range as input."
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -51,7 +51,7 @@ function binDir(installDir: string): string {
|
||||||
// A particular version of PyPy may contain one or more versions of the Python interpreter.
|
// A particular version of PyPy may contain one or more versions of the Python interpreter.
|
||||||
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
|
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
|
||||||
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
|
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
|
||||||
function usePyPy(majorVersion: 2 | 3, architecture: string): void {
|
function usePyPy(majorVersion: 2 | 3, architecture: string): InstalledVersion {
|
||||||
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
|
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
|
||||||
let installDir: string | null = findPyPy(architecture);
|
let installDir: string | null = findPyPy(architecture);
|
||||||
|
|
||||||
|
@ -77,12 +77,17 @@ function usePyPy(majorVersion: 2 | 3, architecture: string): void {
|
||||||
|
|
||||||
core.addPath(installDir);
|
core.addPath(installDir);
|
||||||
core.addPath(_binDir);
|
core.addPath(_binDir);
|
||||||
|
|
||||||
|
const impl = 'pypy' + majorVersion.toString();
|
||||||
|
core.setOutput('python-version', impl);
|
||||||
|
|
||||||
|
return {impl: impl, version: versionFromPath(installDir)};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function useCpythonVersion(
|
async function useCpythonVersion(
|
||||||
version: string,
|
version: string,
|
||||||
architecture: string
|
architecture: string
|
||||||
): Promise<void> {
|
): Promise<InstalledVersion> {
|
||||||
const desugaredVersionSpec = desugarDevVersion(version);
|
const desugaredVersionSpec = desugarDevVersion(version);
|
||||||
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
||||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||||
|
@ -135,6 +140,11 @@ async function useCpythonVersion(
|
||||||
core.addPath(userScriptsDir);
|
core.addPath(userScriptsDir);
|
||||||
}
|
}
|
||||||
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
|
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
|
||||||
|
|
||||||
|
const installed = versionFromPath(installDir);
|
||||||
|
core.setOutput('python-version', installed);
|
||||||
|
|
||||||
|
return {impl: 'CPython', version: installed};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
|
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
|
||||||
|
@ -147,6 +157,19 @@ function desugarDevVersion(versionSpec: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Extracts python version from install path from hosted tool cache as described in README.md */
|
||||||
|
function versionFromPath(installDir: string) {
|
||||||
|
const parts = installDir.split(path.sep);
|
||||||
|
const idx = parts.findIndex(part => part === 'PyPy' || part === 'Python');
|
||||||
|
|
||||||
|
return parts[idx + 1] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InstalledVersion {
|
||||||
|
impl: string;
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Python's prelease versions look like `3.7.0b2`.
|
* 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`.
|
* This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
|
||||||
|
@ -160,7 +183,7 @@ export function pythonVersionToSemantic(versionSpec: string) {
|
||||||
export async function findPythonVersion(
|
export async function findPythonVersion(
|
||||||
version: string,
|
version: string,
|
||||||
architecture: string
|
architecture: string
|
||||||
): Promise<void> {
|
): Promise<InstalledVersion> {
|
||||||
switch (version.toUpperCase()) {
|
switch (version.toUpperCase()) {
|
||||||
case 'PYPY2':
|
case 'PYPY2':
|
||||||
return usePyPy(2, architecture);
|
return usePyPy(2, architecture);
|
||||||
|
|
|
@ -7,7 +7,10 @@ async function run() {
|
||||||
let version = core.getInput('python-version');
|
let version = core.getInput('python-version');
|
||||||
if (version) {
|
if (version) {
|
||||||
const arch: string = core.getInput('architecture', {required: true});
|
const arch: string = core.getInput('architecture', {required: true});
|
||||||
await finder.findPythonVersion(version, arch);
|
const installed = await finder.findPythonVersion(version, arch);
|
||||||
|
console.log(
|
||||||
|
`Successfully setup ${installed.impl} (${installed.version}).`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);
|
||||||
|
|
Loading…
Reference in New Issue