Skip to content

Commit 2091722

Browse files
committed
Major reorganization of the CI workflows.
Add ci-workflow.yaml which is a top-level workflow that allows you to select which jobs to run (code checks, tests, build, publish, release).
1 parent 05fbdb7 commit 2091722

File tree

8 files changed

+134
-71
lines changed

8 files changed

+134
-71
lines changed

.github/workflows/check-test-build.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/ci-workflow.yaml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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
File renamed without changes.
File renamed without changes.
File renamed without changes.

.github/workflows/ci-tox.yaml renamed to .github/workflows/test-tox.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,3 @@ jobs:
5555

5656
- name: Run tests # Use `tox` to run the tests
5757
run: uv run --frozen tox run --skip-pkg-install
58-
59-
build:
60-
name: Build
61-
uses: glenn20/python-ci/.github/workflows/build.yaml@dev

examples/ci-release.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ on:
2121
jobs:
2222
tests:
2323
name: Tests
24-
uses: glenn20/python-ci/.github/workflows/check-test-build.yaml@main
24+
uses: glenn20/python-ci/.github/workflows/ci-tox.yaml@v1
2525
with:
26-
os: '["ubuntu-latest", "windows-latest", "macos-latest"]'
26+
os: '["ubuntu-latest"]' # CI tests only run on linux
2727
python-version: '["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]'
2828

2929
publish-test:
@@ -38,7 +38,7 @@ jobs:
3838
publish-pypi:
3939
name: Publish to pypi
4040
uses: ./.github/workflows/publish.yaml
41-
needs: tests
41+
needs: publish-test
4242
with:
4343
pypi: upload.pypi
4444
permissions:
@@ -47,7 +47,7 @@ jobs:
4747
github-release:
4848
name: Create GitHub release
4949
uses: glenn20/python-ci/.github/workflows/release.yaml@v1
50-
needs: tests
50+
needs: publish-pypi
5151
permissions:
5252
contents: write # IMPORTANT: mandatory for github release
5353
id-token: write # IMPORTANT: mandatory for github release

examples/publish.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ name: Publish python package
1414
# 1. For trusted publishing, the publishing workflow must be in the project
1515
# repository, so copy this workflow file to
1616
# `.github/workflows/publish.yaml` in your repository.
17-
# 2. Create the `publish-test.pypi` and `publish-pypi` Environments in your
18-
# github repository (Settings->Environments->New Environment).
19-
# 3. Add this workflow as a "trusted publisher" on your pypi and test.pypi
20-
# project pages (add the name of the relevant Environment for additional
21-
# access control).
17+
# 2. Create the `publish-test.pypi` and `publish-upload.pypi` Environments in
18+
# your github repository (Settings->Environments->New Environment).
19+
# 3. Add the name of this workflow file (publish.yaml) as a "trusted
20+
# publisher" on your pypi and test.pypi project pages (add the name of the
21+
# relevant Environment for additional access control).
2222
# 4. Call this workflow from a parent workflow with the `pypi` input set to
2323
# "upload.pypi" or "test.pypi" (default).
2424
#
25-
# Invoke with `uses: ./.github/workflows/publish@v1`
25+
# Invoke with `uses: ./.github/workflows/publish.yaml` from a parent workflow.
2626

2727
on:
2828
workflow_call:

0 commit comments

Comments
 (0)