@@ -18,27 +18,48 @@ defaults:
1818 shell : bash -euo pipefail {0}
1919
2020jobs :
21+ # Get the test environment from hatch as defined in pyproject.toml.
22+ # This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are
23+ # run locally and on continuous integration.
24+ # Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for
25+ # more details.
26+ get-environments :
27+ runs-on : ubuntu-latest
28+ outputs :
29+ envs : ${{ steps.get-envs.outputs.envs }}
30+ steps :
31+ - uses : actions/checkout@v4
32+ with :
33+ filter : blob:none
34+ fetch-depth : 0
35+ - name : Install uv
36+ uses : astral-sh/setup-uv@v5
37+ - name : Get test environments
38+ id : get-envs
39+ run : |
40+ ENVS_JSON=$(uvx hatch env show --json | jq -c 'to_entries
41+ | map(
42+ select(.key | startswith("hatch-test"))
43+ | {
44+ name: .key,
45+ label: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end),
46+ python: .value.python
47+ }
48+ )')
49+ echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT
50+
51+ # Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above.
2152 test :
22- runs-on : ${{ matrix.os }}
53+ needs : get-environments
2354
2455 strategy :
2556 fail-fast : false
2657 matrix :
27- include :
28- - os : ubuntu-latest
29- python : " 3.10"
30- - os : ubuntu-latest
31- python : " 3.12"
32- - os : ubuntu-latest
33- python : " 3.12"
34- pip-flags : " --pre"
35- name : PRE-RELEASE DEPENDENCIES
36-
37- name : ${{ matrix.name }} Python ${{ matrix.python }}
38-
39- env :
40- OS : ${{ matrix.os }}
41- PYTHON : ${{ matrix.python }}
58+ os : [ubuntu-latest]
59+ env : ${{ fromJSON(needs.get-environments.outputs.envs) }}
60+
61+ name : ${{ matrix.env.label }}
62+ runs-on : ${{ matrix.os }}
4263
4364 steps :
4465 - uses : actions/checkout@v4
@@ -48,14 +69,31 @@ jobs:
4869 - name : Install uv
4970 uses : astral-sh/setup-uv@v5
5071 with :
72+ python-version : ${{ matrix.env.python }}
5173 cache-dependency-glob : pyproject.toml
74+ - name : create hatch environment
75+ run : uvx hatch env create ${{ matrix.env.name }}
5276 - name : run tests using hatch
5377 env :
5478 MPLBACKEND : agg
5579 PLATFORM : ${{ matrix.os }}
5680 DISPLAY : :42
57- run : uvx hatch test --cover --python ${{ matrix.python }}
81+ run : uvx hatch run ${{ matrix.env.name }}:run-cov
5882 - name : generate coverage report
59- run : uvx hatch run hatch-test.py ${{ matrix.python }}:coverage xml
83+ run : uvx hatch run ${{ matrix.env.name }}:coverage xml
6084 - name : Upload coverage
6185 uses : codecov/codecov-action@v4
86+
87+ # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch
88+ # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why.
89+ check :
90+ name : Tests pass in all hatch environments
91+ if : always()
92+ needs :
93+ - get-environments
94+ - test
95+ runs-on : ubuntu-latest
96+ steps :
97+ - uses : re-actors/alls-green@release/v1
98+ with :
99+ jobs : ${{ toJSON(needs) }}
0 commit comments