Skip to content

ci: open the nightly PRs as the riseproject-dev github app (#2083) #14

ci: open the nightly PRs as the riseproject-dev github app (#2083)

ci: open the nightly PRs as the riseproject-dev github app (#2083) #14

# SPDX-FileCopyrightText: 2026 The RISE Project
# SPDX-License-Identifier: MIT
---
name: Build opencv-contrib-python wheels (riscv64)
on:
workflow_dispatch:
inputs:
version:
description: 'Version glob to (re)build; empty builds every version of docs/packages/opencv-contrib-python.yaml not released yet'
required: false
default: ''
pull_request:
branches: [main]
paths:
- '.github/workflows/build-opencv-contrib-python.yml'
- 'docs/packages/opencv-contrib-python.yaml'
push:
branches: [main]
paths:
- '.github/workflows/build-opencv-contrib-python.yml'
- 'docs/packages/opencv-contrib-python.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read # to fetch code (actions/checkout)
env:
MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64
jobs:
setup:
uses: $/.github/workflows/_setup.yml
with:
package: opencv-contrib-python
version: ${{ inputs.version }}
build_wheels:
needs: [setup]
if: needs.setup.outputs.versions != '[]'
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.versions) }}
name: Build opencv-contrib-python ${{ matrix.version }} cp37-abi3-manylinux_riscv64
runs-on: ubuntu-24.04-riscv
timeout-minutes: 1440
env:
OPENCV_PYTHON_VERSION: ${{ matrix.version }}
steps:
# Upstream tags a release by its build number alone: 5.0.0.93 is tag `93`.
- name: Resolve upstream tag
run: echo "OPENCV_TAG=${OPENCV_PYTHON_VERSION##*.}" >> "$GITHUB_ENV"
- name: Checkout opencv-python ${{ env.OPENCV_PYTHON_VERSION }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: opencv/opencv-python
ref: ${{ env.OPENCV_TAG }}
fetch-depth: 0
persist-credentials: false
# Checked out one by one and shallow: `submodules: true` alongside the
# fetch-depth 0 above pulls ~1.8 GB of OpenCV history.
- name: Resolve submodule commits
run: |
{
echo "OPENCV_SHA=$(git rev-parse HEAD:opencv)"
echo "OPENCV_CONTRIB_SHA=$(git rev-parse HEAD:opencv_contrib)"
echo "OPENCV_EXTRA_SHA=$(git rev-parse HEAD:opencv_extra)"
} >> "$GITHUB_ENV"
- name: Checkout OpenCV sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: opencv/opencv
ref: ${{ env.OPENCV_SHA }}
path: opencv
persist-credentials: false
- name: Checkout OpenCV contrib modules
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: opencv/opencv_contrib
ref: ${{ env.OPENCV_CONTRIB_SHA }}
path: opencv_contrib
persist-credentials: false
- name: Checkout OpenCV test data
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: opencv/opencv_extra
ref: ${{ env.OPENCV_EXTRA_SHA }}
path: opencv_extra
persist-credentials: false
# setup.py re-derives cv2/version.py from `git describe` whenever .git is
# present, so stamp it here and drop the repositories: the build then runs
# no git at all, and cibuildwheel copies ~1 GB less into the container.
# Without .git the stamped `contrib` flag is what selects the package
# name and -DOPENCV_EXTRA_MODULES_PATH, so ENABLE_CONTRIB below cannot be
# the only place it is set.
- name: Stamp the package version
run: |
python3 find_version.py True False False False
grep -Fqx "opencv_version = \"${OPENCV_PYTHON_VERSION}\"" cv2/version.py
grep -Fqx "contrib = True" cv2/version.py
rm -rf .git opencv/.git opencv_contrib/.git opencv_extra/.git
- name: Build wheels
uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
env:
# setup.py always configures -DPYTHON3_LIMITED_API=ON, so the one
# cp37-abi3 wheel built on cp312 is reused to test 3.13 and 3.14.
# Upstream publishes no free-threaded wheel, hence no cp314t entry.
CIBW_BUILD: cp312-manylinux_riscv64 cp313-manylinux_riscv64 cp314-manylinux_riscv64
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
CIBW_BUILD_FRONTEND: build
CIBW_CONFIG_SETTINGS: --build-option=--py-limited-api=cp37
# Upstream's CI_BUILD=1 additionally links Qt5 and bundles DejaVu fonts;
# neither is packaged for riscv64, so highgui is built without a GUI backend.
# PNG_RISCV_RVV defaults to OpenCV's CPU_RVV_SUPPORTED, which is set from a
# -march=rv64gc_v *dispatch* probe; libpng then re-probes the intrinsics with
# the baseline flags and fails the build. Its own sources get no -march either,
# so RVV can only be off here.
CIBW_ENVIRONMENT: >-
ENABLE_CONTRIB=1
MAKEFLAGS=-j$(nproc)
CMAKE_ARGS=-DPNG_RISCV_RVV=off
PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/
CIBW_TEST_ENVIRONMENT: 'PIP_ONLY_BINARY=:all:'
CIBW_TEST_COMMAND: >-
python {project}/tests/get_build_info.py &&
cd {project}/opencv &&
OPENCV_TEST_DATA_PATH={project}/opencv_extra/testdata
python modules/python/test/test.py -v --repo .
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: opencv-contrib-python-${{ env.OPENCV_PYTHON_VERSION }}-cp37-abi3-manylinux_riscv64
path: ./wheelhouse/*.whl
if-no-files-found: error
publish:
name: Publish opencv-contrib-python ${{ matrix.version }}
needs: [setup, build_wheels]
if: needs.setup.outputs.versions != '[]'
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.versions) }}
permissions:
contents: write
pull-requests: write
uses: $/.github/workflows/_publish-wheel.yml
secrets:
app-private-key: ${{ secrets.RISEPROJECT_APP_PRIVATE_KEY }}
with:
artifact-pattern: opencv-contrib-python-${{ matrix.version }}-*-manylinux_riscv64