Skip to content

Commit 7ef29f1

Browse files
authored
Allow caller workflows to use pyproject.toml files as the source of the Python version (#216)
* feat: Add the ability for calling workflows to specify to use the Python version stored in the pyproject.toml file instead of hard-coding the Python version in the workflows as well * docs: Updated the changelog * fix: Add known words to avoid doc build failures
1 parent 91e0f54 commit 7ef29f1

File tree

8 files changed

+40
-17
lines changed

8 files changed

+40
-17
lines changed

.github/workflows/_reusable-test-code.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ on:
99
required: true
1010
type: string
1111
python-versions-array:
12-
description: A valid JSON array of Python versions to test against.
12+
description: A valid JSON array of Python versions to test against. A valid
13+
option is also the string 'pyproject.toml', indicating to use the defined
14+
Python version from the pyproject.toml file.
1315
required: true
1416
type: string
1517
operating-systems-array:
@@ -46,11 +48,18 @@ jobs:
4648
with:
4749
node-version: lts/*
4850
check-latest: true
49-
- name: Set up Python ${{ matrix.python-version }}
51+
- name: Set up Python (version)
52+
if: ${{ matrix.python-version != 'pyproject.toml' }}
5053
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
5154
with:
5255
python-version: ${{ matrix.python-version }}
5356
check-latest: true
57+
- name: Set up Python (pyproject.toml)
58+
if: ${{ matrix.python-version == 'pyproject.toml' }}
59+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
60+
with:
61+
python-version-file: ${{ matrix.python-version }}
62+
check-latest: true
5463
- name: Install dependencies
5564
run: python -m pip install tox tox-gh-actions
5665
- name: Set up pre-commit cache

.github/workflows/_reusable-test-docs.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
required: true
99
type: number
1010
python-version:
11-
description: The version of Python to install.
11+
description: The version of Python to install. It can also be the string 'pyproject.toml',
12+
indicating to use the defined Python version from the pyproject.toml file.
1213
required: true
1314
type: string
1415
tox-env-array:
@@ -35,11 +36,18 @@ jobs:
3536
run: |
3637
npm install --global @mermaid-js/mermaid-cli
3738
sudo apt install --no-install-recommends --assume-yes graphviz
38-
- name: Set up Python
39+
- name: Set up Python (version)
40+
if: ${{ inputs.python-version != 'pyproject.toml' }}
3941
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
4042
with:
4143
python-version: ${{ inputs.python-version }}
4244
check-latest: true
45+
- name: Set up Python (pyproject.toml)
46+
if: ${{ inputs.python-version == 'pyproject.toml' }}
47+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
48+
with:
49+
python-version-file: ${{ inputs.python-version }}
50+
check-latest: true
4351
- name: Install tox
4452
run: python -m pip install tox
4553
- name: Test

.github/workflows/test-code.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
repo-name: tektronix/python-package-ci-cd
1818
operating-systems-array: '["ubuntu", "windows", "macos"]' # this needs to match the operating-systems-array in the publish-test-results.yml file
19-
python-versions-array: '["3.12"]' # this needs to match the [tool.poetry.dependencies.python] version in the pyproject.toml file
19+
python-versions-array: '["pyproject.toml"]'
2020
upload-to-codecov: true
2121
secrets:
2222
codecov-token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/test-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
uses: ./.github/workflows/_reusable-test-docs.yml
1515
with:
1616
node-version: 20 # The node version needs to stay in sync with .readthedocs.yml
17-
python-version: '3.12' # this needs to match the [tool.poetry.dependencies.python] version in the pyproject.toml file and stay in sync with .readthedocs.yml
17+
python-version: pyproject.toml
1818
tox-env-array: '["docs", "doctests"]'

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Valid subsections within a version are:
1818

1919
Things to be included in the next release go here.
2020

21+
### Added
22+
23+
- Added the ability for caller workflows for the `_reusable-test-docs.yml` and `_reusable-test-code.yml` workflows to specify to use the `pyproject.toml` file as the source of the Python version instead of always requiring a hard-coded Python version.
24+
2125
### Changed
2226

2327
- Bumped dependency versions.

doc_config/known_words.txt

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pr
3030
pre
3131
pypa
3232
pypi
33+
pyproject
3334
repo
3435
sarif
3536
sbom
@@ -39,6 +40,7 @@ stefanzweifel
3940
sublicense
4041
tektronix
4142
testpypi
43+
toml
4244
update_development_dependencies
4345
vimtor
4446
white_check_mark

workflows/test-code.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ commands_pre =
106106
107107
## Inputs
108108

109-
| Input variable | Necessity | Description | Default |
110-
| ------------------------- | --------- | ------------------------------------------------------------------------------------------- | ---------------------------------- |
111-
| `repo-name` | required | The full name of the repository to use to gate Codecov uploads, in the format `owner/repo`. | |
112-
| `python-versions-array` | required | A valid JSON array of Python versions to test against. | |
113-
| `operating-systems-array` | optional | A valid JSON array of operating system names to run tests on. | `'["ubuntu", "windows", "macos"]'` |
114-
| `upload-to-codecov` | optional | A boolean indicating if coverage results should be uploaded to Codecov. | `false` |
109+
| Input variable | Necessity | Description | Default |
110+
| ------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
111+
| `repo-name` | required | The full name of the repository to use to gate Codecov uploads, in the format `owner/repo`. | |
112+
| `python-versions-array` | required | A valid JSON array of Python versions to test against. A valid option is also the string 'pyproject.toml', indicating to use the defined Python version from the pyproject.toml file. | |
113+
| `operating-systems-array` | optional | A valid JSON array of operating system names to run tests on. | `'["ubuntu", "windows", "macos"]'` |
114+
| `upload-to-codecov` | optional | A boolean indicating if coverage results should be uploaded to Codecov. | `false` |
115115

116116
## Secrets
117117

workflows/test-docs.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ commands =
6868
6969
## Inputs
7070

71-
| Input variable | Necessity | Description | Default |
72-
| ---------------- | --------- | ---------------------------------------------- | ------------------------ |
73-
| `node-version` | required | The version of Node.js to install. | |
74-
| `python-version` | required | The version of Python to install. | |
75-
| `tox-env-array` | optional | A valid JSON array of tox environments to run. | `'["docs", "doctests"]'` |
71+
| Input variable | Necessity | Description | Default |
72+
| ---------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
73+
| `node-version` | required | The version of Node.js to install. | |
74+
| `python-version` | required | The version of Python to install. It can also be the string 'pyproject.toml', indicating to use the defined Python version from the pyproject.toml file. | |
75+
| `tox-env-array` | optional | A valid JSON array of tox environments to run. | `'["docs", "doctests"]'` |
7676

7777
## Example
7878

0 commit comments

Comments
 (0)