|
| 1 | +name: CI using tox |
| 2 | + |
| 3 | +# A reusable github workflow to run python CI workflows, including static code |
| 4 | +# checks, automated testing (using pytest or tox), package building, |
| 5 | +# publishing to test.pypi.org and pypi.org, and creating a GitHub release. |
| 6 | +# |
| 7 | +# The workflow elements to selected are specified in the `jobs` input. The |
| 8 | +# default is to run the `test-tox` and `build` jobs. The CI workflow is |
| 9 | +# configured in the tox-gh config (eg. pyproject.toml). See |
| 10 | +# https://github.com/tox-dev/tox-gh. |
| 11 | +# |
| 12 | +# Accepts the following inputs: |
| 13 | +# - `jobs`: A json string containing the list of jobs to run. Default is |
| 14 | +# `["test-tox", "build"]`. The available jobs are: |
| 15 | +# - `code-check`: Run static code checks (using `mypy`, `ruff`, etc.). |
| 16 | +# - `test-pytest`: Run tests using `pytest`. |
| 17 | +# - `test-tox`: Run tests and code checks using `tox` (alias "test"). |
| 18 | +# - `build`: Build the python package. |
| 19 | +# - `publish-test`: Publish the package to test.pypi.org. |
| 20 | +# - `publish`: Publish the package to pypi.org. |
| 21 | +# - `release`: Create a GitHub release. |
| 22 | +# - `os`: A json string containing the list of operating systems on which to |
| 23 | +# run tests. Default is `["ubuntu-latest", "windows-latest", |
| 24 | +# "macos-latest"]`. |
| 25 | +# - `python-version`: A json string containing the list of python versions on |
| 26 | +# which to run tests. Default is `["3.9", "3.10", "3.11", "3.12", "3.13"]`. |
| 27 | +# |
| 28 | +# Assumes the configurations for all tools (`mypy`, `uv`, `ruff`, `pytest`, |
| 29 | +# ...) are fully specified in config files (eg `pyproject.toml`). |
| 30 | +# |
| 31 | +# You should select either `test-tox` or `code-check`+`test-pytest`, but not |
| 32 | +# both. |
| 33 | +# |
| 34 | +# It is recommended to use the `test-tox` job, as it includes the code checks, |
| 35 | +# and can be more easily customised in yourq pyproject.toml so that the same CI |
| 36 | +# process runs on your local computer and on github. |
| 37 | +# |
| 38 | +# All workflows use astral `uv` to execute actions wherever possible. |
| 39 | + |
| 40 | +on: |
| 41 | + workflow_call: |
| 42 | + inputs: |
| 43 | + jobs: |
| 44 | + description: >- |
| 45 | + A json string containing the list of jobs to run. Default is |
| 46 | + `["tests", "build"]`. |
| 47 | + default: '["test-tox", "build"]' |
| 48 | + type: string |
| 49 | + required: false |
| 50 | + os: |
| 51 | + description: >- |
| 52 | + A json string containing the list of operating systems on which to |
| 53 | + run the test matrix. |
| 54 | + default: '["ubuntu-latest", "windows-latest", "macos-latest"]' |
| 55 | + type: string |
| 56 | + required: false |
| 57 | + python-version: |
| 58 | + description: >- |
| 59 | + A json string containing the list of python versions on |
| 60 | + which to run the test matrix. |
| 61 | + default: '["3.9", "3.10", "3.11", "3.12", "3.13"]' |
| 62 | + type: string |
| 63 | + required: false |
| 64 | + |
| 65 | +jobs: |
| 66 | + code-check: |
| 67 | + if: ${{ contains(fromJson(inputs.jobs), 'code-check') }} |
| 68 | + name: Run static code checks |
| 69 | + uses: glenn20/python-ci/.github/workflows/check.yaml@dev |
| 70 | + |
| 71 | + test-pytest: |
| 72 | + if: ${{ contains(fromJson(inputs.jobs), 'test-pytest') }} |
| 73 | + name: Run tests using pytest |
| 74 | + uses: glenn20/python-ci/.github/workflows/test-pytest.yaml@dev |
| 75 | + with: |
| 76 | + os: ${{ inputs.os }} |
| 77 | + python-version: ${{ inputs.python-version }} |
| 78 | + |
| 79 | + test-tox: |
| 80 | + if: ${{ contains(fromJson(inputs.jobs), 'test-tox') || contains(fromJson(inputs.jobs), 'test') }} |
| 81 | + name: Run tests and code checks using tox |
| 82 | + uses: glenn20/python-ci/.github/workflows/test-tox.yaml@dev |
| 83 | + with: |
| 84 | + os: ${{ inputs.os }} |
| 85 | + python-version: ${{ inputs.python-version }} |
| 86 | + |
| 87 | + build: |
| 88 | + if: ${{ contains(fromJson(inputs.jobs), 'build') }} |
| 89 | + name: Build python package |
| 90 | + uses: glenn20/python-ci/.github/workflows/build.yaml@dev |
| 91 | + |
| 92 | + # The publish workflows must be located in your project repository, not in the |
| 93 | + # python-ci repository, so that they can access the secrets needed to publish |
| 94 | + # to test.pypi.org and pypi.org. Copy the `publish.yaml` workflow from |
| 95 | + # `glenn20/python-ci/examples/publish.yaml` to your project's |
| 96 | + # `.github/workflows` directory. |
| 97 | + publish-test: |
| 98 | + if: ${{ contains(fromJson(inputs.jobs), 'publish-test') }} |
| 99 | + name: Publish to test.pypi |
| 100 | + uses: .github/workflows/publish.yaml@dev |
| 101 | + with: |
| 102 | + pypi: 'test.pypi' |
| 103 | + needs: build |
| 104 | + permissions: |
| 105 | + id-token: write # IMPORTANT: mandatory for trusted publishing! |
| 106 | + |
| 107 | + publish: |
| 108 | + if: ${{ contains(fromJson(inputs.jobs), 'publish') }} |
| 109 | + name: Publish to pypi |
| 110 | + uses: .github/workflows/publish.yaml@dev |
| 111 | + with: |
| 112 | + pypi: 'upload.pypi' |
| 113 | + needs: publish-test |
| 114 | + permissions: |
| 115 | + id-token: write # IMPORTANT: mandatory for trusted publishing! |
| 116 | + |
| 117 | + release: |
| 118 | + if: ${{ contains(fromJson(inputs.jobs), 'release') }} |
| 119 | + name: Create GitHub release |
| 120 | + uses: glenn20/python-ci/.github/workflows/github-release.yaml@dev |
| 121 | + needs: publish |
| 122 | + permissions: |
| 123 | + contents: write # IMPORTANT: mandatory for github release |
| 124 | + id-token: write # IMPORTANT: mandatory for github release |
0 commit comments