|
1 | 1 | name: Build and test |
2 | 2 |
|
3 | | -on: [push] |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
4 | 8 |
|
5 | 9 | jobs: |
6 | | - build-linux: |
7 | | - runs-on: ubuntu-latest |
| 10 | + build: |
| 11 | + name: build (${{ matrix.os }}) |
| 12 | + runs-on: ${{ matrix.os }} |
8 | 13 | strategy: |
9 | | - max-parallel: 5 |
| 14 | + fail-fast: false |
| 15 | + matrix: |
| 16 | + # Combined all environments into a single matrix job |
| 17 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 18 | + python-version: ["3.12"] |
10 | 19 |
|
11 | 20 | steps: |
12 | | - - uses: actions/checkout@v3 |
13 | | - - name: Set up Python 3.12 |
14 | | - uses: actions/setup-python@v4 |
15 | | - with: |
16 | | - python-version: '3.12' |
17 | | - - name: Install uv |
18 | | - uses: astral-sh/setup-uv@v1 |
19 | | - with: |
20 | | - uv-version: latest |
21 | | - - name: Install dependencies |
22 | | - run: | |
23 | | - uv venv islp |
24 | | - echo "VIRTUAL_ENV=$(pwd)/islp" >> $GITHUB_ENV |
25 | | - echo "$(pwd)/islp/bin" >> $GITHUB_PATH |
26 | | - uv pip install . |
27 | | - - name: Lint with flake8 |
28 | | - run: | |
29 | | - uv pip install flake8 |
30 | | - # stop the build if there are Python syntax errors or undefined names |
31 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
32 | | - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
33 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
34 | | - - name: Test with pytest |
35 | | - timeout-minutes: 12 |
36 | | - run: | |
37 | | - uv pip install torchvision torchinfo |
38 | | - uv pip install pytest |
39 | | - pytest |
40 | | -
|
41 | | - build-windows: |
42 | | - runs-on: windows-latest |
43 | | - strategy: |
44 | | - max-parallel: 5 |
45 | | - |
46 | | - steps: |
47 | | - - uses: actions/checkout@v3 |
48 | | - - name: Set up Python 3.12 |
49 | | - uses: actions/setup-python@v4 |
50 | | - with: |
51 | | - python-version: '3.12' |
52 | | - - name: Install uv |
53 | | - uses: astral-sh/setup-uv@v1 |
54 | | - with: |
55 | | - uv-version: latest |
56 | | - - name: Install dependencies |
57 | | - run: | |
58 | | - uv venv islp |
59 | | - echo "VIRTUAL_ENV=$(pwd)/islp" >> $env:GITHUB_ENV |
60 | | - echo "$(pwd)/islp/Scripts" >> $env:GITHUB_PATH |
61 | | - uv pip install . |
62 | | - - name: Lint with flake8 |
63 | | - run: | |
64 | | - uv pip install flake8 |
65 | | - # stop the build if there are Python syntax errors or undefined names |
66 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
67 | | - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
68 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
69 | | - - name: Test with pytest |
70 | | - timeout-minutes: 12 |
71 | | - run: | |
72 | | - uv pip install torchvision torchinfo |
73 | | - uv pip install pytest |
74 | | - pytest |
75 | | -
|
76 | | - build-mac: |
77 | | - runs-on: macos-latest |
78 | | - strategy: |
79 | | - max-parallel: 5 |
80 | | - |
81 | | - steps: |
82 | | - - uses: actions/checkout@v3 |
83 | | - - name: Set up Python 3.12 |
84 | | - uses: actions/setup-python@v4 |
85 | | - with: |
86 | | - python-version: '3.12' |
87 | | - - name: Install uv |
88 | | - uses: astral-sh/setup-uv@v1 |
89 | | - with: |
90 | | - uv-version: latest |
91 | | - - name: Install dependencies |
92 | | - run: | |
93 | | - uv venv islp |
94 | | - echo "VIRTUAL_ENV=$(pwd)/islp" >> $GITHUB_ENV |
95 | | - echo "$(pwd)/islp/bin" >> $GITHUB_PATH |
96 | | - uv pip install . |
97 | | - - name: Lint with flake8 |
98 | | - run: | |
99 | | - uv pip install flake8 |
100 | | - # stop the build if there are Python syntax errors or undefined names |
101 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
102 | | - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
103 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
104 | | - - name: Test with pytest |
105 | | - timeout-minutes: 12 |
106 | | - run: | |
107 | | - uv pip install torchvision torchinfo |
108 | | - uv pip install pytest |
109 | | - pytest --ignore tests/deeplearning/test_hitters.py --ignore tests/deeplearning/test_mnist.py |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Install uv |
| 24 | + uses: astral-sh/setup-uv@v5 |
| 25 | + with: |
| 26 | + enable-cache: true |
| 27 | + cache-dependency-glob: "**/pyproject.toml" |
| 28 | + |
| 29 | + - name: Set up Python |
| 30 | + run: uv python install ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Install Project |
| 33 | + # 'uv sync' automatically manages the virtual environment for you. |
| 34 | + # We include dev dependencies for linting and testing. |
| 35 | + run: uv sync --all-extras --dev |
| 36 | + |
| 37 | + - name: Lint with flake8 |
| 38 | + # We use 'uv run' to execute commands in the synced environment. |
| 39 | + # This works consistently across Linux, Mac, and Windows. |
| 40 | + run: | |
| 41 | + uv run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 42 | + uv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 43 | +
|
| 44 | + - name: Test with pytest |
| 45 | + timeout-minutes: 12 |
| 46 | + run: | |
| 47 | + # If torchvision/torchinfo are not in your pyproject.toml, |
| 48 | + # you can install them on the fly like this: |
| 49 | + uv pip install torchvision torchinfo |
| 50 | + |
| 51 | + # Run pytest logic based on OS |
| 52 | + if [ "${{ matrix.os }}" = "macos-latest" ]; then |
| 53 | + uv run pytest --ignore tests/deeplearning/test_hitters.py --ignore tests/deeplearning/test_mnist.py |
| 54 | + else |
| 55 | + uv run pytest |
| 56 | + fi |
| 57 | + shell: bash # Using bash as a shell on all OSs (including Windows) makes if-statements easier |
110 | 58 |
|
111 | 59 |
|
0 commit comments