@@ -3,7 +3,6 @@ name: Test
33on :
44 push :
55 branches : [main]
6- tags : ["v*"]
76 pull_request :
87 branches : [main]
98 schedule :
@@ -13,23 +12,27 @@ concurrency:
1312 group : ${{ github.workflow }}-${{ github.ref }}
1413 cancel-in-progress : true
1514
16- env :
17- MPLBACKEND : agg
15+ permissions :
16+ contents : read
1817
1918jobs :
20- # Dynamically extract the test matrix from hatch so pyproject.toml is the single source of truth.
21- # See [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml.
19+ # Get the test environment from hatch as defined in pyproject.toml.
20+ # This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are
21+ # run locally and on continuous integration.
22+ # Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for
23+ # more details.
2224 get-environments :
23- runs-on : ubuntu-latest
25+ runs-on : ubuntu-slim
2426 outputs :
2527 envs : ${{ steps.get-envs.outputs.envs }}
2628 steps :
27- - uses : actions/checkout@v5
29+ - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2830 with :
2931 filter : blob:none
3032 fetch-depth : 0
33+ persist-credentials : false
3134 - name : Install uv
32- uses : astral-sh/setup-uv@v7
35+ uses : astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
3336 - name : Get test environments
3437 id : get-envs
3538 run : |
@@ -44,10 +47,12 @@ jobs:
4447 )')
4548 echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT
4649
50+ # Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above.
4751 test :
4852 needs : get-environments
4953 permissions :
5054 id-token : write # for codecov OIDC
55+ contents : read
5156
5257 strategy :
5358 fail-fast : false
@@ -57,23 +62,27 @@ jobs:
5762
5863 name : ${{ matrix.env.label }}
5964 runs-on : ${{ matrix.os }}
60- continue-on-error : ${{ contains(matrix.env.name, 'pre') }}
65+ continue-on-error : ${{ contains(matrix.env.name, 'pre') }} # make "all-green" pass even if pre-release job fails
6166
6267 steps :
63- - uses : actions/checkout@v5
68+ - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
6469 with :
6570 filter : blob:none
6671 fetch-depth : 0
72+ persist-credentials : false
6773 - name : Install uv
68- uses : astral-sh/setup-uv@v7
74+ uses : astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
6975 with :
7076 python-version : ${{ matrix.env.python }}
7177 - name : Ensure figure directory exists
7278 run : mkdir -p tests/figures
7379 - name : Create hatch environment
7480 run : uvx hatch env create ${{ matrix.env.name }}
81+ - name : List all installed package versions
82+ run : uvx hatch run ${{ matrix.env.name }}:uv pip list
7583 - name : Run tests
7684 env :
85+ MPLBACKEND : agg
7786 DISPLAY : " :42"
7887 run : >-
7988 uvx hatch run ${{ matrix.env.name }}:${{
@@ -88,19 +97,19 @@ jobs:
8897 uvx hatch run ${{ matrix.env.name }}:cov-report
8998 - name : Archive visual test figures
9099 if : always()
91- uses : actions/upload-artifact@v4
100+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
92101 with :
93102 name : visual_test_results_${{ matrix.env.name }}
94103 path : tests/figures/*
95104 - name : Upload coverage
96105 if : matrix.env.name == 'hatch-test.py3.14-stable'
97- uses : codecov/codecov-action@v6
106+ uses : codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
98107 with :
99108 fail_ci_if_error : true
100109 use_oidc : true
101110
102- # Single required check for branch protection.
103- # See https://github.com/re-actors/alls-green#why
111+ # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch
112+ # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why.
104113 check :
105114 name : Tests pass in all hatch environments
106115 if : always()
@@ -109,6 +118,6 @@ jobs:
109118 - test
110119 runs-on : ubuntu-latest
111120 steps :
112- - uses : re-actors/alls-green@release/v1
121+ - uses : re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
113122 with :
114123 jobs : ${{ toJSON(needs) }}
0 commit comments