Skip to content
This repository was archived by the owner on Jan 3, 2025. It is now read-only.

Commit 9b8f473

Browse files
committed
👷 Enhance CI workflow with manylinux container
1 parent 33783ea commit 9b8f473

File tree

2 files changed

+96
-38
lines changed

2 files changed

+96
-38
lines changed

.github/workflows/ci.yml

Lines changed: 92 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ on:
99

1010
jobs:
1111
build-opencv:
12-
name: Build OpenCV
12+
name: Build OpenCV (${{ matrix.os.artifact-name || matrix.os.runner }})
1313

1414
strategy:
1515
matrix:
1616
os:
17-
- ubuntu-latest
18-
- windows-latest
19-
- macos-13
20-
- macos-latest
17+
- runner: ubuntu-latest
18+
container: quay.io/pypa/manylinux_2_34_x86_64
19+
artifact-name: linux
20+
- runner: ubuntu-latest
21+
container: quay.io/pypa/musllinux_1_2_x86_64
22+
artifact-name: linux-musl
23+
- runner: windows-latest
24+
- runner: macos-13
25+
- runner: macos-latest
2126

2227
defaults:
2328
run:
@@ -26,33 +31,40 @@ jobs:
2631
env:
2732
SCCACHE_GHA_ENABLED: true
2833

29-
runs-on: ${{ matrix.os }}
34+
runs-on: ${{ matrix.os.runner }}
35+
container: ${{ matrix.os.container }}
3036

3137
steps:
3238
- name: Get latest release
3339
id: latest-release
3440
run: |
35-
curl -s https://api.github.com/repos/opencv/opencv/releases/latest \
36-
-H "Accept: application/vnd.github.v3+json" \
37-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
38-
| jq -r '.tag_name' | tee latest-release.txt
41+
curl -Ls -o /dev/null -w %{url_effective} \
42+
https://github.com/opencv/opencv/releases/latest \
43+
| sed 's#.*tag/\(.*\)$#\1#' > latest-release.txt
3944
echo "tag=$(cat latest-release.txt)" >> $GITHUB_OUTPUT
4045
4146
- uses: actions/checkout@main
4247
with:
4348
repository: opencv/opencv
4449
ref: ${{ steps.latest-release.outputs.tag }}
4550

51+
- uses: seanmiddleditch/gha-setup-ninja@master
52+
id: setup-ninja
53+
if: matrix.os.artifact-name != 'linux-musl'
54+
55+
- name: Manually install ninja
56+
if: steps.setup-ninja.conclusion == 'skipped'
57+
run: apk add samurai
58+
4659
- uses: mozilla-actions/sccache-action@main
4760

4861
- uses: ilammy/msvc-dev-cmd@v1
4962
id: msvc-env
50-
if: startsWith(matrix.os, 'windows')
63+
if: startsWith(matrix.os.runner, 'windows')
5164

5265
- name: Setup MSVC environment
5366
if: steps.msvc-env.conclusion == 'success'
5467
run: |
55-
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
5668
echo "CC=cl" >> $GITHUB_ENV
5769
echo "CXX=cl" >> $GITHUB_ENV
5870
@@ -62,6 +74,7 @@ jobs:
6274
cd build
6375
6476
cmake .. \
77+
-D CMAKE_GENERATOR=Ninja \
6578
-D CMAKE_INSTALL_PREFIX=../opencv \
6679
-D CMAKE_BUILD_TYPE=Release \
6780
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
@@ -81,24 +94,29 @@ jobs:
8194
-D WITH_PNG=OFF \
8295
-D WITH_TIFF=OFF
8396
84-
cmake --build . --target install --parallel 4
97+
cmake --build . --target install --parallel $(nproc)
8598
8699
- uses: actions/upload-artifact@main
87100
with:
88-
name: opencv-${{ matrix.os }}
101+
name: opencv-${{ matrix.os.artifact-name || matrix.os.runner }}
89102
path: ./opencv
90103

91104
build:
92-
name: Build Wheel
105+
name: Build Wheel (${{ matrix.os.artifact-name || matrix.os.runner }}, Python ${{ matrix.python }})
93106
needs: [build-opencv]
94107

95108
strategy:
96109
matrix:
97110
os:
98-
- ubuntu-latest
99-
- windows-latest
100-
- macos-13
101-
- macos-latest
111+
- runner: ubuntu-latest
112+
container: quay.io/pypa/manylinux_2_34_x86_64
113+
artifact-name: linux
114+
# - runner: ubuntu-latest
115+
# container: quay.io/pypa/musllinux_1_2_x86_64
116+
# artifact-name: linux-musl
117+
- runner: windows-latest
118+
- runner: macos-13
119+
- runner: macos-latest
102120
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
103121
exclude:
104122
- os: macos-latest
@@ -111,30 +129,47 @@ jobs:
111129
run:
112130
shell: bash
113131

114-
runs-on: ${{ matrix.os }}
132+
runs-on: ${{ matrix.os.runner }}
133+
container: ${{ matrix.os.container }}
115134

116135
steps:
117136
- uses: actions/checkout@main
118137

119138
- uses: actions/download-artifact@main
120139
with:
121-
name: opencv-${{ matrix.os }}
140+
name: opencv-${{ matrix.os.artifact-name || matrix.os.runner }}
122141
path: ./opencv
123142

124143
- uses: pdm-project/setup-pdm@main
144+
id: install-pdm
145+
if: ${{ !matrix.os.container }}
125146
with:
126147
python-version: ${{ matrix.python }}
127148
cache: true
128149

