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.
This commit is contained in:
Loo Zheng Yuan 2021-10-25 21:10:03 +08:00
parent feeaa3ba49
commit 34cc07ddac
No known key found for this signature in database
GPG Key ID: 6290E69DBAE908E6
2 changed files with 27 additions and 25 deletions

23
dist/index.js vendored
View File

@ -2651,17 +2651,18 @@ function isPyPyVersion(versionSpec) {
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
let version = core.getInput('python-version'); const version = core.getInput('python-version');
if (version) { if (!version) {
const arch = core.getInput('architecture') || os.arch(); throw new Error(`Invalid python version: ${version}`);
if (isPyPyVersion(version)) { }
const installed = yield finderPyPy.findPyPyVersion(version, arch); const arch = core.getInput('architecture') || os.arch();
core.info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`); if (isPyPyVersion(version)) {
} const installed = yield finderPyPy.findPyPyVersion(version, arch);
else { core.info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`);
const installed = yield finder.findPythonVersion(version, arch); }
core.info(`Successfully setup ${installed.impl} (${installed.version})`); else {
} const installed = yield finder.findPythonVersion(version, arch);
core.info(`Successfully setup ${installed.impl} (${installed.version})`);
} }
const matchersPath = path.join(__dirname, '..', '.github'); const matchersPath = path.join(__dirname, '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);

View File

@ -10,20 +10,21 @@ function isPyPyVersion(versionSpec: string) {
async function run() { async function run() {
try { try {
let version = core.getInput('python-version'); const version: string = core.getInput('python-version');
if (version) { if (!version) {
const arch: string = core.getInput('architecture') || os.arch(); throw new Error(`Invalid python version: ${version}`)
if (isPyPyVersion(version)) { }
const installed = await finderPyPy.findPyPyVersion(version, arch); const arch: string = core.getInput('architecture') || os.arch();
core.info( if (isPyPyVersion(version)) {
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` const installed = await finderPyPy.findPyPyVersion(version, arch);
); core.info(
} else { `Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
const installed = await finder.findPythonVersion(version, arch); );
core.info( } else {
`Successfully setup ${installed.impl} (${installed.version})` const installed = await finder.findPythonVersion(version, arch);
); core.info(
} `Successfully setup ${installed.impl} (${installed.version})`
);
} }
const matchersPath = path.join(__dirname, '..', '.github'); const matchersPath = path.join(__dirname, '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);