From 35853705fb9f01a35d81413a33317548b2497ffc Mon Sep 17 00:00:00 2001 From: Kazuhiro Masuda Date: Fri, 18 Apr 2025 18:16:15 +0900 Subject: [PATCH 1/4] 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 ec5261efc..2c450a642 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 ab5931b82..fd3037211 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')}`); From 7c49ba0e44ac46db87d28d2bd6ef0370a16f6985 Mon Sep 17 00:00:00 2001 From: Kazuhiro Masuda Date: Mon, 21 Apr 2025 00:36:14 +0900 Subject: [PATCH 2/4] Tweak --- 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 2c450a642..4febd9757 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -97735,7 +97735,7 @@ function run() { 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.`); + throw new Error('The `python-version` input is required.'); } } const matchersPath = path.join(__dirname, '../..', '.github'); diff --git a/src/setup-python.ts b/src/setup-python.ts index fd3037211..1d3948853 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -154,7 +154,7 @@ async function run() { ); } else { throw new Error( - `The python-version input is required.` + 'The `python-version` input is required.' ); } } From 34240e253f06f8a3369abbe03a2d922db6bc2b66 Mon Sep 17 00:00:00 2001 From: Kazuhiro Masuda Date: Mon, 21 Apr 2025 00:36:35 +0900 Subject: [PATCH 3/4] Add test --- .github/workflows/test-python.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index d89646f30..c701e74b4 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -505,3 +505,30 @@ jobs: } $pythonVersion shell: pwsh + + setup-python-version-required: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + [ + macos-latest, + windows-latest, + ubuntu-22.04, + ubuntu-22.04-arm, + ubuntu-24.04-arm, + ubuntu-latest, + macos-13 + ] + steps: + - uses: actions/checkout@v4 + - name: Setup Python + id: setup-python + uses: ./ + env: + PYTHON_VERSION_REQUIRED: true + continue-on-error: true + - name: Validate failure + if: steps.setup-python.outcome != 'failure' + run: exit 1 From 3a69c5f668b2214f6cb5583d9609a69358d337b5 Mon Sep 17 00:00:00 2001 From: Kazuhiro Masuda Date: Mon, 21 Apr 2025 00:53:13 +0900 Subject: [PATCH 4/4] Update documentation --- docs/advanced-usage.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 72b350169..7f252ead3 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -138,6 +138,16 @@ steps: ``` Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [semver](https://github.com/npm/node-semver) to check other available range syntaxes. +If you want to make an error when unspecified, set `PYTHON_VERSION_REQUIRED: true` to env. +```yaml +steps: +- uses: actions/checkout@v4 +- uses: actions/setup-python@v5 + env: + PYTHON_VERSION_REQUIRED: true + # the action fail with error. +``` + ### Specifying a PyPy version The version of PyPy should be specified in the format `pypy[-v]` or `pypy-[-v]`. The `-v` parameter is optional and can be skipped. The latest PyPy version will be used in this case.