129-
- name: Install dependencies
130-
run: pdm install -G :all --no-self
150+
- name: Manually install PDM
151+
if: steps.install-pdm.conclusion == 'skipped'
152+
run: |
153+
pipx install pdm
154+
export PYTHONPATH=$(python${{matrix.python}} -c 'import sys; print(sys.exec_prefix)')
131155
132-
- uses: ilammy/msvc-dev-cmd@v1
133-
id: msvc-env
134-
if: startsWith(matrix.os, 'windows')
156+
echo "$PYTHONPATH" >> $GITHUB_PATH
157+
echo "$PYTHONPATH/bin" >> $GITHUB_PATH
158+
echo "LD_LIBRARY_PATH=$PYTHONPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> $GITHUB_ENV
159+
echo "pythonLocation=$PYTHONPATH" >> $GITHUB_ENV
160+
echo "PKG_CONFIG_PATH=$PYTHONPATH/lib/pkgconfig" >> $GITHUB_ENV
135161
136-
- name: Setup MSVC environment
137-
if: steps.msvc-env.conclusion == 'success'
162+
- uses: seanmiddleditch/gha-setup-ninja@master
163+
id: setup-ninja
164+
if: matrix.os.artifact-name != 'linux-musl'
165+
166+
- name: Manually install ninja
167+
if: steps.setup-ninja.conclusion == 'skipped'
168+
run: apk add samurai
169+
170+
- name: Setup Windows environment
171+
id: msvc-env
172+
if: startsWith(matrix.os.runner, 'windows')
138173
run: |
139174
CV_DIR=$(find ./opencv/x64 | grep -i '\.cmake$' | head -n 1)
140175
echo "OpenCV_DIR=$(realpath $(dirname $CV_DIR))" >> $GITHUB_ENV
@@ -151,20 +186,25 @@ jobs:
151186

152187
- uses: actions/upload-artifact@main
153188
with:
154-
name: wheel-${{matrix.os}}-${{matrix.python}}
189+
name: wheel-${{ matrix.os.artifact-name || matrix.os.runner }}-${{ matrix.python }}
155190
path: ./dist/*.whl
156191

157192
test:
158-
name: Test Wheel
193+
name: Test Wheel (${{ matrix.os.artifact-name || matrix.os.runner }}, Python ${{ matrix.python }})
159194
needs: [build]
160195

161196
strategy:
162197
matrix:
163198
os:
164-
- ubuntu-latest
165-
- windows-latest
166-
- macos-13
167-
- macos-latest
199+
- runner: ubuntu-latest
200+
container: quay.io/pypa/manylinux_2_34_x86_64
201+
artifact-name: linux
202+
# - runner: ubuntu-latest
203+
# container: quay.io/pypa/musllinux_1_2_x86_64
204+
# artifact-name: linux-musl
205+
- runner: windows-latest
206+
- runner: macos-13
207+
- runner: macos-latest
168208
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
169209
exclude:
170210
- os: macos-latest
@@ -177,26 +217,41 @@ jobs:
177217
run:
178218
shell: bash
179219

180-
runs-on: ${{ matrix.os }}
220+
runs-on: ${{ matrix.os.runner }}
221+
container: ${{ matrix.os.container }}
181222

182223
steps:
183224
- uses: actions/checkout@main
184225

185226
- name: Download wheel
186227
uses: actions/download-artifact@main
187228
with:
188-
name: wheel-${{matrix.os}}-${{matrix.python}}
229+
name: wheel-${{ matrix.os.artifact-name || matrix.os.runner }}-${{ matrix.python }}
189230
path: ./dist
190231

191232
- uses: pdm-project/setup-pdm@main
233+
id: install-pdm
234+
if: ${{ !matrix.os.container }}
192235
with:
193236
python-version: ${{ matrix.python }}
194237
cache: true
195238

239+
- name: Manually install PDM
240+
if: steps.install-pdm.conclusion == 'skipped'
241+
run: |
242+
pipx install pdm
243+
export PYTHONPATH=$(python${{matrix.python}} -c 'import sys; print(sys.exec_prefix)')
244+
245+
echo "$PYTHONPATH" >> $GITHUB_PATH
246+
echo "$PYTHONPATH/bin" >> $GITHUB_PATH
247+
echo "LD_LIBRARY_PATH=$PYTHONPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> $GITHUB_ENV
248+
echo "pythonLocation=$PYTHONPATH" >> $GITHUB_ENVd
249+
echo "PKG_CONFIG_PATH=$PYTHONPATH/lib/pkgconfig" >> $GITHUB_ENV
250+
196251
- name: Install dependencies
197252
run: |
198253
pdm install -G test --no-self
199-
pdm add dist/*.whl --no-lock
254+
pdm add -v dist/*.whl --frozen-lockfile
200255
201256
- name: Run tests
202257
run: |
@@ -246,7 +301,6 @@ jobs:
246301

247302
- uses: pdm-project/setup-pdm@main
248303
with:
249-
python-version: "3"
250304
cache: true
251305

252306
- name: Publish to PyPI

pdm_build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import subprocess
55
import sys
6+
import sysconfig
67
from pathlib import Path
78

89
from numpy import get_include as get_numpy_include_dir
@@ -51,6 +52,9 @@ def build_extension(self, ext: CMakeExtension) -> None:
5152
cmake_args = [
5253
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
5354
f"-DPython_EXECUTABLE={sys.executable}",
55+
f"-DPython_ROOT_DIR={sys.exec_prefix}",
56+
f"-DPython_INCLUDE_DIR={sysconfig.get_path('include')}",
57+
f"-DPython_LIBRARY={sysconfig.get_config_var('LIBDIR')}",
5458
f"-DPython_NumPy_INCLUDE_DIR={get_numpy_include_dir()}",
5559
f"-Dpybind11_DIR={get_pybind11_cmake_dir()}",
5660
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm

0 commit comments

Comments
 (0)