Skip to content

Commit 6a3c62f

Browse files
committed
Add custom action and unified Linux build
1 parent 0dbdce0 commit 6a3c62f

14 files changed

+680
-3
lines changed

.github/workflows/OCV-PR-Linux.yaml

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: OCV PR Linux
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- '.github/workflows/OCV-PR-Linux.yaml'
9+
workflow_call:
10+
inputs:
11+
workflow_branch:
12+
description: "Branch for ci-gha-workflow repository"
13+
default: "main"
14+
required: false
15+
type: string
16+
17+
concurrency:
18+
group: OCV-PR-Linux-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
branch_eval:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
branches: ${{ steps.determine-branches.outputs.branches }}
26+
steps:
27+
- id: determine-branches
28+
shell: bash
29+
run: |
30+
if [ "${{ github.event.repository.name == 'ci-gha-workflow' }}" = "true" ] ; then
31+
echo "branches=[ '4.x', '5.x' ]" >> "$GITHUB_OUTPUT"
32+
else
33+
echo "branches=[ '${{ github.base_ref }}' ]" >> "$GITHUB_OUTPUT"
34+
fi
35+
Ubuntu:
36+
runs-on: opencv-cn-lin-x86-64
37+
needs:
38+
- branch_eval
39+
strategy:
40+
fail-fast: false
41+
max-parallel: 2
42+
matrix:
43+
version:
44+
- '24.04'
45+
- '22.04'
46+
- '20.04'
47+
branch: ${{ fromJSON(needs.branch_eval.outputs.branches )}}
48+
include:
49+
- version: '24.04'
50+
image: '24.04:20241031'
51+
- version: '22.04'
52+
image: '22.04:20230602'
53+
- version: '20.04'
54+
image: '20.04:20230413'
55+
- version: '24.04'
56+
jpegxl: "true"
57+
- branch: '4.x'
58+
amodules: 'calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio'
59+
pmodules: 'calib3d core dnn features2d gapi imgcodecs imgproc objdetect photo stitching video videoio'
60+
- branch: '5.x'
61+
amodules: '3d core dnn features flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio'
62+
pmodules: '3d core dnn features gapi imgcodecs imgproc objdetect photo stitching video videoio'
63+
defaults:
64+
run:
65+
shell: bash
66+
container:
67+
image: 'quay.io/opencv-ci/opencv-ubuntu-${{ matrix.image }}'
68+
volumes:
69+
- /home/opencv-cn/git_cache:/opt/git_cache
70+
- /home/opencv-cn/ci_cache/opencv:/opt/.ccache
71+
- /home/opencv-cn/binaries_cache:/opt/binaries_cache
72+
- /home/opencv-cn/dnn-models:/opt/dnn-models
73+
env:
74+
ANT_HOME: '/usr/share/ant'
75+
DNN_MODELS: '/opt/dnn-models'
76+
CCACHE_DIR: '/opt/.ccache'
77+
OPENCV_DOWNLOAD_PATH: '/opt/binaries_cache'
78+
CMAKE_OPT: "-DBUILD_DOCS=ON -DBUILD_EXAMPLES=ON -DOPENCV_ENABLE_NONFREE=ON ${{ matrix.jpegxl && '-DWITH_JPEGXL=ON' }}"
79+
HOME: ${{ contains(matrix.image, '24.04') && '/home/ubuntu' || '/home/ci' }}
80+
OPENCV_FOR_THREADS_NUM: 4
81+
CMAKE_BUILD_PARALLEL_LEVEL: 4
82+
83+
# ==========
84+
85+
steps:
86+
87+
- name: Checkout workflow repository
88+
uses: actions/checkout@v4
89+
with:
90+
repository: opencv/ci-gha-workflow
91+
ref: ${{ github.repository == 'opencv/ci-gha-workflow' && github.ref || inputs.workflow_branch }}
92+
93+
- name: Checkout and merge OpenCV
94+
uses: ./checkout-and-merge
95+
with:
96+
target_branch: ${{ matrix.branch }}
97+
author: ${{ github.event.pull_request.user.login }}
98+
source_branch: ${{ github.event.repository.name == 'ci-gha-workflow' && '' || github.head_ref }}
99+
gitcache: '/opt/git_cache'
100+
home: '${{ env.HOME }}'
101+
workdir: '${{ env.HOME }}'
102+
103+
- name: Update extra dnn models
104+
timeout-minutes: 60
105+
working-directory: '${{ env.HOME }}'
106+
run: |
107+
python3 opencv_extra/testdata/dnn/download_models.py -d '${{ env.DNN_MODELS }}/dnn'
108+
echo "OPENCV_DNN_TEST_DATA_PATH=${{ env.DNN_MODELS }}" >> $GITHUB_ENV
109+
110+
- name: Configure and build OpenCV
111+
uses: ./configure-and-build
112+
with:
113+
workdir: '${{ env.HOME }}'
114+
builddir: 'build'
115+
generator: 'Ninja'
116+
enable_contrib: false
117+
options: '${{ env.CMAKE_OPT }}'
118+
119+
- name: Configure and build OpenCV with contrib
120+
uses: ./configure-and-build
121+
with:
122+
workdir: '${{ env.HOME }}'
123+
builddir: 'build-contrib'
124+
generator: 'Ninja'
125+
enable_contrib: true
126+
options: '${{ env.CMAKE_OPT }}'
127+
128+
- name: Run OpenCV tests
129+
uses: ./run-tests
130+
env:
131+
OPENCV_TEST_DATA_PATH: '${{ env.HOME }}/opencv_extra/testdata'
132+
OPENCV_TEST_REQUIRE_DATA: 1
133+
OPENCV_TEST_CHECK_OPTIONAL_DATA: 1
134+
PYTHONPATH: '${{ env.HOME }}/build/python_loader:$PYTHONPATH'
135+
with:
136+
workdir: '${{ env.HOME }}'
137+
builddir: 'build'
138+
wrapper: 'xvfb-run -a'
139+
accuracy_modules: ${{ matrix.amodules }}
140+
performance_modules: ${{ matrix.pmodules }}
141+
skipgroup: "ubuntu24-list"
142+
enable_python: "true"
143+
enable_java: "true"
144+
suffix: '${{ matrix.image }}_${{ matrix.branch }}'

