From 84087f5301387d405e78745351baf99179125d2b Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 16:21:14 +0200 Subject: [PATCH] Rearrange logic --- src/setup-python.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/setup-python.ts b/src/setup-python.ts index 62cee96d..ec1fcd89 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -39,28 +39,32 @@ function resolveVersionInput(): string { if (versionFile) { const defaultVersionFile = '.python-version'; - const versionFileExists = fs.existsSync(versionFile); - const defaultVersionFileExists = fs.existsSync(defaultVersionFile); + if (!fs.existsSync(versionFile)) { + if (versionFile === defaultVersionFile) { + throw new Error( + `The specified python version file at: ${versionFile} does not exist.` + ); + } - if (!versionFileExists && !defaultVersionFileExists) { - throw new Error( - `The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found` - ); - } - if (versionFileExists) { - version = fs.readFileSync(versionFile, 'utf8'); - core.info(`Resolved ${versionFile} as ${version}`); - } else { - version = fs.readFileSync(defaultVersionFile, 'utf8'); - core.info(`Resolved ${defaultVersionFile} as ${version}`); + if (fs.existsSync(defaultVersionFile)) { + versionFile = defaultVersionFile; + } else { + throw new Error( + `The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found` + ); + } } + version = fs.readFileSync(versionFile, 'utf8'); + core.info(`Resolved ${versionFile} as ${version}`); + return version; } core.warning( "Neither 'python-version' nor 'python-version-file' inputs were supplied. " ); + return version; }