1
# Copyright (c) ONNX Project Contributors
3
# SPDX-License-Identifier: Apache-2.0
9
- cron: '0 0 * * *' # every day at midnight for reporting code coverage to codecov
17
permissions: # set top-level default permissions as security best practice
21
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
22
cancel-in-progress: true
26
name: Test ${{ matrix.os }}, ${{ matrix.python_version }}, ${{ matrix.protobuf_type }}, debug=${{ matrix.debug_build }}, onnx_ml=${{ matrix.onnx_ml }}, doc=${{ matrix.documentation }}
30
os: [ubuntu-latest, windows-latest, macos-latest]
31
python_version: ['3.12', '3.11', '3.10', '3.9', '3.8']
33
- python_version: '3.12'
37
protobuf_type: 'Internal'
38
- python_version: '3.11'
42
protobuf_type: 'External'
43
- python_version: '3.10'
47
protobuf_type: 'Internal'
48
- python_version: '3.9'
52
protobuf_type: 'External'
53
- python_version: '3.8'
57
protobuf_type: 'Internal'
58
runs-on: ${{ matrix.os }}
60
- name: Checkout repository
61
uses: actions/checkout@9a9194f87191a7e9055e3e9b95b8cfb13023bb08
64
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
66
python-version: ${{ matrix.python_version }}
73
- name: Install external protobuf - Linux
74
if: matrix.protobuf_type == 'External' && matrix.os == 'ubuntu-latest'
76
sudo apt-get install libprotobuf-dev protobuf-compiler
78
- name: Install external protobuf - MacOS
79
if: matrix.protobuf_type == 'External' && matrix.os == 'macos-latest'
81
source workflow_scripts/protobuf/build_protobuf_unix.sh 3 $(pwd)/protobuf/protobuf_install
83
- name: Set up MSBuild
84
if: matrix.os == 'windows-latest'
85
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0
87
msbuild-architecture: x64
89
- name: Install external protobuf - Windows
90
if: matrix.protobuf_type == 'External' && matrix.os == 'windows-latest'
92
workflow_scripts/protobuf/build_protobuf_win.ps1
94
- name: Install dependencies
96
python -m pip install --upgrade pip
97
python -m pip install -r requirements-release.txt
98
python -m pip install protobuf==3.20.2
99
git submodule update --init --recursive
101
- name: Build and install ONNX - Linux
102
if: matrix.os == 'ubuntu-latest'
104
if [ "${{ matrix.protobuf_type }}" == "External" ]; then
105
export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
107
pip install -e ".[reference]" -v
109
DEBUG: ${{ matrix.debug_build }}
110
ONNX_ML: ${{ matrix.onnx_ml }}
112
CMAKE_ARGS: "-DONNX_WERROR=ON -DCMAKE_CXX_FLAGS='-fsanitize=undefined -fno-sanitize-recover=all '"
114
- name: Build and install ONNX - MacOS
115
if: matrix.os == 'macos-latest'
117
pip install -e ".[reference]" -v
119
DEBUG: ${{ matrix.debug_build }}
120
ONNX_ML: ${{ matrix.onnx_ml }}
122
CMAKE_ARGS: "-DONNX_WERROR=ON"
124
- name: Build and install ONNX - Windows
125
if: matrix.os == 'windows-latest' && matrix.python_version != '3.9' && matrix.python_version != '3.8' && matrix.python_version != '3.12'
127
python setup.py build_ext --inplace
128
python setup.py install
130
DEBUG: ${{ matrix.debug_build }}
131
ONNX_ML: ${{ matrix.onnx_ml }}
133
CMAKE_ARGS: "-DONNX_WERROR=OFF -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON"
135
- name: Build and install ONNX - Windows
136
if: matrix.os == 'windows-latest' && (matrix.python_version == '3.9' || matrix.python_version == '3.8' || matrix.python_version == '3.12')
140
DEBUG: ${{ matrix.debug_build }}
141
ONNX_ML: ${{ matrix.onnx_ml }}
143
CMAKE_ARGS: "-DONNX_WERROR=OFF -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON"
149
- name: Run Python tests
151
pytest -sv --cov=onnx --cov-report=xml --cov-append --cov-branch --junit-xml pytest.xml -n auto --dist loadscope
153
- name: Run C++ tests
154
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
156
export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH"
157
./.setuptools-cmake-build/onnx_gtests
159
- name: Upload coverage to Codecov
161
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673
163
token: ${{ secrets.CODECOV_TOKEN }}
165
- name: Upload Test Results
167
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
169
name: TestResults-(${{ matrix.os }}-${{ matrix.python_version }})
172
# Note that the test data should be generated with numpy>=2.0.
173
# numpy 1.x and numpy 2.0 produce slightly different numerical values.
174
- name: Test backend test data
175
if: matrix.documentation == 1 && matrix.os == 'ubuntu-latest'
177
python onnx/backend/test/cmd_tools.py generate-data --clean
179
git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb'
180
if [ $? -ne 0 ]; then
181
echo "git diff for test generation returned failures. Please check updated node test files"
184
git diff --exit-code --diff-filter=ADR -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3'
185
if [ $? -ne 0 ]; then
186
echo "Test generation returned failures. Please check the number of node test files (input_*.pb or output_*.pb)"
189
pip uninstall -y pillow
190
python onnx/backend/test/cmd_tools.py generate-data --clean
192
git diff --exit-code -- . ':!onnx/onnx-data.proto' ':!onnx/onnx-data.proto3' ':!*output_*.pb' ':!*input_*.pb'
193
if [ $? -ne 0 ]; then
194
echo "git diff for test generation without pillow returned failures. Please check updated node test files"
198
- name: Test documentation
199
if: matrix.documentation == 1
201
pip install -r docs/docsgen/source/requirements.txt
202
cd docs/docsgen && make text
203
continue-on-error: true
205
- name: Run Python tests with numpy<2.0
206
if: matrix.python_version == '3.11' || matrix.python_version == '3.12'
208
pip install "numpy<2.0" "pillow<10"
211
publish-test-results:
212
name: "Publish Test Results to Github"
214
runs-on: ubuntu-latest
217
# only needed unless run with comment_mode: off
221
- name: Download Artifacts
222
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
225
pattern: TestResults*
228
- name: Publish Test Results
229
uses: EnricoMi/publish-unit-test-result-action@567cc7f8dcea3eba5da355f6ebc95663310d8a07
231
files: "artifacts/**/*.xml"