From afd3e72a25e35f57d63421163b2bfa536eded186 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 13:38:43 +0200 Subject: [PATCH] Fix bug in resolveVersionInput() --- dist/setup/index.js | 22 +++++++++++++++++----- src/setup-python.ts | 32 ++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b98b9af2..e7cfc7a1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64471,12 +64471,24 @@ function resolveVersionInput() { if (version) { return version; } - versionFile = versionFile || '.python-version'; - if (!fs_1.default.existsSync(versionFile)) { - throw new Error(`The specified python version file at: ${versionFile} does not exist`); + if (versionFile) { + const defaultVersionFile = '.python-version'; + const VersionFileExists = fs_1.default.existsSync(versionFile); + const defaultVersionFileExists = fs_1.default.existsSync(defaultVersionFile); + 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_1.default.readFileSync(versionFile, 'utf8'); + core.info(`Resolved ${versionFile} as ${version}`); + } + else { + version = fs_1.default.readFileSync('.python-version', 'utf8'); + core.info(`Resolved ${'.python-version'} as ${version}`); + } + return version; } - version = fs_1.default.readFileSync(versionFile, 'utf8'); - core.info(`Resolved ${versionFile} as ${version}`); + core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied. "); return version; } function run() { diff --git a/src/setup-python.ts b/src/setup-python.ts index a7728714..97efe538 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -36,15 +36,31 @@ function resolveVersionInput(): string { return version; } - versionFile = versionFile || '.python-version'; - if (!fs.existsSync(versionFile)) { - throw new Error( - `The specified python version file at: ${versionFile} does not exist` - ); - } - version = fs.readFileSync(versionFile, 'utf8'); - core.info(`Resolved ${versionFile} as ${version}`); + if (versionFile) { + const defaultVersionFile = '.python-version'; + const VersionFileExists = fs.existsSync(versionFile); + const defaultVersionFileExists = fs.existsSync(defaultVersionFile); + + 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('.python-version', 'utf8'); + core.info(`Resolved ${'.python-version'} as ${version}`); + } + + return version; + } + + core.warning( + "Neither 'python-version' nor 'python-version-file' inputs were supplied. " + ); return version; }