-
Notifications
You must be signed in to change notification settings - Fork 386
199 lines (179 loc) · 7.02 KB
/
build-and-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Build and Test
on: [push, pull_request]
env:
ONNXSIM_CI: 1
jobs:
build_wheels:
env:
# Only build universal2 package
# Related issue: https://github.com/pypa/cibuildwheel/issues/1190
CIBW_ARCHS_MACOS: universal2
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_ENVIRONMENT_PASS_LINUX: ONNXSIM_CI
CIBW_BEFORE_ALL_LINUX: WD=`pwd` && /opt/python/cp38-cp38/bin/python -m pip install --target tmp_cmake cmake && cp tmp_cmake/bin/cmake /usr/local/bin/cmake && rm -rf tmp_cmake && /opt/python/cp38-cp38/bin/python -m pip install cmake && cmake --version && whereis cmake
CIBW_BEFORE_ALL_MACOS: WD=`pwd` && python3 -m pip install cmake
CIBW_TEST_REQUIRES_LINUX: pytest flake8 onnxruntime
CIBW_TEST_REQUIRES_MACOS: pytest onnxruntime
CIBW_TEST_REQUIRES_WINDOWS: pytest onnxruntime
CIBW_BEFORE_TEST_LINUX: pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
CIBW_BEFORE_TEST_MACOS: pip install torch torchvision
CIBW_BEFORE_TEST_WINDOWS: pip install torch torchvision
# Skip arm test on x86. Skip python 3.11 test because of the absense of torchvision binary wheel
# Skip python3.7 because of onnxruntime has deprecated it
CIBW_TEST_SKIP: "cp37-* cp311-* *_arm64 *_universal2:arm64"
CIBW_TEST_COMMAND: pytest -v {project}/tests/test_python_api.py
# Only build on Python 3 and skip 32-bit or musl builds
CIBW_BUILD: "cp3?-* cp310-* cp311-*"
CIBW_SKIP: "cp36-* *-win32 *-manylinux_i686 *-musllinux_*"
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Build onnxsim wheels
uses: pypa/[email protected]
env:
CIBW_ENVIRONMENT: CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON" ONNXSIM_PKG_NAME=onnxsim
CIBW_ENVIRONMENT_WINDOWS: USE_MSVC_STATIC_RUNTIME=0 CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON" ONNXSIM_PKG_NAME=onnxsim
- name: Build onnx-simplifier wheels
uses: pypa/[email protected]
env:
# set ONNXSIM_PKG_NAME to onnx-simplifier
CIBW_ENVIRONMENT: CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON" ONNXSIM_PKG_NAME=onnx-simplifier
CIBW_ENVIRONMENT_WINDOWS: USE_MSVC_STATIC_RUNTIME=0 CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON" ONNXSIM_PKG_NAME=onnx-simplifier
- uses: actions/upload-artifact@v3
with:
name: python-dist
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Update version
if: startsWith(github.ref, 'refs/tags/v')
run: |
sed -i "s/0.0.0/${GITHUB_REF/refs\/tags\/v/}/" setup.py
- name: Build sdist
run: |
export ONNXSIM_SDIST=ON
export ONNXSIM_PKG_NAME=onnxsim
pipx run build --sdist
export ONNXSIM_PKG_NAME=onnx-simplifier
pipx run build --sdist
- name: Install and test sdist
run: |
# It's important to leave the project directory where a 'onnxsim' subdirectory exists
cd dist
python3 -m pip install onnxruntime
python3 -m pip install onnxsim-*.tar.gz
python3 -c "import onnxsim; print(dir(onnxsim))"
python3 -m pip uninstall -y onnxsim
python3 -m pip install onnx-simplifier-*.tar.gz
python3 -c "import onnxsim; print(dir(onnxsim))"
python3 -m pip uninstall -y onnx-simplifier
- uses: actions/upload-artifact@v3
with:
name: python-dist
path: dist/*.tar.gz
upload_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
# unpacks python-dist artifact into dist/
# if `name: python-dist` is omitted, the action will create extra parent dir
name: python-dist
path: dist
- name: Publish distribution 📦 to Test PyPI
if: ${{ github.ref == 'refs/heads/master' }}
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
build_wasm:
name: Build WebAssembly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: mymindstorm/setup-emsdk@v11
- uses: seanmiddleditch/gha-setup-ninja@v3
- name: Verify
run: emcc -v
- name: Build
run: ./build_wasm.sh
- uses: actions/upload-artifact@v3
with:
name: wasm
path: |
build-wasm-node-OFF/onnxsim.js
build-wasm-node-OFF/onnxsim.wasm
- name: Upload to convertmodel.com
if: ${{ github.ref == 'refs/heads/master' }}
run: |
wget https://gosspublic.alicdn.com/ossutil/1.7.14/ossutil64
chmod 755 ossutil64
echo "[Credentials]" >> ~/.ossutilconfig
echo "language=EN" >> ~/.ossutilconfig
echo "endpoint=oss-cn-beijing.aliyuncs.com" >> ~/.ossutilconfig
echo "accessKeyID=${{ secrets.OSS_ACCESS_KEY }}" >> ~/.ossutilconfig
echo "accessKeySecret=${{ secrets.OSS_SECRET_KEY }}" >> ~/.ossutilconfig
gzip -c -9 build-wasm-node-OFF/onnxsim.wasm > onnxsim_gz.wasm
./ossutil64 --config-file ~/.ossutilconfig cp -u onnxsim_gz.wasm oss://converter-web/onnxsim.wasm --meta=Content-Type:application/wasm#Content-Encoding:gzip
./ossutil64 --config-file ~/.ossutilconfig cp -u build-wasm-node-OFF/onnxsim.js oss://converter-web/
build_wasm_with_noderawfs:
name: Build WebAssembly with NODERAWFS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: mymindstorm/setup-emsdk@v11
- uses: seanmiddleditch/gha-setup-ninja@v3
- name: Verify
run: emcc -v
- name: Build
run: ./build_wasm.sh ON
- uses: actions/upload-artifact@v3
with:
name: wasm-with-noderawfs
path: |
build-wasm-node-ON/onnxsim.js
build-wasm-node-ON/onnxsim.wasm
build_native:
name: Build Native
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: seanmiddleditch/gha-setup-ninja@v3
- name: Build
run: |
mkdir build-native
cd build-native
cmake -GNinja ..
ninja onnxsim_bin
- uses: actions/upload-artifact@v3
with:
name: native
path: |
build-native/onnxsim