onnx

Форк
0
231 строка · 8.3 Кб
1
# Copyright (c) ONNX Project Contributors
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
name: CI
6

7
on:
8
  schedule:
9
    - cron: '0 0 * * *'  # every day at midnight for reporting code coverage to codecov
10
  push:
11
    branches:
12
      - main
13
  pull_request:
14
  merge_group:
15
  workflow_dispatch:
16

17
permissions:  # set top-level default permissions as security best practice
18
  contents: read
19

20
concurrency:
21
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
22
  cancel-in-progress: true
23

24
jobs:
25
  test:
26
    name: Test ${{ matrix.os }}, ${{ matrix.python_version }}, ${{ matrix.protobuf_type }}, debug=${{ matrix.debug_build }}, onnx_ml=${{ matrix.onnx_ml }}, doc=${{ matrix.documentation }}
27
    strategy:
28
      fail-fast: false
29
      matrix:
30
        os: [ubuntu-latest, windows-latest, macos-latest]
31
        python_version: ['3.12', '3.11', '3.10', '3.9', '3.8']
32
        include:
33
          - python_version: '3.12'
34
            onnx_ml: 1
35
            debug_build: 1
36
            documentation: 1
37
            protobuf_type: 'Internal'
38
          - python_version: '3.11'
39
            onnx_ml: 1
40
            debug_build: 0
41
            documentation: 0
42
            protobuf_type: 'External'
43
          - python_version: '3.10'
44
            onnx_ml: 0
45
            debug_build: 0
46
            documentation: 0
47
            protobuf_type: 'Internal'
48
          - python_version: '3.9'
49
            onnx_ml: 1
50
            debug_build: 0
51
            documentation: 0
52
            protobuf_type: 'External'
53
          - python_version: '3.8'
54
            onnx_ml: 0
55
            debug_build: 0
56
            documentation: 0
57
            protobuf_type: 'Internal'
58
    runs-on: ${{ matrix.os }}
59
    steps:
60
      - name: Checkout repository
61
        uses: actions/checkout@9a9194f87191a7e9055e3e9b95b8cfb13023bb08
62

63
      - name: Set up Python
64
        uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
65
        with:
66
          python-version: ${{ matrix.python_version }}
67

68
      - name: Show versions
69
        run: |
70
          python --version
71
          cmake --version
72

73
      - name: Install external protobuf - Linux
74
        if: matrix.protobuf_type == 'External' && matrix.os == 'ubuntu-latest'
75
        run: |
76
          sudo apt-get install libprotobuf-dev protobuf-compiler
77

78
      - name: Install external protobuf - MacOS
79
        if: matrix.protobuf_type == 'External' && matrix.os == 'macos-latest'
80
        run: |
81
          source workflow_scripts/protobuf/build_protobuf_unix.sh 3 $(pwd)/protobuf/protobuf_install
82

83
      - name: Set up MSBuild
84
        if: matrix.os == 'windows-latest'
85
        uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0
86
        with:
87
          msbuild-architecture: x64
88

89
      - name: Install external protobuf - Windows
90
        if: matrix.protobuf_type == 'External' && matrix.os == 'windows-latest'
91
        run: |
92
          workflow_scripts/protobuf/build_protobuf_win.ps1
93

94
      - name: Install dependencies
95
        run: |
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
100

101
      - name: Build and install ONNX - Linux
102
        if: matrix.os == 'ubuntu-latest'
103
        run: |
104
          if [ "${{ matrix.protobuf_type }}" == "External" ]; then
105
            export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
106
          fi
107
          pip install -e ".[reference]" -v
108
        env:
109
          DEBUG: ${{ matrix.debug_build }}
110
          ONNX_ML: ${{ matrix.onnx_ml }}
111
          ONNX_BUILD_TESTS: 1
112
          CMAKE_ARGS: "-DONNX_WERROR=ON -DCMAKE_CXX_FLAGS='-fsanitize=undefined -fno-sanitize-recover=all '"
113

114
      - name: Build and install ONNX - MacOS
115
        if: matrix.os == 'macos-latest'
116
        run: |
117
          pip install -e ".[reference]" -v
118
        env:
119
          DEBUG: ${{ matrix.debug_build }}
120
          ONNX_ML: ${{ matrix.onnx_ml }}
121
          ONNX_BUILD_TESTS: 1
122
          CMAKE_ARGS: "-DONNX_WERROR=ON"
123

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'
126
        run: |
127
          python setup.py build_ext --inplace
128
          python setup.py install
129
        env:
130
          DEBUG: ${{ matrix.debug_build }}
131
          ONNX_ML: ${{ matrix.onnx_ml }}
132
          ONNX_BUILD_TESTS: 1
133
          CMAKE_ARGS: "-DONNX_WERROR=OFF -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON"
134

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')
137
        run: |
138
          pip install -e . -v
139
        env:
140
          DEBUG: ${{ matrix.debug_build }}
141
          ONNX_ML: ${{ matrix.onnx_ml }}
142
          ONNX_BUILD_TESTS: 1
143
          CMAKE_ARGS: "-DONNX_WERROR=OFF -DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DONNX_USE_LITE_PROTO=ON"
144

145
      - name: pip freeze
146
        run: |
147
          pip freeze
148

149
      - name: Run Python tests
150
        run: |
151
          pytest -sv --cov=onnx --cov-report=xml --cov-append --cov-branch --junit-xml pytest.xml -n auto --dist loadscope
152

153
      - name: Run C++ tests
154
        if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
155
        run: |
156
          export LD_LIBRARY_PATH="./.setuptools-cmake-build/:$LD_LIBRARY_PATH"
157
          ./.setuptools-cmake-build/onnx_gtests
158

159
      - name: Upload coverage to Codecov
160
        if: always()
161
        uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673
162
        with:
163
          token: ${{ secrets.CODECOV_TOKEN }}
164

165
      - name: Upload Test Results
166
        if: always()
167
        uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
168
        with:
169
          name: TestResults-(${{ matrix.os }}-${{ matrix.python_version }})
170
          path: pytest.xml          
171

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'
176
        run: |
177
          python onnx/backend/test/cmd_tools.py generate-data --clean
178
          git status
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"
182
            exit 1
183
          fi
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)"
187
            exit 1
188
          fi
189
          pip uninstall -y pillow
190
          python onnx/backend/test/cmd_tools.py generate-data --clean
191
          git status
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"
195
            exit 1
196
          fi
197

198
      - name: Test documentation
199
        if: matrix.documentation == 1
200
        run: |
201
          pip install -r docs/docsgen/source/requirements.txt
202
          cd docs/docsgen && make text
203
        continue-on-error: true
204

205
      - name: Run Python tests with numpy<2.0
206
        if: matrix.python_version == '3.11' || matrix.python_version == '3.12'
207
        run: |
208
          pip install "numpy<2.0" "pillow<10"
209
          pytest -s
210

211
  publish-test-results:
212
    name: "Publish Test Results to Github"
213
    needs: test
214
    runs-on: ubuntu-latest
215
    permissions:
216
      checks: write
217
      # only needed unless run with comment_mode: off
218
      pull-requests: write
219
    if: always()
220
    steps:
221
      - name: Download Artifacts
222
        uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
223
        with:
224
          path: artifacts
225
          pattern: TestResults*
226
          merge-multiple: true
227

228
      - name: Publish Test Results
229
        uses: EnricoMi/publish-unit-test-result-action@567cc7f8dcea3eba5da355f6ebc95663310d8a07
230
        with:
231
          files: "artifacts/**/*.xml"
232

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.