ci: Add code coverage to MRs
[platform/upstream/libnice.git] / .gitlab-ci.yml
1 stages:
2  - verify
3  - containers
4  - build
5  - test
6  - deploy
7
8 workflow:
9   rules:
10     - if: $CI_PIPELINE_SOURCE == "merge_request_event"
11     - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
12     - if: $CI_COMMIT_BRANCH == "latest-release"
13     - if: $CI_PIPELINE_SOURCE == "web"
14
15 #
16 # Check "allow-edit" checkbox on merge requests with ci-fairy
17 #
18
19 include:
20   - project: 'freedesktop/ci-templates'
21     file: '/templates/ci-fairy.yml'
22   - project: 'freedesktop/ci-templates'
23     file: '/templates/centos.yml'
24
25 .libnice.centos:7:
26   variables:
27     FDO_DISTRIBUTION_VERSION: '7'
28     FDO_DISTRIBUTION_TAG: '2022-10-17'
29     FDO_UPSTREAM_REPO: 'libnice/libnice'
30
31 check-allow-collaboration:
32   extends:
33     - .fdo.ci-fairy
34   script:
35    - ci-fairy check-merge-request --require-allow-collaboration
36   interruptible: true
37   needs: []
38   stage: 'verify'
39   variables:
40     GIT_STRATEGY: 'none'
41   rules:
42     - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
43       when: always
44
45 build-centos-container:7:
46   extends:
47   - .fdo.container-build@centos     # the CI template
48   - .libnice.centos:7               # our template job above
49   stage: containers
50   variables:
51     FDO_DISTRIBUTION_PACKAGES: 'git gtk-doc gnutls-devel gupnp-igd-devel gstreamer1-devel gobject-introspection-devel valgrind net-tools centos-release-scl graphviz'
52     FDO_DISTRIBUTION_EXEC: 'tests/docker/centos7-meson/pip-installs.sh'
53
54 build:
55   stage: build
56   extends:
57   - .fdo.distribution-image@centos
58   - .libnice.centos:7
59   interruptible: true
60   variables:
61     PREFIX: "${CI_PROJECT_DIR}/libnice-prefix"
62   except:
63     - schedules
64   before_script:
65     - mkdir -p "${CI_PROJECT_DIR}"
66   script:
67     ## && true to make gitlab-ci happy
68     - source scl_source enable rh-python36 && true
69     - meson --werror --warnlevel 2 -Dgtk_doc=enabled --prefix=$PREFIX -Db_coverage=true build/
70     - ninja -C build/
71   artifacts:
72     paths:
73       - build/
74
75
76 .build windows:
77   image: 'registry.freedesktop.org/gstreamer/gstreamer/amd64/windows:2021-10-01.0-master'
78   stage: 'build'
79   interruptible: true
80   tags:
81     - 'docker'
82     - 'windows'
83     - '1809'
84   variables:
85     MESON_ARGS: >
86       --prefix=${CI_PROJECT_DIR}/libnice-prefix
87     # Make sure any failure in PowerShell scripts is fatal
88     ErrorActionPreference: 'Stop'
89     WarningPreference: 'Stop'
90
91 build msys2:
92   extends: .build windows
93   allow_failure: true
94   before_script:
95     # Make sure powershell exists on errors
96     # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6
97     - $ErrorActionPreference = "Stop"
98
99     # For some reason docker build hangs if this is included in the image, needs more troubleshooting
100     - $env:PATH += ';C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\msys64\mingw32\bin'
101
102     # It seems that the gpg doesn't like the SSL secured version of the keyserver
103     - C:\msys64\usr\bin\bash -c "pacman-key --init && pacman-key --populate msys2 && pacman-key --refresh-keys || true"
104     - echo "Download newest msys2 keyring"
105     - C:\msys64\usr\bin\bash -c "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz && pacman -U --noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
106     - C:\msys64\usr\bin\bash -c "pacman-key --init && pacman-key --populate msys2"
107     - C:\msys64\usr\bin\bash -c "pacman-key --refresh-keys || true"
108     - C:\msys64\usr\bin\bash -c "pacman -Sy --noconfirm --needed mingw-w64-x86_64-toolchain ninja"
109
110   script:
111     # Make sure powershell exists on errors
112     # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6
113     - $ErrorActionPreference = "Stop"
114     # For some reason docker build hangs if this is included in the image, needs more troubleshooting
115     - $env:PATH += ';C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\msys64\mingw32\bin'
116
117     # For some reason, options are separated by newline instead of space, so we
118     # have to replace them first.
119     - $env:MESON_ARGS = $env:MESON_ARGS.replace("`n"," ")
120
121     - $env:PATH += ";C:\msys64\usr\bin;C:\msys64\mingw64/bin;C:\msys64\mingw32/bin"
122
123     # For some reason, options are separated by newline instead of space, so we
124     # have to replace them first.
125     - $env:CI_PROJECT_DIR = $env:CI_PROJECT_DIR.replace('\','/')
126     - $env:MESON_ARGS = $env:MESON_ARGS.replace('\','/')
127
128     # Build and run the tests.
129     # This is part of the same job due to a bug in the gitlab-runner
130     # that prevents us from exporting artifacts with docker-windows
131     # executors. It has since been fixed in gitlab 12.1, but
132     # we are blocked from upgrading currently.
133     #
134     # Gitlab Runner issue: https://gitlab.com/gitlab-org/gitlab-runner/issues/4291
135     # Blocked upgrade issue: https://gitlab.freedesktop.org/gstreamer/gst-ci/issues/6#note_192780
136     - C:\msys64\usr\bin\bash -c "meson build $env:MESON_ARGS"
137     - C:\msys64\usr\bin\bash -c "ninja -j 1 -C build"
138     - C:\msys64\usr\bin\bash -c "meson test -C build --print-errorlogs --suite libnice"
139   artifacts:
140     when: on_failure
141     paths:
142       - build/meson-logs/
143       - build/build.ninja
144
145 .build msvc:
146   extends: .build windows
147   variables:
148     GLIB_VERSION: 2.64.2
149   script:
150     # For some reason, options are separated by newline instead of space, so we
151     # have to replace them first.
152     - $env:MESON_ARGS = $env:MESON_ARGS.replace("`n"," ")
153
154     # Build and run the tests.
155     # This is part of the same job due to a bug in the gitlab-runner
156     # that prevents us from exporting artifacts with docker-windows
157     # executors. It has since been fixed in gitlab 12.1, but
158     # we are blocked from upgrading currently.
159     #
160     # Gitlab Runner issue: https://gitlab.com/gitlab-org/gitlab-runner/issues/4291
161     # Blocked upgrade issue: https://gitlab.freedesktop.org/gstreamer/gst-ci/issues/6#note_192780
162     - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
163         meson subprojects download &&
164         meson wrap promote subprojects\glib-$env:GLIB_VERSION\subprojects\libffi.wrap &&
165         meson wrap promote subprojects\glib-$env:GLIB_VERSION\subprojects\proxy-libintl.wrap &&
166         meson subprojects download"
167     - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
168         meson build $env:MESON_ARGS &&
169         ninja -C build &&
170         meson test -C build --print-errorlogs --suite libnice"
171   artifacts:
172     reports:
173       junit: build/meson-logs/testlog-*.junit.xml
174     when: on_failure
175     paths:
176       - build/meson-logs/
177
178 build msvc amd64:
179   extends: .build msvc
180   variables:
181     ARCH: 'amd64'
182
183 build msvc x86:
184   extends: .build msvc
185   variables:
186     ARCH: 'x86'
187
188 .build msvc openssl:
189   extends: .build windows
190   variables:
191     GLIB_VERSION: 2.64.2
192   script:
193     # For some reason, options are separated by newline instead of space, so we
194     # have to replace them first.
195     - $env:MESON_ARGS = $env:MESON_ARGS.replace("`n"," ")
196     - $env:MESON_ARGS += " -Dcrypto-library=openssl"
197
198     # Build and run the tests.
199     # This is part of the same job due to a bug in the gitlab-runner
200     # that prevents us from exporting artifacts with docker-windows
201     # executors. It has since been fixed in gitlab 12.1, but
202     # we are blocked from upgrading currently.
203     #
204     # Gitlab Runner issue: https://gitlab.com/gitlab-org/gitlab-runner/issues/4291
205     # Blocked upgrade issue: https://gitlab.freedesktop.org/gstreamer/gst-ci/issues/6#note_192780
206     - New-Item -Path subprojects -Name openssl.wrap -Value "[wrap-git]`r`ndirectory=openssl`r`nurl=https://gitlab.freedesktop.org/libnice/openssl-binaries-for-ci.git`r`nrevision=1.1.1c`r`n"
207     - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
208         meson subprojects download &&
209         meson wrap promote subprojects\glib-$env:GLIB_VERSION\subprojects\libffi.wrap &&
210         meson wrap promote subprojects\glib-$env:GLIB_VERSION\subprojects\proxy-libintl.wrap &&
211         meson subprojects download"
212     - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
213         meson build $env:MESON_ARGS &&
214         ninja -C build &&
215         meson test -C build --print-errorlogs --suite libnice"
216
217 build msvc amd64 openssl:
218   extends: .build msvc openssl
219   variables:
220     ARCH: 'amd64'
221
222 build msvc x86 openssl:
223   extends: .build msvc openssl
224   variables:
225     ARCH: 'x86'
226
227 test:
228   stage: test
229   extends:
230   - .fdo.distribution-image@centos
231   - .libnice.centos:7
232   interruptible: true
233   needs:
234     - build
235   except:
236     - schedules
237   script:
238     - ifconfig
239     - source scl_source enable rh-python36 && true
240     - ninja -C build/
241     - meson test -C build/ --setup debug
242     - ninja -C build coverage
243   coverage: '/lines......: \d+\.\d+% /'
244   artifacts:
245     reports:
246       junit: build/meson-logs/testlog-*.junit.xml
247     when: on_failure
248     paths:
249       - build/meson-logs/
250
251 test valgrind:
252   extends: test
253   script:
254     - ifconfig
255     - source scl_source enable rh-python36 && true
256     - meson configure build -Dgtk_doc=disabled
257     - ninja -C build/
258     - meson test -C build/ --setup valgrind --print-errorlogs
259
260
261 doc-and-install:
262   stage: test
263   extends:
264   - .fdo.distribution-image@centos
265   - .libnice.centos:7
266   interruptible: true
267   needs:
268     - build
269   except:
270     - schedules
271   variables:
272     PREFIX: "${CI_PROJECT_DIR}/libnice-prefix"
273   script:
274     - source scl_source enable rh-python36 && true
275     - ninja -C build/ libnice-doc
276     - ninja -C build/ install
277     - ls -lR ${PREFIX}
278   artifacts:
279     paths:
280       - build/docs/reference/libnice/html/
281
282 submit-to-coverity:
283  stage: test
284  extends:
285   - .fdo.distribution-image@centos
286   - .libnice.centos:7
287  variables:
288    COVERITY_PROJECT: libnice
289    PREFIX: "${CI_PROJECT_DIR}/libnice-prefix"
290  only:
291   - schedules
292   - web
293  dependencies: []
294  before_script:
295   - mkdir -p "${CI_PROJECT_DIR}"
296  script:
297   - curl -v https://scan.coverity.com/download/linux64  -o coverity_tool.tgz  --data "token=${COVERITY_TOKEN}&project=${COVERITY_PROJECT}" && tar xf coverity_tool.tgz && rm coverity_tool.tgz
298   - mv cov-analysis-linux64-* cov-analysis-linux64
299   - source scl_source enable rh-python36 && true
300   - meson --werror --warnlevel 2 -Dgtk_doc=disabled -Dinstrospection=disabled --prefix=$PREFIX cov-build/
301   - export PATH="$PATH:${CI_PROJECT_DIR}/cov-analysis-linux64/bin"
302   - echo $PATH
303   - cov-build --dir cov-int ninja -C cov-build
304   - tar czvf libnice.tgz cov-int
305   - curl --form token=$COVERITY_TOKEN --form email=olivier.crete@ocrete.ca --form file=@libnice.tgz --form version="${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}" --form description="CI weekly run" https://scan.coverity.com/builds?project=libnice
306
307 pages:
308   stage: deploy
309   dependencies:
310     - doc-and-install
311   only:
312     - latest-release
313   artifacts:
314     paths:
315       - public
316     expire_in: 1 year
317   # For some reason, trigger gets rejected
318   # trigger: libnice/libnice-website
319   script:
320     - mkdir public/
321     - mv build/docs/reference/libnice/html/ public/libnice/