@@ -12,56 +12,92 @@ concurrency:
1212 group : ${{ github.workflow }}-${{ github.ref }}
1313 cancel-in-progress : true
1414
15+ defaults :
16+ run :
17+ # to fail on error in multiline statements (-e), in pipes (-o pipefail), and on unset variables (-u).
18+ shell : bash -euo pipefail {0}
19+
1520jobs :
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.
1652 test :
17- runs-on : ${{ matrix.os }}
18- defaults :
19- run :
20- shell : bash -e {0} # -e to fail on error
53+ needs : get-environments
2154
2255 strategy :
2356 fail-fast : false
2457 matrix :
25- include :
26- - os : ubuntu-latest
27- python : " 3.11"
28- - os : ubuntu-latest
29- python : " 3.13"
30- - os : ubuntu-latest
31- python : " 3.13"
32- pip-flags : " --pre"
33- name : PRE-RELEASE DEPENDENCIES
58+ os : [ubuntu-latest]
59+ env : ${{ fromJSON(needs.get-environments.outputs.envs) }}
3460
35- name : ${{ matrix.name }} Python ${{ matrix.python }}
36-
37- env :
38- OS : ${{ matrix.os }}
39- PYTHON : ${{ matrix.python }}
61+ name : ${{ matrix.env.label }}
62+ runs-on : ${{ matrix.os }}
4063
4164 steps :
42- - uses : actions/checkout@v5
43- - name : Set up Python ${{ matrix.python }}
44- uses : actions/setup-python@v6
65+ - uses : actions/checkout@v4
4566 with :
46- python-version : ${{ matrix.python }}
47- cache : " pip"
48- cache-dependency-path : " **/pyproject.toml"
49-
50- - name : Install test dependencies
51- run : |
52- python -m pip install --upgrade pip wheel
53- - name : Install dependencies
54- run : |
55- pip install ${{ matrix.pip-flags }} ".[dev,test]"
56- - name : Test
67+ filter : blob:none
68+ fetch-depth : 0
69+ - name : Install uv
70+ uses : astral-sh/setup-uv@v5
71+ with :
72+ python-version : ${{ matrix.env.python }}
73+ cache-dependency-glob : pyproject.toml
74+ - name : create hatch environment
75+ run : uvx hatch env create ${{ matrix.env.name }}
76+ - name : run tests using hatch
5777 env :
5878 MPLBACKEND : agg
5979 PLATFORM : ${{ matrix.os }}
6080 DISPLAY : :42
81+ run : uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto
82+ - name : generate coverage report
6183 run : |
62- coverage run -m pytest -v --color=yes
63- - name : Report coverage
64- run : |
65- coverage report
84+ # See https://coverage.readthedocs.io/en/latest/config.html#run-patch
85+ test -f . coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine
86+ uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly
87+ uvx hatch run ${{ matrix.env.name }}: coverage xml # create report for upload
6688 - name : Upload coverage
6789 uses : codecov/codecov-action@v5
90+
91+ # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch
92+ # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why.
93+ check :
94+ name : Tests pass in all hatch environments
95+ if : always()
96+ needs :
97+ - get-environments
98+ - test
99+ runs-on : ubuntu-latest
100+ steps :
101+ - uses : re-actors/alls-green@release/v1
102+ with :
103+ jobs : ${{ toJSON(needs) }}
0 commit comments