1
- # This file runs the tests in `tests/`
2
- # They will run in parallel, and run on three operating systems:
3
- # Ubuntu, Windows and Mac.
4
-
5
1
name : tests
6
2
7
3
on :
8
4
push :
9
5
branches : [main]
10
6
workflow_dispatch :
7
+ inputs :
8
+ operating_systems :
9
+ description : ' Operating systems to test on'
10
+ type : choice
11
+ default : ' all'
12
+ options :
13
+ - all
14
+ - ubuntu-latest
15
+ - windows-latest
16
+ - macos-latest
11
17
12
18
jobs :
13
-
14
- # Run tests on Ubuntu
15
- tests-on-ubuntu :
19
+ # Generate matrix based on input
20
+ setup-matrix :
16
21
runs-on : ubuntu-latest
22
+ outputs :
23
+ matrix : ${{ steps.set-matrix.outputs.matrix }}
17
24
steps :
18
-
19
- - name : Check out repository
20
- uses : actions/checkout@v4
21
-
22
- - name : Install python and dependencies
23
- uses : actions/setup-python@v4
24
- with :
25
- python-version : ' 3.13'
26
- cache : ' pip'
27
- - run : pip install -r requirements.txt
28
-
29
- - name : Run tests
30
- run : pytest
31
-
32
- - name : List the environment variables
33
- run : env
34
-
35
- # Run tests on Windows
36
- tests-on-windows :
37
- runs-on : windows-latest
25
+ - name : Set matrix
26
+ id : set-matrix
27
+ run : |
28
+ if [[ "${{ inputs.operating_systems }}" == "all" || "${{ github.event_name }}" == "push" ]]; then
29
+ echo 'matrix=["ubuntu-latest", "windows-latest", "macos-latest"]' >> $GITHUB_OUTPUT
30
+ else
31
+ echo 'matrix=["${{ inputs.operating_systems }}"]' >> $GITHUB_OUTPUT
32
+ fi
33
+
34
+ # Run tests using matrix strategy
35
+ tests :
36
+ needs : setup-matrix
37
+ runs-on : ${{ matrix.os }}
38
+ strategy :
39
+ matrix :
40
+ os : ${{ fromJSON(needs.setup-matrix.outputs.matrix) }}
41
+
38
42
steps :
39
-
40
43
- name : Check out repository
41
44
uses : actions/checkout@v4
42
45
@@ -45,31 +48,17 @@ jobs:
45
48
with :
46
49
python-version : ' 3.13'
47
50
cache : ' pip'
48
- - run : python -m pip install -r requirements.txt
51
+
52
+ - name : Install requirements (Windows)
53
+ if : runner.os == 'Windows'
54
+ run : python -m pip install -r requirements.txt
55
+
56
+ - name : Install requirements (Unix)
57
+ if : runner.os != 'Windows'
58
+ run : pip install -r requirements.txt
49
59
50
60
- name : Run tests
51
61
run : pytest
52
62
53
63
- name : List the environment variables
54
64
run : env
55
-
56
- # Run tests on Mac
57
- tests-on-macos :
58
- runs-on : macos-latest
59
- steps :
60
-
61
- - name : Check out repository
62
- uses : actions/checkout@v4
63
-
64
- - name : Install python and dependencies
65
- uses : actions/setup-python@v4
66
- with :
67
- python-version : ' 3.13'
68
- cache : ' pip'
69
- - run : pip install -r requirements.txt
70
-
71
- - name : Run tests
72
- run : pytest
73
-
74
- - name : List the environment variables
75
- run : env
0 commit comments