@@ -13,55 +13,86 @@ concurrency:
1313 cancel-in-progress : true
1414
1515jobs :
16+ # Get the test environment from hatch as defined in pyproject.toml.
17+ # This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are
18+ # run locally and on continuous integration.
19+ # Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for
20+ # more details.
21+ get-environments :
22+ runs-on : ubuntu-latest
23+ outputs :
24+ envs : ${{ steps.get-envs.outputs.envs }}
25+ steps :
26+ - uses : actions/checkout@v4
27+ with :
28+ filter : blob:none
29+ fetch-depth : 0
30+ - name : Install uv
31+ uses : astral-sh/setup-uv@v5
32+ - name : Get test environments
33+ id : get-envs
34+ run : |
35+ ENVS_JSON=$(uvx hatch env show --json | jq -c 'to_entries
36+ | map(
37+ select(.key | startswith("hatch-test"))
38+ | {
39+ name: .key,
40+ label: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end),
41+ python: .value.python
42+ }
43+ )')
44+ echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT
45+
46+ # Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above.
1647 test :
17- runs-on : ${{ matrix.os }}
18- defaults :
19- run :
20- shell : bash -e {0} # -e to fail on error
48+ needs : get-environments
2149
2250 strategy :
2351 fail-fast : false
2452 matrix :
25- include :
26- - os : ubuntu-latest
27- python : " 3.10"
28- - os : ubuntu-latest
29- python : " 3.12"
30- - os : ubuntu-latest
31- python : " 3.12"
32- pip-flags : " --pre"
33- name : PRE-RELEASE DEPENDENCIES
34-
35- name : ${{ matrix.name }} Python ${{ matrix.python }}
53+ os : [ubuntu-latest]
54+ env : ${{ fromJSON(needs.get-environments.outputs.envs) }}
3655
37- env :
38- OS : ${{ matrix.os }}
39- PYTHON : ${{ matrix.python }}
56+ name : ${{ matrix.env.label }}
57+ runs-on : ${{ matrix.os }}
4058
4159 steps :
42- - uses : actions/checkout@v3
43- - name : Set up Python ${{ matrix.python }}
44- uses : actions/setup-python@v4
60+ - uses : actions/checkout@v4
4561 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
62+ filter : blob:none
63+ fetch-depth : 0
64+ - name : Install uv
65+ uses : astral-sh/setup-uv@v5
66+ with :
67+ python-version : ${{ matrix.env.python }}
68+ cache-dependency-glob : pyproject.toml
69+ - name : create hatch environment
70+ run : uvx hatch env create ${{ matrix.env.name }}
71+ - name : run tests using hatch
5772 env :
5873 MPLBACKEND : agg
5974 PLATFORM : ${{ matrix.os }}
6075 DISPLAY : :42
76+ run : uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto
77+ - name : generate coverage report
6178 run : |
62- coverage run -m pytest -v --color=yes
63- - name : Report coverage
64- run : |
65- coverage report
79+ # See https://coverage.readthedocs.io/en/latest/config.html#run-patch
80+ test -f . coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine
81+ uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly
82+ uvx hatch run ${{ matrix.env.name }}: coverage xml # create report for upload
6683 - name : Upload coverage
67- uses : codecov/codecov-action@v3
84+ uses : codecov/codecov-action@v5
85+
86+ # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch
87+ # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why.
88+ check :
89+ name : Tests pass in all hatch environments
90+ if : always()
91+ needs :
92+ - get-environments
93+ - test
94+ runs-on : ubuntu-latest
95+ steps :
96+ - uses : re-actors/alls-green@release/v1
97+ with :
98+ jobs : ${{ toJSON(needs) }}
0 commit comments