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

👷 Enhance CI workflow with manylinux container #435

👷 Enhance CI workflow with manylinux container

👷 Enhance CI workflow with manylinux container #435

Workflow file for this run

name: CI
on:
schedule:
- cron: "0 0 * * *"
push:
pull_request:
workflow_dispatch:
jobs:
build-opencv:
name: Build OpenCV (${{ matrix.os.artifact-name || matrix.os.runner }})
strategy:
matrix:
os:
- runner: ubuntu-latest
container: quay.io/pypa/manylinux_2_34_x86_64
artifact-name: linux
- runner: ubuntu-latest
container: quay.io/pypa/musllinux_1_2_x86_64
artifact-name: linux-musl
- runner: windows-latest
- runner: macos-13
- runner: macos-latest
defaults:
run:
shell: bash
env:
SCCACHE_GHA_ENABLED: true
runs-on: ${{ matrix.os.runner }}
container: ${{ matrix.os.container }}
steps:
- name: Get latest release
id: latest-release
run: |
curl -Ls -o /dev/null -w %{url_effective} \
https://github.com/opencv/opencv/releases/latest \
| sed 's#.*tag/\(.*\)$#\1#' > 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: seanmiddleditch/gha-setup-ninja@master
if: matrix.os.artifact-name != 'linux-musl'
- uses: ilammy/msvc-dev-cmd@v1
id: msvc-env
if: startsWith(matrix.os.runner, '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 $(nproc)
- uses: actions/upload-artifact@main
with:
name: opencv-${{ matrix.os.artifact-name || matrix.os.runner }}
path: ./opencv
build:
name: Build Wheel (${{ matrix.os.artifact-name || matrix.os.runner }}, Python ${{ matrix.python }})
needs: [build-opencv]
strategy:
matrix:
os:
- runner: ubuntu-latest
container: quay.io/pypa/manylinux_2_34_x86_64
artifact-name: linux
- runner: ubuntu-latest
container: quay.io/pypa/musllinux_1_2_x86_64
artifact-name: linux-musl
- runner: windows-latest
- runner: macos-13
- runner: 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.runner }}
container: ${{ matrix.os.container }}
steps:
- uses: actions/checkout@main
- uses: actions/download-artifact@main
with:
name: opencv-${{ matrix.os.artifact-name || matrix.os.runner }}
path: ./opencv
- name: Manually install PDM
id: install-pdm
if: matrix.os.container
run: |
set -xve
curl -fsSL https://pdm.fming.dev/install-pdm.py | python3
set PYTHONPATH=$(python${{matrix.python}} -c 'import sys; print(sys.exec_prefix)')
echo "$PYTHONPATH" >> $GITHUB_PATH
echo "$PYTHONPATH/bin" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=$PYTHONPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> $GITHUB_ENV
echo "pythonLocation=$PYTHONPATH" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PYTHONPATH/lib/pkgconfig" >> $GITHUB_ENV
echo "PYTHON_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
echo "PYTHON2_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
echo "PYTHON3_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
- uses: pdm-project/setup-pdm@main
if: steps.install-pdm.conclusion == 'skipped'
with:
python-version: ${{ matrix.python }}
cache: true
- name: Install dependencies
run: pdm install -G :all --no-self
- uses: seanmiddleditch/gha-setup-ninja@master
if: matrix.os.artifact-name != 'linux-musl'
- uses: ilammy/msvc-dev-cmd@v1
id: msvc-env
if: startsWith(matrix.os.runner, 'windows')
- name: Setup MSVC environment
if: steps.msvc-env.conclusion == 'success'
run: |
choco install -y ninja
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.artifact-name || matrix.os.runner }}-${{ matrix.python }}
path: ./dist/*.whl
test:
name: Test Wheel (${{ matrix.os.artifact-name || matrix.os.runner }}, Python ${{ matrix.python }})
needs: [build]
strategy:
matrix:
os:
- runner: ubuntu-latest
container: quay.io/pypa/manylinux_2_34_x86_64
artifact-name: linux
- runner: ubuntu-latest
container: quay.io/pypa/musllinux_1_2_x86_64
artifact-name: linux-musl
- runner: windows-latest
- runner: macos-13
- runner: 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.runner }}
container: ${{ matrix.os.container }}
steps:
- uses: actions/checkout@main
- name: Download wheel
uses: actions/download-artifact@main
with:
name: wheel-${{ matrix.os.artifact-name || matrix.os.runner }}-${{ matrix.python }}
path: ./dist
- name: Manually install PDM
id: install-pdm
if: matrix.os.container
run: |
set -xve
curl -fsSL https://pdm.fming.dev/install-pdm.py | python
set PYTHONPATH=$(python${{matrix.python}} -c 'import sys; print(sys.exec_prefix)')
echo "$PYTHONPATH" >> $GITHUB_PATH
echo "$PYTHONPATH/bin" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=$PYTHONPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> $GITHUB_ENV
echo "pythonLocation=$PYTHONPATH" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PYTHONPATH/lib/pkgconfig" >> $GITHUB_ENV
echo "PYTHON_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
echo "PYTHON2_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
echo "PYTHON3_ROOT_DIR=$PYTHONPATH" >> $GITHUB_ENV
- uses: pdm-project/setup-pdm@main
if: steps.install-pdm.conclusion == 'skipped'
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:
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