From 34cc07ddacc872506803d9640b2da3fea2261ad7 Mon Sep 17 00:00:00 2001 From: Loo Zheng Yuan Date: Mon, 25 Oct 2021 21:10:03 +0800 Subject: [PATCH] fix: non-zero exit code for falsey version This commit fixes an issue where an empty string input for the 'python-version' input parameter succeeds silently without installing any versions. --- dist/index.js | 23 ++++++++++++----------- src/setup-python.ts | 29 +++++++++++++++-------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/dist/index.js b/dist/index.js index 16cab227..d62a139c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2651,17 +2651,18 @@ function isPyPyVersion(versionSpec) { function run() { return __awaiter(this, void 0, void 0, function* () { try { - let version = core.getInput('python-version'); - if (version) { - const arch = core.getInput('architecture') || os.arch(); - if (isPyPyVersion(version)) { - const installed = yield finderPyPy.findPyPyVersion(version, arch); - core.info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`); - } - else { - const installed = yield finder.findPythonVersion(version, arch); - core.info(`Successfully setup ${installed.impl} (${installed.version})`); - } + const version = core.getInput('python-version'); + if (!version) { + throw new Error(`Invalid python version: ${version}`); + } + const arch = core.getInput('architecture') || os.arch(); + if (isPyPyVersion(version)) { + const installed = yield finderPyPy.findPyPyVersion(version, arch); + core.info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`); + } + else { + const installed = yield finder.findPythonVersion(version, arch); + core.info(`Successfully setup ${installed.impl} (${installed.version})`); } const matchersPath = path.join(__dirname, '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); diff --git a/src/setup-python.ts b/src/setup-python.ts index 15e46956..4a089feb 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -10,20 +10,21 @@ function isPyPyVersion(versionSpec: string) { async function run() { try { - let version = core.getInput('python-version'); - if (version) { - const arch: string = core.getInput('architecture') || os.arch(); - if (isPyPyVersion(version)) { - const installed = await finderPyPy.findPyPyVersion(version, arch); - core.info( - `Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` - ); - } else { - const installed = await finder.findPythonVersion(version, arch); - core.info( - `Successfully setup ${installed.impl} (${installed.version})` - ); - } + const version: string = core.getInput('python-version'); + if (!version) { + throw new Error(`Invalid python version: ${version}`) + } + const arch: string = core.getInput('architecture') || os.arch(); + if (isPyPyVersion(version)) { + const installed = await finderPyPy.findPyPyVersion(version, arch); + core.info( + `Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` + ); + } else { + const installed = await finder.findPythonVersion(version, arch); + core.info( + `Successfully setup ${installed.impl} (${installed.version})` + ); } const matchersPath = path.join(__dirname, '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);