Skip to content

Commit 02f135a

Browse files
committed
Add custom action and unified Linux build
1 parent 7c3d534 commit 02f135a

File tree

9 files changed

+968
-3
lines changed

9 files changed

+968
-3
lines changed

.editorconfig

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 4
12+
13+
[*.json]
14+
indent_size = 4
15+
16+
[*.{yml,yaml}]
17+
indent_size = 2
18+
19+
[*.{bat,cmd,cmd.*}]
20+
end_of_line = crlf
21+
indent_style = space
22+
indent_size = 2
23+
24+
[*.{ps1,ps1.*}]
25+
end_of_line = crlf
26+
indent_style = space
27+
indent_size = 4
28+
29+
[*.{md,markdown}]
30+
indent_size = 2

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

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
# TODO: are following paths necessary?
10+
- 'checkout-and-merge/*'
11+
- 'configure-and-build/*'
12+
- 'run-tests/*'
13+
- 'scripts/runner.py'
14+
- 'scripts/test-plan.json'
15+
workflow_call:
16+
inputs:
17+
workflow_branch:
18+
description: "Branch for ci-gha-workflow repository"
19+
default: "main"
20+
required: false
21+
type: string
22+
23+
concurrency:
24+
group: OCV-PR-Linux-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
29+
branch_eval:
30+
runs-on: ubuntu-24.04
31+
outputs:
32+
branches: ${{ steps.determine-branches.outputs.branches }}
33+
steps:
34+
- id: determine-branches
35+
shell: bash
36+
run: |
37+
if [ "${{ github.event.repository.name == 'ci-gha-workflow' }}" = "true" ] ; then
38+
echo "branches=[ '4.x', '5.x' ]" >> "$GITHUB_OUTPUT"
39+
else
40+
echo "branches=[ '${{ github.base_ref }}' ]" >> "$GITHUB_OUTPUT"
41+
fi
42+
43+
Ubuntu:
44+
# runs-on: opencv-ru-lin-riscv
45+
runs-on: opencv-cn-lin-x86-64
46+
needs:
47+
- branch_eval
48+
strategy:
49+
# NOTE: Debugging
50+
# fail-fast: true
51+
# max-parallel: 3
52+
fail-fast: false
53+
max-parallel: 3
54+
matrix:
55+
version:
56+
- '24.04'
57+
- '22.04'
58+
- '20.04'
59+
# TODO: enable later
60+
# - '24.04_asan'
61+
branch: ${{ fromJSON(needs.branch_eval.outputs.branches )}}
62+
include:
63+
- version: '24.04'
64+
image: '24.04:20241031'
65+
jpegxl: true
66+
avif: true
67+
avx2: true
68+
# TODO: enable later
69+
# - version: '24.04_asan'
70+
# image: '24.04:20241031'
71+
# asan: true
72+
# jpegxl: true
73+
# avif: true
74+
- version: '22.04'
75+
image: '22.04:20230602'
76+
avif: true
77+
plugins: true
78+
- version: '20.04'
79+
image: '20.04:20230413'
80+
limited_api: true
81+
82+
defaults:
83+
run:
84+
shell: bash
85+
container:
86+
image: 'quay.io/opencv-ci/opencv-ubuntu-${{ matrix.image }}'
87+
volumes:
88+
# NOTE: RU config
89+
# - /mnt/cache/git_cache:/opt/git_cache
90+
# - /mnt/cache/ci_cache/opencv:/opt/.ccache
91+
# - /mnt/cache/binaries_cache:/opt/binaries_cache
92+
# - vol_dnn_models:/opt/dnn-models
93+
# NOTE: CN config
94+
- /home/opencv-cn/git_cache:/opt/git_cache
95+
- /home/opencv-cn/ci_cache/opencv:/opt/.ccache
96+
- /home/opencv-cn/binaries_cache:/opt/binaries_cache
97+
- /home/opencv-cn/dnn-models:/opt/dnn-models
98+
options: '--user root:root'
99+
env:
100+
ANT_HOME: '/usr/share/ant'
101+
DNN_MODELS: '/opt/dnn-models'
102+
CCACHE_DIR: '/opt/.ccache'
103+
CCACHE_MAXSIZE: '3G'
104+
OPENCV_DOWNLOAD_PATH: '/opt/binaries_cache'
105+
CMAKE_OPT: >-
106+
-DBUILD_DOCS=ON
107+
-DBUILD_EXAMPLES=ON
108+
-DOPENCV_ENABLE_NONFREE=ON
109+
-DWITH_IMGCODEC_GIF=ON
110+
${{ matrix.jpegxl && '-DWITH_JPEGXL=ON' }}
111+
${{ matrix.avif && '-DWITH_AVIF=ON' }}
112+
${{ matrix.avx2 && '-DCPU_BASELINE=AVX2'}}
113+
${{ matrix.plugins && '-DVIDEOIO_PLUGIN_LIST=all -DHIGHGUI_PLUGIN_LIST=all' }}
114+
${{ matrix.limited_api && '-DPYTHON3_LIMITED_API=ON' }}
115+
${{ matrix.asan && '-DENABLE_OMIT_FRAME_POINTER=OFF -DCMAKE_CXX_FLAGS="-fsanitize=address"' }}
116+
HOME: ${{ contains(matrix.image, '24.04') && '/home/ubuntu' || '/home/ci' }}
117+
MAIN_BUILD_DIR: "${{ (github.event.repository.name != 'opencv_contrib') && 'build' || 'build-contrib' }}"
118+
# NOTE: CN config
119+
OPENCV_FOR_THREADS_NUM: 8
120+
CMAKE_BUILD_PARALLEL_LEVEL: 8
121+
# NOTE: RU config
122+
# OPENCV_FOR_THREADS_NUM: 10
123+
# CMAKE_BUILD_PARALLEL_LEVEL: 20
124+
125+
# ==========
126+
127+
steps:
128+
129+
- name: Checkout workflow repository
130+
uses: actions/checkout@v4
131+
with:
132+
repository: opencv/ci-gha-workflow
133+
ref: "${{ github.repository == 'opencv/ci-gha-workflow' && github.ref || inputs.workflow_branch }}"
134+
135+
- name: Checkout and merge OpenCV
136+
uses: ./checkout-and-merge
137+
with:
138+
target_branch: "${{ matrix.branch }}"
139+
author: "${{ github.event.pull_request.user.login }}"
140+
source_branch: "${{ github.event.repository.name == 'ci-gha-workflow' && '' || github.head_ref }}"
141+
gitcache: '/opt/git_cache'
142+
home: '${{ env.HOME }}'
143+
workdir: '${{ env.HOME }}'
144+
145+
- name: Update extra dnn models
146+
timeout-minutes: 60
147+
working-directory: '${{ env.HOME }}'
148+
run: |
149+
ls -lR ${{ env.DNN_MODELS }}
150+
python3 opencv_extra/testdata/dnn/download_models.py \
151+
--cleanup \
152+
--dst '${{ env.DNN_MODELS }}/dnn'
153+
echo "OPENCV_DNN_TEST_DATA_PATH=${{ env.DNN_MODELS }}" >> $GITHUB_ENV
154+
155+
- if: ${{ github.event.repository.name != 'opencv_contrib' }}
156+
name: Configure and build OpenCV
157+
uses: ./configure-and-build
158+
with:
159+
workdir: '${{ env.HOME }}'
160+
builddir: 'build'
161+
generator: 'Ninja'
162+
options: '${{ env.CMAKE_OPT }}'
163+
164+
- name: Configure and build OpenCV with contrib
165+
uses: ./configure-and-build
166+
with:
167+
workdir: '${{ env.HOME }}'
168+
builddir: 'build-contrib'
169+
generator: 'Ninja'
170+
options: '-DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules ${{ env.CMAKE_OPT }}'
171+
172+
- name: Run OpenCV tests
173+
uses: ./run-tests
174+
env:
175+
OPENCV_TEST_DATA_PATH: '${{ env.HOME }}/opencv_extra/testdata'
176+
OPENCV_TEST_REQUIRE_DATA: 1
177+
OPENCV_TEST_CHECK_OPTIONAL_DATA: 1
178+
PYTHONPATH: '${{ env.HOME }}/${{ env.MAIN_BUILD_DIR }}/python_loader:$PYTHONPATH'
179+
# TODO: enable later
180+
# ASAN_OPTIONS: 'detect_leaks=0'
181+
with:
182+
workdir: '${{ env.HOME }}'
183+
builddir: '${{ env.MAIN_BUILD_DIR }}'
184+
plan: "test-plan-${{ matrix.branch }}.json"
185+
# NOTE: Just keeping this construction here for possible future use:
186+
# ${{ (github.event.repository.name == 'opencv_contrib') && format('''linux-contrib-{0}''', matrix.branch) || '' }}
187+
suite: "[ ${{ (github.event.repository.name == 'opencv_contrib') && '''linux-contrib''' || '''linux''' }} ]"
188+
filter: "[ 'ubuntu-common', ${{ matrix.avx2 && '''ubuntu-avx2''' }} ]"
189+
enable_python: "true"
190+
enable_java: "true"
191+
suffix: '${{ matrix.version }}_${{ matrix.branch }}'
192+
193+
- if: ${{ always() }}
194+
name: Finalize
195+
run: |
196+
if [ "$WARNINGS" -ne 0 ]; then
197+
echo "Warnings detected. Exiting with non-zero status."
198+
exit 1
199+
fi

