Skip to content

Commit

Permalink
feat: Add the ability for calling workflows to specify to use the Pyt…
Browse files Browse the repository at this point in the history
…hon version stored in the pyproject.toml file instead of hard-coding the Python version in the workflows as well
  • Loading branch information
nfelt14 committed Nov 13, 2024
1 parent 91e0f54 commit bf7e685
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/_reusable-test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
required: true
type: string
python-versions-array:
description: A valid JSON array of Python versions to test against.
description: 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.
required: true
type: string
operating-systems-array:
Expand Down Expand Up @@ -46,11 +48,18 @@ jobs:
with:
node-version: lts/*
check-latest: true
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python (version)
if: ${{ matrix.python-version != 'pyproject.toml' }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Set up Python (pyproject.toml)
if: ${{ matrix.python-version == 'pyproject.toml' }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version-file: ${{ matrix.python-version }}
check-latest: true
- name: Install dependencies
run: python -m pip install tox tox-gh-actions
- name: Set up pre-commit cache
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/_reusable-test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
required: true
type: number
python-version:
description: The version of Python to install.
description: 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.
required: true
type: string
tox-env-array:
Expand All @@ -35,11 +36,18 @@ jobs:
run: |
npm install --global @mermaid-js/mermaid-cli
sudo apt install --no-install-recommends --assume-yes graphviz
- name: Set up Python
- name: Set up Python (version)
if: ${{ inputs.python-version != 'pyproject.toml' }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ inputs.python-version }}
check-latest: true
- name: Set up Python (pyproject.toml)
if: ${{ inputs.python-version == 'pyproject.toml' }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version-file: ${{ inputs.python-version }}
check-latest: true
- name: Install tox
run: python -m pip install tox
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
repo-name: tektronix/python-package-ci-cd
operating-systems-array: '["ubuntu", "windows", "macos"]' # this needs to match the operating-systems-array in the publish-test-results.yml file
python-versions-array: '["3.12"]' # this needs to match the [tool.poetry.dependencies.python] version in the pyproject.toml file
python-versions-array: '["pyproject.toml"]'
upload-to-codecov: true
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
uses: ./.github/workflows/_reusable-test-docs.yml
with:
node-version: 20 # The node version needs to stay in sync with .readthedocs.yml
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
python-version: pyproject.toml
tox-env-array: '["docs", "doctests"]'
12 changes: 6 additions & 6 deletions workflows/test-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ commands_pre =
## Inputs

| Input variable | Necessity | Description | Default |
| ------------------------- | --------- | ------------------------------------------------------------------------------------------- | ---------------------------------- |
| `repo-name` | required | The full name of the repository to use to gate Codecov uploads, in the format `owner/repo`. | |
| `python-versions-array` | required | A valid JSON array of Python versions to test against. | |
| `operating-systems-array` | optional | A valid JSON array of operating system names to run tests on. | `'["ubuntu", "windows", "macos"]'` |
| `upload-to-codecov` | optional | A boolean indicating if coverage results should be uploaded to Codecov. | `false` |
| Input variable | Necessity | Description | Default |
| ------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| `repo-name` | required | The full name of the repository to use to gate Codecov uploads, in the format `owner/repo`. | |
| `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. | |
| `operating-systems-array` | optional | A valid JSON array of operating system names to run tests on. | `'["ubuntu", "windows", "macos"]'` |
| `upload-to-codecov` | optional | A boolean indicating if coverage results should be uploaded to Codecov. | `false` |

## Secrets

Expand Down
10 changes: 5 additions & 5 deletions workflows/test-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ commands =
## Inputs

| Input variable | Necessity | Description | Default |
| ---------------- | --------- | ---------------------------------------------- | ------------------------ |
| `node-version` | required | The version of Node.js to install. | |
| `python-version` | required | The version of Python to install. | |
| `tox-env-array` | optional | A valid JSON array of tox environments to run. | `'["docs", "doctests"]'` |
| Input variable | Necessity | Description | Default |
| ---------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| `node-version` | required | The version of Node.js to install. | |
| `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. | |
| `tox-env-array` | optional | A valid JSON array of tox environments to run. | `'["docs", "doctests"]'` |

## Example

Expand Down

0 comments on commit bf7e685

Please sign in to comment.