checkout-and-merge/action.yaml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: checkout-and-merge
2+
description: "Checkout OpenCV repositories and merge if needed"
3+
4+
inputs:
5+
repos:
6+
description: "Repository list to clone, can contain 'main', 'contrib' and 'extra'"
7+
default: 'main,contrib,extra'
8+
target_branch:
9+
description: "Target PR branch in OpenCV repository (4.x, 5.x)"
10+
default: "4.x"
11+
author:
12+
description: "PR author"
13+
source_branch:
14+
description: "Source PR branch"
15+
gitcache:
16+
description: "Root folder with git cache (can contain opencv.git/, opencv_contrib.git/, opencv_extra.git/)"
17+
home:
18+
description: "Home directory on executor (for git configuration)"
19+
default: "/home/ubuntu"
20+
workdir:
21+
description: "Work directory on executor, repositories will be cloned to opencv/opencv_contrib/opencv_extra"
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
27+
# opencv
28+
29+
- if: ${{ contains(inputs.repos, 'main') }}
30+
working-directory: ${{ inputs.workdir }}
31+
shell: bash
32+
run: |
33+
echo "::group::Clone opencv"
34+
rm -rf opencv
35+
HOME=${{ inputs.home }} \
36+
git clone \
37+
--reference-if-able ${{ inputs.gitcache }}/opencv.git \
38+
--single-branch \
39+
--branch ${{ inputs.target_branch }} \
40+
https://github.com/opencv/opencv.git
41+
echo "::endgroup::"
42+
43+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'main') && inputs.source_branch }}
44+
working-directory: ${{ inputs.workdir }}
45+
shell: bash
46+
run: |
47+
echo "OPENCV_MAIN_FORK=$(HOME=${{ inputs.home }} git ls-remote --heads https://github.com/${{ inputs.author }}/opencv ${{ inputs.source_branch }})" >> $GITHUB_ENV
48+
49+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'main') && inputs.source_branch && env.OPENCV_MAIN_FORK }}
50+
working-directory: ${{ inputs.workdir }}
51+
shell: bash
52+
run: |
53+
echo "::group::Merge opencv"
54+
HOME=${{ inputs.home }} \
55+
git -C opencv pull -v "https://github.com/${{ inputs.author }}/opencv" "${{ inputs.source_branch }}"
56+
echo "::endgroup::"
57+
58+
# opencv_contrib
59+
60+
- if: ${{ contains(inputs.repos, 'contrib') }}
61+
working-directory: ${{ inputs.workdir }}
62+
shell: bash
63+
run: |
64+
echo "::group::Clone opencv_contrib"
65+
rm -rf opencv_contrib
66+
HOME=${{ inputs.home }} \
67+
git clone \
68+
--reference-if-able ${{ inputs.gitcache }}/opencv_contrib.git \
69+
--single-branch \
70+
--branch ${{ inputs.target_branch }} \
71+
https://github.com/opencv/opencv_contrib.git
72+
echo "::endgroup::"
73+
74+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'contrib') && inputs.source_branch }}
75+
working-directory: ${{ inputs.workdir }}
76+
shell: bash
77+
run: |
78+
echo "OPENCV_CONTRIB_FORK=$(HOME=${{ inputs.home }} git ls-remote --heads https://github.com/${{ inputs.author }}/opencv_contrib ${{ inputs.source_branch }})" >> $GITHUB_ENV
79+
80+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'contrib') && inputs.source_branch && env.OPENCV_CONTRIB_FORK }}
81+
shell: bash
82+
run: |
83+
echo "::group::Merge opencv_contrib"
84+
HOME=${{ inputs.home }} \
85+
git -C opencv_contrib pull -v "https://github.com/${{ inputs.author }}/opencv_contrib" "${{ inputs.source_branch }}"
86+
echo "::endgroup::"
87+
88+
# opencv_extra
89+
90+
- if: ${{ contains(inputs.repos, 'extra') }}
91+
working-directory: ${{ inputs.workdir }}
92+
shell: bash
93+
run: |
94+
echo "::group::Clone opencv_extra"
95+
rm -rf opencv_extra
96+
HOME=${{ inputs.home }} \
97+
git clone \
98+
--reference-if-able ${{ inputs.gitcache }}/opencv_extra.git \
99+
--single-branch \
100+
--branch ${{ inputs.target_branch }} \
101+
https://github.com/opencv/opencv_extra.git
102+
echo "::endgroup::"
103+
104+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'extra') && inputs.source_branch }}
105+
working-directory: ${{ inputs.workdir }}
106+
shell: bash
107+
run: |
108+
echo "OPENCV_EXTRA_FORK=$(HOME=${{ inputs.home }} git ls-remote --heads https://github.com/${{ inputs.author }}/opencv_extra ${{ inputs.source_branch }})" >> $GITHUB_ENV
109+
110+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'extra') && inputs.source_branch && env.OPENCV_EXTRA_FORK }}
111+
shell: bash
112+
run: |
113+
echo "::group::Merge opencv_extra"
114+
HOME=${{ inputs.home }} \
115+
git -C opencv_extra pull -v "https://github.com/${{ inputs.author }}/opencv_extra" "${{ inputs.source_branch }}"
116+
echo "::endgroup::"