checkout-and-merge/action.yaml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
working-directory: ${{ inputs.workdir }}
82+
shell: bash
83+
run: |
84+
echo "::group::Merge opencv_contrib"
85+
HOME=${{ inputs.home }} \
86+
git -C opencv_contrib pull -v "https://github.com/${{ inputs.author }}/opencv_contrib" "${{ inputs.source_branch }}"
87+
echo "::endgroup::"
88+
89+
# opencv_extra
90+
91+
- if: ${{ contains(inputs.repos, 'extra') }}
92+
working-directory: ${{ inputs.workdir }}
93+
shell: bash
94+
run: |
95+
echo "::group::Clone opencv_extra"
96+
rm -rf opencv_extra
97+
HOME=${{ inputs.home }} \
98+
git clone \
99+
--reference-if-able ${{ inputs.gitcache }}/opencv_extra.git \
100+
--single-branch \
101+
--branch ${{ inputs.target_branch }} \
102+
https://github.com/opencv/opencv_extra.git
103+
echo "::endgroup::"
104+
105+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'extra') && inputs.source_branch }}
106+
working-directory: ${{ inputs.workdir }}
107+
shell: bash
108+
run: |
109+
echo "OPENCV_EXTRA_FORK=$(HOME=${{ inputs.home }} git ls-remote --heads https://github.com/${{ inputs.author }}/opencv_extra ${{ inputs.source_branch }})" >> $GITHUB_ENV
110+
111+
- if: ${{ github.event.repository.name != 'ci-gha-workflow' && contains(inputs.repos, 'extra') && inputs.source_branch && env.OPENCV_EXTRA_FORK }}
112+
working-directory: ${{ inputs.workdir }}
113+
shell: bash
114+
run: |
115+
echo "::group::Merge opencv_extra"
116+
HOME=${{ inputs.home }} \
117+
git -C opencv_extra pull -v "https://github.com/${{ inputs.author }}/opencv_extra" "${{ inputs.source_branch }}"
118+
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+
15+
runs:
16+
using: "composite"
17+
steps:
18+
19+
- working-directory: ${{ inputs.workdir }}
20+
shell: bash
21+
run: |
22+
echo "::group::Configure"
23+
rm -rf ${{ inputs.builddir }}
24+
mkdir -p ${{ inputs.builddir }}
25+
cmake \
26+
-S opencv \
27+
-B ${{ inputs.builddir }} \
28+
-G ${{ inputs.generator }} \
29+
${{ inputs.options }}
30+
echo "::endgroup::"
31+
32+
- working-directory: ${{ inputs.workdir }}
33+
shell: bash
34+
run: |
35+
echo "::group::Build"
36+
cmake --build ${{ inputs.builddir }} 2>&1 | tee ${{ inputs.builddir }}/log.txt
37+
echo "::endgroup::"
38+
39+
- shell: bash
40+
run: |
41+
set +e
42+
python3 ./scripts/warnings-handling.py \
43+
${{ inputs.workdir }}/${{ inputs.builddir }}/log.txt
44+
if [ $? -ne 0 ]; then
45+
echo "WARNINGS=1" >> $GITHUB_ENV
46+
fi

0 commit comments

Comments
 (0)