8000 set output for the installed version · actions/setup-python@49d27c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 49d27c4

Browse files
committed
set output for the installed version
1 parent 9d6ce31 commit 49d27c4

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ inputs:
99
architecture:
1010
description: 'The target architecture (x86, x64) of the Python interpreter.'
1111
default: 'x64'
12+
outputs:
13+
python-version:
14+
description: "The installed python version. Useful when given a version range as input."
1215
runs:
1316
using: 'node12'
1417
main: 'dist/index.js'

dist/index.js

Lines changed: 11 additions & 7 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -3005,7 +3005,9 @@ function usePyPy(majorVersion, architecture) {
30053005
core.exportVariable('pythonLocation', pythonLocation);
30063006
core.addPath(installDir);
30073007
core.addPath(_binDir);
3008-
return versionFromPath(installDir);
3008+
const impl = 'pypy' + majorVersion.toString();
3009+
core.setOutput('python-version', impl);
3010+
return { impl: impl, version: versionFromPath(installDir) };
30093011
}
30103012
function useCpythonVersion(version, architecture) {
30113013
return __awaiter(this, void 0, void 0, function* () {
@@ -3044,7 +3046,9 @@ function useCpythonVersion(version, architecture) {
30443046
core.addPath(userScriptsDir);
30453047
}
30463048
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
3047-
return versionFromPath(installDir);
3049+
const installed = versionFromPath(installDir);
3050+
core.setOutput('python-version', installed);
3051+
return { impl: 'CPython', version: installed };
30483052
});
30493053
}
30503054
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
@@ -3059,9 +3063,9 @@ function desugarDevVersion(versionSpec) {
30593063
}
30603064
/** Extracts python version from install path from hosted tool cache as described in README.md */
30613065
function versionFromPath(installDir) {
3062-
let parts = installDir.split(path.sep);
3063-
let idx = parts.findIndex(part => part === 'PyPy' || part === 'Python');
3064-
return parts.slice(idx, idx + 2).join(' ');
3066+
const parts = installDir.split(path.sep);
3067+
const idx = parts.findIndex(part => part === 'PyPy' || part === 'Python');
3068+
return parts[idx + 1] || '';
30653069
}
30663070
/**
30673071
* Python's prelease versions look like `3.7.0b2`.
@@ -3714,8 +3718,8 @@ function run() {
37143718
let version = core.getInput('python-version');
37153719
if (version) {
37163720
const arch = core.getInput('architecture', { required: true });
3717-
let installed = yield finder.findPythonVersion(version, arch);
3718-
console.log(`Successfully setup ${installed}.`);
3721+
const installed = yield finder.findPythonVersion(version, arch);
3722+
console.log(`Successfully setup ${installed.impl} ($ D7AF {installed.version}).`);
37193723
}
37203724
const matchersPath = path.join(__dirname, '..', '.github');
37213725
console.log(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);

src/find-python.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function binDir(installDir: string): string {
5151
// A particular version of PyPy may contain one or more versions of the Python interpreter.
5252
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
5353
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
54-
function usePyPy(majorVersion: 2 | 3, architecture: string): string {
54+
function usePyPy(majorVersion: 2 | 3, architecture: string): InstalledVersion {
5555
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
5656
let installDir: string | null = findPyPy(architecture);
5757

@@ -78,13 +78,16 @@ function usePyPy(majorVersion: 2 | 3, architecture: string): string {
7878
core.addPath(installDir);
7979
core.addPath(_binDir);
8080

81-
return versionFromPath(installDir);
81+
const impl = 'pypy' + majorVersion.toString();
82+
core.setOutput('python-version', impl);
83+
84+
return {impl: impl, version: versionFromPath(installDir)};
8285
}
8386

8487
async function useCpythonVersion(
8588
version: string,
8689
architecture: string
87-
): Promise<string> {
90+
): Promise<InstalledVersion> {
8891
const desugaredVersionSpec = desugarDevVersion(version);
8992
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
9093
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
@@ -138,7 +141,10 @@ async function useCpythonVersion(
138141
}
139142
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
140143

141-
return versionFromPath(installDir);
144+
const installed = versionFromPath(installDir);
145+
core.setOutput('python-version', installed);
146+
147+
return {impl: 'CPython', version: installed};
142148
}
143149

144150
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
@@ -153,10 +159,15 @@ function desugarDevVersion(versionSpec: string) {
153159

154160
/** Extracts python version from install path from hosted tool cache as described in README.md */
155161
function versionFromPath(installDir: string) {
156-
let parts = installDir.split(path.sep);
157-
let idx = parts.findIndex(part => part === 'PyPy' || part === 'Python');
162+
const parts = installDir.split(path.sep);
163+
const idx = parts.findIndex(part => part === 'PyPy' || part === 'Python');
164+
165+
return parts[idx + 1] || '';
166+
}
158167

159-
return parts.slice(idx, idx + 2).join(' ');
168+
interface InstalledVersion {
169+
impl: string;
170+
version: string;
160171
}
161172

162173
/**
@@ -172,7 +183,7 @@ export function pythonVersionToSemantic(versionSpec: string) {
172183
export async function findPythonVersion(
173184
version: string,
174185
architecture: string
175-
): Promise<string> {
186+
): Promise<InstalledVersion> {
176187
switch (version.toUpperCase()) {
177188
case 'PYPY2':
178189
return usePyPy(2, architecture);

src/setup-python.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ async function run() {
77
let version = core.getInput('python-version');
88
if (version) {
99
const arch: string = core.getInput('architecture', {required: true});
10-
let installed = await finder.findPythonVersion(version, arch);
11-
console.log(`Successfully setup ${installed}.`);
10+
const installed = await finder.findPythonVersion(version, arch);
11+
console.log(
12+
`Successfully setup ${installed.impl} (${installed.version}).`
13+
);
1214
}
1315
const matchersPath = path.join(__dirname, '..', '.github');
1416
console.log(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);

0 commit comments

Comments
 (0)
0