From b88a682917db311eac9aab40569d7ee9db572924 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Fri, 15 Jul 2022 16:52:20 +0200 Subject: [PATCH] Fix resolveVersionInput() logic --- dist/setup/index.js | 15 +++++++++------ src/setup-python.ts | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 9ac89a4f..57bd35fe 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65262,17 +65262,20 @@ function resolveVersionInput() { } if (versionFile) { if (!fs_1.default.existsSync(versionFile)) { - logWarning(`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`); - versionFile = '.python-version'; - if (!fs_1.default.existsSync(versionFile)) { - throw new Error(`The ${versionFile} doesn't exist.`); - } + throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`); } version = fs_1.default.readFileSync(versionFile, 'utf8'); core.info(`Resolved ${versionFile} as ${version}`); return version; } - core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied."); + logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."); + versionFile = '.python-version'; + if (fs_1.default.existsSync(versionFile)) { + version = fs_1.default.readFileSync(versionFile, 'utf8'); + core.info(`Resolved ${versionFile} as ${version}`); + return version; + } + logWarning(`${versionFile} doesn't exist.`); return version; } function run() { diff --git a/src/setup-python.ts b/src/setup-python.ts index db17735b..23356889 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -38,24 +38,26 @@ function resolveVersionInput(): string { if (versionFile) { if (!fs.existsSync(versionFile)) { - logWarning( - `The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.` + throw new Error( + `The specified python version file at: ${versionFile} doesn't exist.` ); - versionFile = '.python-version'; - if (!fs.existsSync(versionFile)) { - throw new Error(`The ${versionFile} doesn't exist.`); - } } - 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." + logWarning( + "Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file." ); + versionFile = '.python-version'; + if (fs.existsSync(versionFile)) { + version = fs.readFileSync(versionFile, 'utf8'); + core.info(`Resolved ${versionFile} as ${version}`); + return version; + } + + logWarning(`${versionFile} doesn't exist.`); return version; }