configure-and-build/action.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: configure-and-build
2+
description: "Build OpenCV using CMake"
3+
4+
inputs:
5+
workdir:
6+
description: "Work directory on executor, repositories will be cloned to opencv/opencv_contrib/opencv_extra"
7+
builddir:
8+
description: "Build directory"
9+
default: "build"
10+
generator:
11+
description: "CMake generator, e.g. Ninja"
12+
options:
13+
description: "Extra CMake options"
14+
enable_contrib:
15+
description: "Enable opencv_contrib"
16+
default: "false"
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
22+
- working-directory: ${{ inputs.workdir }}
23+
shell: bash
24+
run: |
25+
echo "::group::Configure"
26+
rm -rf ${{ inputs.builddir }}
27+
mkdir -p ${{ inputs.builddir }}
28+
cmake \
29+
-S opencv \
30+
-B ${{ inputs.builddir }} \
31+
-G ${{ inputs.generator }} \
32+
${{ inputs.enable_contrib && '-DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules' }} \
33+
${{ inputs.options }}
34+
echo "::endgroup::"
35+
36+
- working-directory: ${{ inputs.workdir }}
37+
shell: bash
38+
run: |
39+
echo "::group::Build"
40+
cmake --build ${{ inputs.builddir }} 2>&1 | tee ${{ inputs.builddir }}/log.txt
41+
echo "::endgroup::"
42+
43+
- shell: bash
44+
run: |
45+
python3 ./scripts/warnings-handling.py \
46+
${{ inputs.workdir }}/${{ inputs.builddir }}/log.txt

0 commit comments

Comments
 (0)