From 35853705fb9f01a35d81413a33317548b2497ffc Mon Sep 17 00:00:00 2001 From: Kazuhiro Masuda Date: Fri, 18 Apr 2025 18:16:15 +0900 Subject: [PATCH] Throwing an error when python-version input is empty and PYTHON_VERSION_REQUIRED is set true --- dist/setup/index.js | 9 ++++++++- src/setup-python.ts | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ec5261ef..2c450a64 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -97729,7 +97729,14 @@ function run() { } } else { - core.warning('The `python-version` input is not set. The version of Python currently in `PATH` will be used.'); + const trueValue = ['true', 'True', 'TRUE']; + const pythonVersionRequired = process.env['PYTHON_VERSION_REQUIRED'] || ''; + if (!trueValue.includes(pythonVersionRequired)) { + core.warning('The `python-version` input is not set. The version of Python currently in `PATH` will be used.'); + } + else { + throw new Error(`The python-version input is required.`); + } } const matchersPath = path.join(__dirname, '../..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); diff --git a/src/setup-python.ts b/src/setup-python.ts index ab5931b8..fd303721 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -146,9 +146,17 @@ async function run() { await cacheDependencies(cache, pythonVersion); } } else { - core.warning( - 'The `python-version` input is not set. The version of Python currently in `PATH` will be used.' - ); + const trueValue = ['true', 'True', 'TRUE']; + const pythonVersionRequired = process.env['PYTHON_VERSION_REQUIRED'] || ''; + if(!trueValue.includes(pythonVersionRequired)) { + core.warning( + 'The `python-version` input is not set. The version of Python currently in `PATH` will be used.' + ); + } else { + throw new Error( + `The python-version input is required.` + ); + } } const matchersPath = path.join(__dirname, '../..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);