This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
262 lines (212 loc) · 6.36 KB
/
ci.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
name: CI
on:
schedule:
- cron: "0 0 * * *"
push:
pull_request:
workflow_dispatch:
jobs:
build-opencv:
name: Build OpenCV
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-13
- macos-latest
defaults:
run:
shell: bash
env:
SCCACHE_GHA_ENABLED: true
runs-on: ${{ matrix.os }}
container: ${{ startsWith(matrix.os, 'ubuntu') && 'quay.io/pypa/manylinux_2_34_x86_64' }}
steps:
- name: Get latest release
id: latest-release
run: |
curl -s https://api.github.com/repos/opencv/opencv/releases/latest \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
| jq -r '.tag_name' | tee latest-release.txt
echo "tag=$(cat latest-release.txt)" >> $GITHUB_OUTPUT
- uses: actions/checkout@main
with:
repository: opencv/opencv
ref: ${{ steps.latest-release.outputs.tag }}
- uses: mozilla-actions/sccache-action@main
- uses: ilammy/msvc-dev-cmd@v1
id: msvc-env
if: startsWith(matrix.os, 'windows')
- name: Setup MSVC environment
if: steps.msvc-env.conclusion == 'success'
run: |
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
echo "CC=cl" >> $GITHUB_ENV
echo "CXX=cl" >> $GITHUB_ENV
- name: CMake build
run: |
mkdir build
cd build
cmake .. \
-D CMAKE_INSTALL_PREFIX=../opencv \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache \
-D BUILD_LIST=core,imgproc,features2d \
-D BUILD_SHARED_LIBS=OFF \
-D ENABLE_CCACHE=ON \
-D WITH_ADE=OFF \
-D WITH_PROTOBUF=OFF \
-D WITH_QUIRC=OFF \
-D WITH_ITT=OFF \
-D WITH_OPENEXR=OFF \
-D WITH_WEBP=OFF \
-D WITH_JASPER=OFF \
-D WITH_OPENJPEG=OFF \
-D WITH_JPEG=OFF \
-D WITH_PNG=OFF \
-D WITH_TIFF=OFF
cmake --build . --target install --parallel 4
- uses: actions/upload-artifact@main
with:
name: opencv-${{ matrix.os }}
path: ./opencv
build:
name: Build Wheel
needs: [build-opencv]
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-13
- macos-latest
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python: "3.8"
- os: macos-latest
python: "3.9"
fail-fast: false
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
container: ${{ startsWith(matrix.os, 'ubuntu') && 'quay.io/pypa/manylinux_2_34_x86_64' || '' }}
steps:
- uses: actions/checkout@main
- uses: actions/download-artifact@main
with:
name: opencv-${{ matrix.os }}
path: ./opencv
- uses: pdm-project/setup-pdm@main
with:
python-version: ${{ matrix.python }}
cache: true
- name: Install dependencies
run: pdm install -G :all --no-self
- uses: ilammy/msvc-dev-cmd@v1
id: msvc-env
if: startsWith(matrix.os, 'windows')
- name: Setup MSVC environment
if: steps.msvc-env.conclusion == 'success'
run: |
CV_DIR=$(find ./opencv/x64 | grep -i '\.cmake$' | head -n 1)
echo "OpenCV_DIR=$(realpath $(dirname $CV_DIR))" >> $GITHUB_ENV
echo "OpenCV_STATIC=ON" >> $GITHUB_ENV
- name: Setup Unix environment
if: steps.msvc-env.conclusion == 'skipped'
run: |
echo "OpenCV_DIR=$(pwd)/opencv/lib/cmake/opencv4" >> $GITHUB_ENV
echo "OpenCV_STATIC=ON" >> $GITHUB_ENV
- name: Build wheel
run: pdm build -v
- uses: actions/upload-artifact@main
with:
name: wheel-${{matrix.os}}-${{matrix.python}}
path: ./dist/*.whl
test:
name: Test Wheel
needs: [build]
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-13
- macos-latest
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python: "3.8"
- os: macos-latest
python: "3.9"
fail-fast: false
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@main
- name: Download wheel
uses: actions/download-artifact@main
with:
name: wheel-${{matrix.os}}-${{matrix.python}}
path: ./dist
- uses: pdm-project/setup-pdm@main
with:
python-version: ${{ matrix.python }}
cache: true
- name: Install dependencies
run: |
pdm install -G test --no-self
pdm add -v dist/*.whl --frozen-lockfile
- name: Run tests
run: |
pdm run pytest
cleanup:
name: Cleanup artifacts
runs-on: ubuntu-latest
needs: [build, test]
steps:
- uses: geekyeggo/delete-artifact@main
with:
name: opencv-*
- uses: actions/download-artifact@main
- name: Merge wheels
run: |
mkdir dist
cp -v wheel-*/*.whl dist/
- uses: actions/upload-artifact@main
with:
name: wheel-all
path: ./dist/*.whl
release:
name: Release
needs: [build, test]
if: startsWith(github.ref, 'refs/tags/v') && github.head_ref == ''
runs-on: ubuntu-latest
permissions:
# This permission is needed for private repositories.
contents: read
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@main
- uses: actions/download-artifact@main
with:
name: wheel-all
path: ./dist
- uses: pdm-project/setup-pdm@main
with:
python-version: "3"
cache: true
- name: Publish to PyPI
env:
PDM_PUBLISH_USERNAME: __token__
PDM_PUBLISH_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
pdm build --no-wheel
pdm publish --skip-existing --no-build