@@ -13,57 +13,91 @@ 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@v5
27+ with :
28+ filter : blob:none
29+ fetch-depth : 0
30+ - name : Install uv
31+ uses : astral-sh/setup-uv@v7
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
49+ permissions :
50+ id-token : write # for codecov OIDC
2151
2252 strategy :
2353 fail-fast : false
2454 matrix :
25- include :
26- - os : ubuntu-latest
27- python : " 3.9"
28- - os : ubuntu-latest
29- python : " 3.11"
30- - os : ubuntu-latest
31- python : " 3.11"
32- pip-flags : " --pre"
33- name : PRE-RELEASE DEPENDENCIES
34-
35- name : ${{ matrix.name }} Python ${{ matrix.python }}
55+ os : [ubuntu-latest]
56+ env : ${{ fromJSON(needs.get-environments.outputs.envs) }}
3657
37- env :
38- OS : ${{ matrix.os }}
39- PYTHON : ${{ matrix.python }}
58+ name : ${{ matrix.env.label }}
59+ runs-on : ${{ matrix.os }}
60+ continue-on-error : ${{ contains( matrix.env.name, 'pre') }} # make "all-green" pass even if pre-release job fails
4061
4162 steps :
42- - uses : actions/checkout@v3
43- - name : Set up Python ${{ matrix.python }}
44- uses : actions/setup-python@v4
63+ - uses : actions/checkout@v5
4564 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- pip install torch==2.1.0
54- pip install torch-scatter torch-sparse torch-cluster
55- - name : Install dependencies
56- run : |
57- pip install ${{ matrix.pip-flags }} ".[dev,test]"
58- - name : Test
65+ filter : blob:none
66+ fetch-depth : 0
67+ - name : Install uv
68+ uses : astral-sh/setup-uv@v7
69+ with :
70+ python-version : ${{ matrix.env.python }}
71+ - name : create hatch environment
72+ run : uvx hatch env create ${{ matrix.env.name }}
73+ - name : run tests using hatch
5974 env :
6075 MPLBACKEND : agg
6176 PLATFORM : ${{ matrix.os }}
6277 DISPLAY : :42
78+ run : uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto
79+ - name : generate coverage report
6380 run : |
64- coverage run -m pytest -v --color=yes
65- - name : Report coverage
66- run : |
67- coverage report
81+ # See https://coverage.readthedocs.io/en/latest/config.html#run-patch
82+ test -f . coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine
83+ uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly
84+ uvx hatch run ${{ matrix.env.name }}: coverage xml # create report for upload
6885 - name : Upload coverage
69- uses : codecov/codecov-action@v3
86+ uses : codecov/codecov-action@v5
87+ with :
88+ fail_ci_if_error : true
89+ use_oidc : true
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