Skip to content

Commit a7c4655

Browse files
committed
Refactor github CI workflows
- `ci.yaml`: Configure the CI workflow to use the new ci-workflow.yaml. - Here is where the triggers and workflow configuration are set. - This file will call `ci-workflow-tox.yaml` with the appropriate inputs. Assumes tests and code checks are run by `tox` and configured in the `pyproject.toml` file.
1 parent 63b3db6 commit a7c4655

File tree

7 files changed

+93
-865
lines changed

7 files changed

+93
-865
lines changed

.github/workflows/ci-release.yaml

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

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

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

.github/workflows/ci-test.yaml

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

.github/workflows/ci.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: CI workflow for python projects
2+
3+
# Run the CI test workflow of jobs which includes:
4+
# - `test`: Run tests (including code checks) using `tox`.
5+
# - `build`: Build the python package.
6+
# - `publish-test`: Publish the package to test.pypi.org.
7+
# - `publish`: Publish the package to pypi.org (runs `publish-test`).
8+
# - `release`: Create a GitHub release.
9+
10+
# Configure the workflows here. Each environment variable name should be a
11+
# wildcard matching the
12+
# `on-<github.event_name>-<github.ref_type>-<github.ref_name>` format. For
13+
# example, if the event is a push to a tag `v1.0.0`, the environment variable
14+
# `on-push-tag-v*` will match. The value of the matching variable will be
15+
# written to $GITHUB_OUTPUT to set the jobs, python versions, and operating
16+
# systems to run the workflow on. The first match found is used.
17+
env:
18+
on-push-tag-*: | # Push version tag matching "v*", eg. "v1.0.0"
19+
jobs=["test", "build", "publish", "release"]
20+
python-version=["3.9", "3.10", "3.11", "3.12", "3.13"]
21+
os=["ubuntu-latest"]
22+
on-push-branch-main: | # Push commits to main branch
23+
jobs=["test", "build", "publish-test"]
24+
python-version=["3.9", "3.10", "3.11", "3.12", "3.13"]
25+
os=["ubuntu-latest"]
26+
on-push-branch-*: | # Push commits to other branches
27+
jobs=["test", "build"]
28+
python-version=["3.9", "3.13"]
29+
os=["ubuntu-latest"]
30+
on-workflow_dispatch-*: | # Manual trigger of the workflow
31+
jobs=["test", "build"]
32+
python-version=["3.9", "3.13"]
33+
os=["ubuntu-latest"]
34+
35+
on:
36+
push:
37+
branches: ["**"] # Push commits to any branch
38+
tags: ["v[0-9]*"] # Publish on tags matching "v*", eg. "v1.0.0"
39+
workflow_dispatch: # Allow manual triggering of the workflow
40+
41+
jobs:
42+
config: # Select the workflow config based on the event trigger.
43+
name: Configure workflow
44+
outputs:
45+
jobs: ${{ steps.config.outputs.jobs }}
46+
os: ${{ steps.config.outputs.os }}
47+
python-version: ${{ steps.config.outputs.python-version }}
48+
runs-on: ubuntu-latest
49+
steps:
50+
- id: config
51+
uses: glenn20/python-ci/actions/config@v2
52+
with:
53+
config: ${{ toJson(env) }}
54+
55+
ci-workflow: # Run the CI workflow based on the config.
56+
name: CI workflow
57+
needs: config
58+
uses: glenn20/python-ci/.github/workflows/ci-workflow-tox.yaml@v2
59+
with:
60+
jobs: ${{ needs.config.outputs.jobs }}
61+
os: ${{ needs.config.outputs.os }}
62+
python-version: ${{ needs.config.outputs.python-version }}
63+
64+
# We can't use trusted publishing from a reusable workflow in another
65+
# repository, so the publish workflows must be run from here.
66+
publish:
67+
name: Publish to pypi.org
68+
needs: [config, ci-workflow]
69+
runs-on: ubuntu-latest
70+
if: ${{ contains(needs.config.outputs.jobs, 'publish') }}
71+
environment:
72+
name: publish-pypi
73+
url: ${{ steps.publish.outputs.url }}
74+
permissions:
75+
id-token: write # Required for trusted publishing
76+
steps:
77+
- id: publish
78+
uses: glenn20/python-ci/actions/publish@v2
79+
with:
80+
test-only: ${{ contains(fromJson(needs.config.outputs.jobs), 'publish') && 'false' || 'true' }}
81+
82+
# We run the github release job here instead of in ci-workflow, as it requires
83+
# permissions to sign the release and to simplify the workflow dependency
84+
# graph on the github UI.
85+
release:
86+
needs: [config, ci-workflow]
87+
uses: glenn20/python-ci/.github/workflows/github-release.yaml@v2
88+
permissions:
89+
id-token: write # Required for signing the release
90+
contents: write # Required for github release
91+
if: ${{ contains(fromJson(needs.config.outputs.jobs), 'release') }}

.github/workflows/publish.yaml

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

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ run.omit = ["_version.py"]
8383
report.skip_covered = false
8484
append = true
8585

86-
[tool.tox.gh.python] # For Github Actions workflow - see
86+
# For Github Actions workflow - see https://github.com/tox-dev/tox-gh
87+
[tool.tox.gh.python]
8788
"3.13" = ["clean", "typing", "lint", "format", "3.13"]
8889
"3.12" = ["3.12"]
8990
"3.11" = ["3.11"]
@@ -111,7 +112,6 @@ dependency_groups = ["test"] # Everything we need to run the tox tests
111112
labels = ["test"]
112113
package = "editable" # "editable" runs a bit faster then "wheel"
113114
runner = "uv-venv-runner" # We love uv
114-
passenv = ["GITHUB_ACTIONS"] # So conftest.py knows we are running in github actions
115115

116116
[tool.tox.env.3.13]
117117
# Run coverage tests only on the latest python version

0 commit comments

Comments
 (0)