FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Throwing an error when python-version input is empty and PYTHON_VERSION_REQUIRED is set true by kmasuda050 · Pull Request #1088 · actions/setup-python · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) .md  (1) .ts  (1) .yml  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 27 additions & 0 deletions .github/workflows/test-python.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion dist/setup/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`);
Expand Down
10 changes: 10 additions & 0 deletions docs/advanced-usage.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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<python_version>[-v<pypy_version>]` or `pypy-<python_version>[-v<pypy_version>]`.
The `-v<pypy_version>` parameter is optional and can be skipped. The latest PyPy version will be used in this case.
Expand Down
14 changes: 11 additions & 3 deletions src/setup-python.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`);
Expand Down

Back | FazBrowse Home | New Git URL