From afd3e72a25e35f57d63421163b2bfa536eded186 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 13:38:43 +0200 Subject: [PATCH 01/10] 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; } From 6733fc44ecfb2ab941c4b659afcfb87d2836391d Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 13:44:10 +0200 Subject: [PATCH 02/10] Fix typo --- dist/setup/index.js | 4 ++-- src/setup-python.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e7cfc7a1..9ca5fb7c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64483,8 +64483,8 @@ function resolveVersionInput() { core.info(`Resolved ${versionFile} as ${version}`); } else { - version = fs_1.default.readFileSync('.python-version', 'utf8'); - core.info(`Resolved ${'.python-version'} as ${version}`); + version = fs_1.default.readFileSync(defaultVersionFile, 'utf8'); + core.info(`Resolved ${defaultVersionFile} as ${version}`); } return version; } diff --git a/src/setup-python.ts b/src/setup-python.ts index 97efe538..58ebd8d0 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -51,8 +51,8 @@ function resolveVersionInput(): string { 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}`); + version = fs.readFileSync(defaultVersionFile, 'utf8'); + core.info(`Resolved ${defaultVersionFile} as ${version}`); } return version; From 56f6060254e1c762cbbe5d69d3831ab68d2ee2ac Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 14:41:09 +0200 Subject: [PATCH 03/10] Fix naming --- src/setup-python.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/setup-python.ts b/src/setup-python.ts index 58ebd8d0..62cee96d 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -39,15 +39,15 @@ function resolveVersionInput(): string { if (versionFile) { const defaultVersionFile = '.python-version'; - const VersionFileExists = fs.existsSync(versionFile); + const versionFileExists = fs.existsSync(versionFile); const defaultVersionFileExists = fs.existsSync(defaultVersionFile); - if (!VersionFileExists && !defaultVersionFileExists) { + 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) { + if (versionFileExists) { version = fs.readFileSync(versionFile, 'utf8'); core.info(`Resolved ${versionFile} as ${version}`); } else { From 84087f5301387d405e78745351baf99179125d2b Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 16:21:14 +0200 Subject: [PATCH 04/10] 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; } From a6b01c4e407b1f7787010fb1e61a07c065555209 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 16:22:51 +0200 Subject: [PATCH 05/10] Rebuild action with new changes --- dist/setup/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2b48b607..5ab9c899 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65270,19 +65270,19 @@ function resolveVersionInput() { } 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(defaultVersionFile, 'utf8'); - core.info(`Resolved ${defaultVersionFile} as ${version}`); + if (!fs_1.default.existsSync(versionFile)) { + if (versionFile === defaultVersionFile) { + throw new Error(`The specified python version file at: ${versionFile} does not exist.`); + } + if (fs_1.default.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_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. "); From d97b6edda3da1f628f85b7105cb690790e86c149 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 16:25:46 +0200 Subject: [PATCH 06/10] Fix typos --- dist/setup/index.js | 6 +++--- src/setup-python.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 5ab9c899..43d4cfbb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65263,7 +65263,7 @@ function resolveVersionInput() { let version = core.getInput('python-version'); let versionFile = core.getInput('python-version-file'); if (version && versionFile) { - core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used'); + core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used.'); } if (version) { return version; @@ -65278,14 +65278,14 @@ function resolveVersionInput() { versionFile = defaultVersionFile; } else { - throw new Error(`The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found`); + throw new Error(`The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found.`); } } 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. "); + 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 ec1fcd89..fea50e13 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -28,7 +28,7 @@ function resolveVersionInput(): string { if (version && versionFile) { core.warning( - 'Both python-version and python-version-file inputs are specified, only python-version will be used' + 'Both python-version and python-version-file inputs are specified, only python-version will be used.' ); } @@ -50,7 +50,7 @@ function resolveVersionInput(): string { versionFile = defaultVersionFile; } else { throw new Error( - `The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found` + `The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found.` ); } } @@ -62,7 +62,7 @@ function resolveVersionInput(): string { } core.warning( - "Neither 'python-version' nor 'python-version-file' inputs were supplied. " + "Neither 'python-version' nor 'python-version-file' inputs were supplied." ); return version; From 82eddc4023a579965135122e83230730392b1064 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 16:34:29 +0200 Subject: [PATCH 07/10] Add warning in case the versionFile isn't found --- dist/setup/index.js | 1 + src/setup-python.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 43d4cfbb..f4394233 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65275,6 +65275,7 @@ function resolveVersionInput() { throw new Error(`The specified python version file at: ${versionFile} does not exist.`); } if (fs_1.default.existsSync(defaultVersionFile)) { + core.warning(`The specified python version file at: ${versionFile} does not exist. Attempting to find ${defaultVersionFile} file.`); versionFile = defaultVersionFile; } else { diff --git a/src/setup-python.ts b/src/setup-python.ts index fea50e13..c4db766f 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -47,6 +47,9 @@ function resolveVersionInput(): string { } if (fs.existsSync(defaultVersionFile)) { + core.warning( + `The specified python version file at: ${versionFile} does not exist. Attempting to find ${defaultVersionFile} file.` + ); versionFile = defaultVersionFile; } else { throw new Error( From 5fbb8194072b461a0b699e47c3d444b39e33bb8a Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 17:32:12 +0200 Subject: [PATCH 08/10] Optimize logic, rebuild action --- dist/setup/index.js | 20 +++++++++++--------- src/setup-python.ts | 27 ++++++++++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index f4394233..474ce59f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65241,6 +65241,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.logWarning = void 0; const core = __importStar(__nccwpck_require__(2186)); const finder = __importStar(__nccwpck_require__(9996)); const finderPyPy = __importStar(__nccwpck_require__(4003)); @@ -65269,24 +65270,20 @@ function resolveVersionInput() { return version; } if (versionFile) { - const defaultVersionFile = '.python-version'; if (!fs_1.default.existsSync(versionFile)) { - if (versionFile === defaultVersionFile) { - throw new Error(`The specified python version file at: ${versionFile} does not exist.`); - } - if (fs_1.default.existsSync(defaultVersionFile)) { - core.warning(`The specified python version file at: ${versionFile} does not exist. Attempting to find ${defaultVersionFile} file.`); - versionFile = defaultVersionFile; + logWarning(`The specified python version file at: ${versionFile} does not exist. Attempting to find .python-version file.`); + if (!fs_1.default.existsSync('.python-version')) { + throw new Error(`The specified python version file at: ${versionFile} does not exist and default .python-version file isn't found.`); } else { - throw new Error(`The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found.`); + versionFile = '.python-version'; } } 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."); return version; } function run() { @@ -65331,6 +65328,11 @@ function run() { } }); } +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; run(); diff --git a/src/setup-python.ts b/src/setup-python.ts index c4db766f..22c407ba 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -37,24 +37,16 @@ function resolveVersionInput(): string { } if (versionFile) { - const defaultVersionFile = '.python-version'; - if (!fs.existsSync(versionFile)) { - if (versionFile === defaultVersionFile) { + logWarning( + `The specified python version file at: ${versionFile} does not exist. Attempting to find .python-version file.` + ); + if (!fs.existsSync('.python-version')) { throw new Error( - `The specified python version file at: ${versionFile} does not exist.` + `The specified python version file at: ${versionFile} does not exist and default .python-version file isn't found.` ); - } - - if (fs.existsSync(defaultVersionFile)) { - core.warning( - `The specified python version file at: ${versionFile} does not exist. Attempting to find ${defaultVersionFile} file.` - ); - versionFile = defaultVersionFile; } else { - throw new Error( - `The specified python version file at: ${versionFile} does not exist and default ${defaultVersionFile} file isn't found.` - ); + versionFile = '.python-version'; } } @@ -64,7 +56,7 @@ function resolveVersionInput(): string { return version; } - core.warning( + logWarning( "Neither 'python-version' nor 'python-version-file' inputs were supplied." ); @@ -124,4 +116,9 @@ async function run() { } } +export function logWarning(message: string): void { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} + run(); From ccb7da8ae999f3923ec3f9ed841e83fd0e332963 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 18:28:17 +0200 Subject: [PATCH 09/10] Change warning handler to default --- dist/setup/index.js | 2 +- src/setup-python.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 474ce59f..078ff004 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65283,7 +65283,7 @@ function resolveVersionInput() { core.info(`Resolved ${versionFile} as ${version}`); return version; } - logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied."); + 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 22c407ba..f1171f92 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -56,7 +56,7 @@ function resolveVersionInput(): string { return version; } - logWarning( + core.warning( "Neither 'python-version' nor 'python-version-file' inputs were supplied." ); From 099ed898be0c04ebc3fdcd7c440ad36781523a46 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Thu, 30 Jun 2022 18:42:04 +0200 Subject: [PATCH 10/10] Optimize code --- dist/setup/index.js | 10 ++++------ src/setup-python.ts | 11 ++++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 078ff004..9f8f0d51 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -65271,12 +65271,10 @@ function resolveVersionInput() { } if (versionFile) { if (!fs_1.default.existsSync(versionFile)) { - logWarning(`The specified python version file at: ${versionFile} does not exist. Attempting to find .python-version file.`); - if (!fs_1.default.existsSync('.python-version')) { - throw new Error(`The specified python version file at: ${versionFile} does not exist and default .python-version file isn't found.`); - } - else { - versionFile = '.python-version'; + 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.`); } } version = fs_1.default.readFileSync(versionFile, 'utf8'); diff --git a/src/setup-python.ts b/src/setup-python.ts index f1171f92..55bf4971 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -39,14 +39,11 @@ function resolveVersionInput(): string { if (versionFile) { if (!fs.existsSync(versionFile)) { logWarning( - `The specified python version file at: ${versionFile} does not exist. Attempting to find .python-version file.` + `The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.` ); - if (!fs.existsSync('.python-version')) { - throw new Error( - `The specified python version file at: ${versionFile} does not exist and default .python-version file isn't found.` - ); - } else { - versionFile = '.python-version'; + versionFile = '.python-version'; + if (!fs.existsSync(versionFile)) { + throw new Error(`The ${versionFile} doesn't exist.`); } }