ci: Rework workflow rules to prevent duplicate pipelines
[platform/upstream/gstreamer.git] / .gitlab-ci.yml
1 include:
2   - remote: "https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/7ea696055e322cc7aa4bcbe5422b56a198c4bdff/templates/ci-fairy.yml"
3
4 stages:
5   - 'build docker'
6   - 'preparation'
7   - 'pre-build'
8   - 'build'
9   - 'test'
10   # Use the resulting binaries
11   - 'integrate'
12
13 variables:
14   # Branch to track for modules that have no ref specified in the manifest
15   GST_UPSTREAM_BRANCH: 'master'
16   ORC_UPSTREAM_BRANCH: 'master'
17
18   ###
19   # IMPORTANT
20   # These are the version tags for the docker images the CI runs against.
21   # If you are hacking on them or need a them to rebuild, its enough
22   # to change any part of the string of the image you want.
23   ###
24   FEDORA_TAG:  '2021-06-30.0'
25   INDENT_TAG: '2020-10-22.0'
26   WINDOWS_TAG: "2021-10-01.0"
27
28   GST_UPSTREAM_REPO: 'gstreamer/gst-ci'
29
30   FEDORA_AMD64_SUFFIX:  'amd64/fedora'
31   INDENT_AMD64_SUFFIX: 'amd64/gst-indent'
32   WINDOWS_AMD64_SUFFIX: 'amd64/windows'
33   WINDOWS_RUST_AMD64_SUFFIX: 'amd64/windows-rust'
34
35   FEDORA_IMAGE:   "$CI_REGISTRY_IMAGE/$FEDORA_AMD64_SUFFIX:$FEDORA_TAG-$GST_UPSTREAM_BRANCH"
36   FEDORA_DOCS_IMAGE: "registry.freedesktop.org/gstreamer/gst-ci/amd64/fedora:2020-07-03.0-master"
37   INDENT_IMAGE:   "$CI_REGISTRY_IMAGE/$INDENT_AMD64_SUFFIX:$INDENT_TAG-$GST_UPSTREAM_BRANCH"
38   WINDOWS_IMAGE: "$CI_REGISTRY_IMAGE/$WINDOWS_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH"
39   WINDOWS_UPSTREAM_IMAGE: "$CI_REGISTRY/$GST_UPSTREAM_REPO/$WINDOWS_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH"
40
41   RUST_MINIMUM_VERSION: '1.54.0'
42   RUST_LATEST_VERSION: '1.55.0'
43
44   WINDOWS_RUST_MINIMUM_IMAGE: "$CI_REGISTRY_IMAGE/$WINDOWS_RUST_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH-rust-$RUST_MINIMUM_VERSION"
45   WINDOWS_RUST_MINIMUM_UPSTREAM_IMAGE: "$CI_REGISTRY/$GST_UPSTREAM_REPO/$WINDOWS_RUST_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH-rust-$RUST_MINIMUM_VERSION"
46
47   WINDOWS_RUST_LATEST_IMAGE: "$CI_REGISTRY_IMAGE/$WINDOWS_RUST_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH-rust-$RUST_LATEST_VERSION"
48   WINDOWS_RUST_LATEST_UPSTREAM_IMAGE: "$CI_REGISTRY/$GST_UPSTREAM_REPO/$WINDOWS_RUST_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH-rust-$RUST_LATEST_VERSION"
49
50   MESON_BUILDTYPE_ARGS: --default-library=both
51   DEFAULT_MESON_ARGS: >
52     -Dlibnice:tests=disabled
53     -Dlibnice:examples=disabled
54     -Dopenh264:tests=disabled
55     -Dpygobject:tests=false
56     -Dpython=enabled
57     -Dlibav=enabled
58     -Dugly=enabled
59     -Dbad=enabled
60     -Ddevtools=enabled
61     -Dges=enabled
62     -Drtsp_server=enabled
63     -Dvaapi=enabled
64     -Dsharp=disabled
65
66   MESON_GST_WERROR: >
67     -Dgstreamer:werror=true
68     -Dgst-plugins-base:werror=true
69     -Dgst-plugins-good:werror=true
70     -Dgst-plugins-ugly:werror=true
71     -Dgst-plugins-bad:werror=true
72     -Dgst-rtsp-server:werror=true
73     -Dgst-libav:werror=true
74     -Dgst-examples:werror=true
75     -Dgst-editing-services:werror=true
76     -Dgst-docs:werror=true
77     -Dgst-omx:werror=true
78     -Dgst-devtools:werror=true
79     -Dgst-python:werror=true
80     -Dgstreamer-vaapi:werror=true
81     -Dgstreamer-sharp:werror=true
82
83 workflow:
84   # https://docs.gitlab.com/ee/ci/yaml/index.html#switch-between-branch-pipelines-and-merge-request-pipelines
85   rules:
86     - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
87     - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
88       when: never
89     - if: '$CI_COMMIT_BRANCH'
90
91 #
92 # Global CI policy
93 #
94 # This can be used to configure global behaviour our our jobs.
95 #
96 default:
97   retry:
98     max: 2
99     when:
100       - 'runner_system_failure'
101       - 'stuck_or_timeout_failure'
102       - 'scheduler_failure'
103       - 'api_failure'
104   interruptible: true
105
106
107 # Script to check if a docker image exists in the upstream registry
108 # and if so copy it to the forked registry so we can use it
109 #
110 # This is copied/adapted from citemplates/templates/fedora.yml
111 # https://gitlab.freedesktop.org/freedesktop/ci-templates/-/blob/96b621fe9f57ec2464f8d1a0940446afbf6c8f59/templates/fedora.yml
112 .check_image: &check_image_exists |
113   # if-not-exists steps
114   set -x
115
116   if [[ -z "$GST_FORCE_REBUILD" ]]
117   then
118     # disable exit on failure
119     set +e
120
121     # check if our image is already in the current registry
122     # we store the sha of the digest and the layers
123     skopeo inspect docker://$LOCAL_IMAGE | jq '[.Digest, .Layers]' > local_sha
124
125     # check if our image is already in our gst-ci registry fork
126     skopeo inspect docker://$LOCAL_GST_CI_IMAGE | jq '[.Digest, .Layers]' > local_gst_ci_sha
127
128     # check if our image is already in the upstream registry
129     if [[ -z "$GST_UPSTREAM_REPO" ]]
130     then
131       echo "WARNING! Variable \$GST_UPSTREAM_REPO is undefined, cannot check for images"
132     else
133       skopeo inspect docker://$GST_UPSTREAM_IMAGE | jq '[.Digest, .Layers]' > upstream_sha
134     fi
135
136     # reenable exit on failure
137     set -e
138
139     # if the upstream repo has an image, ensure we use the same
140     if [ -s upstream_sha ]
141     then
142
143       echo "Checking if $LOCAL_IMAGE is up to date"
144       # ensure we use the same image from upstream
145       diff upstream_sha local_sha && exit 0 || true
146
147       echo "Copying image from gstreamer/gst-ci to local registry"
148       # copy the original image into the current project registry namespace
149       # we do 2 attempts with skopeo copy at most
150       skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD \
151                   docker://$GST_UPSTREAM_IMAGE \
152                   docker://$LOCAL_IMAGE || \
153       skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD \
154                   docker://$GST_UPSTREAM_IMAGE \
155                   docker://$LOCAL_IMAGE
156
157       exit 0
158     fi
159
160     set +x
161
162     # if the local ci fork repo has an image, ensure we use the same
163     if [ -s local_gst_ci_sha ]
164     then
165       echo "Checking if $LOCAL_GST_CI_IMAGE is up to date"
166       # ensure we use the same image from upstream
167       diff local_gst_ci_sha local_sha && exit 0 || true
168
169       echo "Copying image from $CI_PROJECT_NAMESPACE/gst-ci to local registry"
170       # copy the original image into the current project registry namespace
171       # we do 2 attempts with skopeo copy at most
172       skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD \
173                   docker://$LOCAL_GST_CI_IMAGE \
174                   docker://$LOCAL_IMAGE || \
175       skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD \
176                   docker://$LOCAL_GST_CI_IMAGE \
177                   docker://$LOCAL_IMAGE
178
179       exit 0
180     fi
181
182     # if we have a local image but none in the upstream repo, use our
183     if [ -s local_sha ]
184     then
185       echo "Using $LOCAL_IMAGE"
186       exit 0
187     fi
188   fi
189
190
191 # Build docker images from Dockerfiles
192 #
193 # This is copied/adapted from citemplates/templates/fedora.yml
194 # https://gitlab.freedesktop.org/freedesktop/ci-templates/-/blob/96b621fe9f57ec2464f8d1a0940446afbf6c8f59/templates/fedora.yml
195 #
196 # CITemplates builds uses buildah run/commit workflow to build the images which doesn't
197 # fit us atm and our images need further adjustment to make use of it. Porting to
198 # ci-templates is the next step though.
199 #
200 # All the documentation from citemplates should be applicable here, so please refer there
201 .base:
202   image: "$CI_REGISTRY/freedesktop/ci-templates/buildah:2020-07-20.1"
203   variables:
204     STORAGE_DRIVER: 'vfs'
205     BUILDAH_FORMAT: 'docker'
206     BUILDAH_ISOLATION: 'chroot'
207   script:
208     - export LOCAL_IMAGE="$CI_REGISTRY_IMAGE/$REPO_SUFFIX:$TAG"
209     - export LOCAL_GST_CI_IMAGE="$CI_REGISTRY/$CI_PROJECT_NAMESPACE/gst-ci/$REPO_SUFFIX:$TAG"
210     - export GST_UPSTREAM_IMAGE="$CI_REGISTRY/$GST_UPSTREAM_REPO/$REPO_SUFFIX:$TAG"
211
212     # check if the docker registry is enabled, else the variable will be missing
213     - |
214       if [[ -z "$CI_REGISTRY_IMAGE" ]]
215       then
216         echo "ERROR! Looks like your repository/fork has disabled Docker Registries."
217         echo "Pleae enable them by following the documentation from here:"
218         echo "https://docs.gitlab.com/ee/user/packages/container_registry/#enable-the-container-registry-for-your-project"
219         exit 1
220       fi
221
222     # Newer versions of podman/buildah try to set overlayfs mount options when
223     # using the vfs driver, and this causes errors.
224     - sed -i '/^mountopt =.*/d' /etc/containers/storage.conf
225
226     - *check_image_exists
227
228     - echo "Building image $LOCAL_IMAGE"
229
230     - >
231       buildah bud
232       --build-arg DEFAULT_BRANCH=$GST_UPSTREAM_BRANCH
233       --label ci.job_id=$CI_JOB_ID
234       --label pipeline.url=$CI_PIPELINE_URL
235       --label git.ref_name=$CI_COMMIT_REF_NAME
236       --label git.sha=$CI_COMMIT_SHA
237       --label gitlab.project_path=$CI_PROJECT_PATH
238       --label gitlab.project_url=$CI_PROJECT_URL
239       --label fdo.upstream-repo=$GST_UPSTREAM_REPO
240       -f $DOCKERFILE
241       -t $LOCAL_IMAGE
242       $CONTEXT_DIR
243
244     - buildah login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
245
246     # Sanity check
247     - |
248       if [ "$CI_PROJECT_PATH" = "gstreamer/gstreamer" ]; then
249         if [ "$LOCAL_IMAGE" != "$GST_UPSTREAM_IMAGE" ]; then
250           echo "ERROR!!! AAAAA! THE IMAGE URI DOES NOT MATCH THE EXPECTED UPSTREAM ONE"
251           echo $LOCAL_IMAGE
252           echo $GST_UPSTREAM_IMAGE
253           exit 1
254         fi
255       fi
256
257     -  buildah push $LOCAL_IMAGE
258
259 fedora amd64 docker:
260   stage: "build docker"
261   variables:
262     REPO_SUFFIX: "$FEDORA_AMD64_SUFFIX"
263     TAG: "$FEDORA_TAG-$GST_UPSTREAM_BRANCH"
264
265     CONTEXT_DIR: "ci/docker/fedora/"
266     DOCKERFILE: "ci/docker/fedora/Dockerfile"
267   extends: .base
268
269 gst-indent amd64 docker:
270   stage: "build docker"
271   variables:
272     REPO_SUFFIX: "$INDENT_AMD64_SUFFIX"
273     TAG: "$INDENT_TAG-$GST_UPSTREAM_BRANCH"
274
275     CONTEXT_DIR: "ci/docker/indent/"
276     DOCKERFILE: "ci/docker/indent/Dockerfile"
277   extends: .base
278
279 windows amd64 docker:
280   stage: "build docker"
281   variables:
282     # Unlike the buildah/linux jobs, this file
283     # needs to be relative to docker/windows/ subdir
284     # as it makes life easier in the powershell script
285     #
286     # We also don't need a CONTEXT_DIR var as its also
287     # hardcoded to be docker/windows/
288     DOCKERFILE: "ci/docker/windows/Dockerfile"
289   tags:
290     - windows
291     - shell
292     - "1809"
293   script:
294     # We need to pass an array and to resolve the env vars, so we can't use a variable:
295     - $DOCKER_BUILD_ARGS = @("--build-arg", "DEFAULT_BRANCH=$GST_UPSTREAM_BRANCH")
296
297     - "& ci/docker/windows/container.ps1 $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD $WINDOWS_IMAGE $WINDOWS_UPSTREAM_IMAGE $DOCKERFILE"
298     - |
299       if (!($?)) {
300         echo "Failed to build the image"
301         Exit 1
302       }
303
304 .windows rust docker build:
305   stage: 'build docker'
306   needs:
307     - job: 'windows amd64 docker'
308       artifacts: false
309   rules:
310     - if: '$CI_PROJECT_NAME == "gst-ci"'
311   variables:
312     # Unlike the buildah/linux jobs, this file
313     # needs to be relative to docker/windows/ subdir
314     # as it makes life easier in the powershell script
315     #
316     # We also don't need a CONTEXT_DIR var as its also
317     # hardcoded to be docker/windows/
318     DOCKERFILE: 'docker/windows/rust.Dockerfile'
319   tags:
320     - 'windows'
321     - 'shell'
322     - '1809'
323   script:
324     # We need to pass an array and to resolve the env vars, so we can't use a variable:
325     - $DOCKER_BUILD_ARGS = @("--build-arg", "DEFAULT_BRANCH=$GST_UPSTREAM_BRANCH", "--build-arg", "BASE_IMAGE=$WINDOWS_IMAGE", "--build-arg", "RUST_VERSION=$RUST_VERSION")
326
327     - $env:WINDOWS_CONTAINER_SCRIPT_PATH = "$env:CI_PROJECT_DIR\container.ps1"
328     - echo "Fetching $env:WINDOWS_CONTAINER_SCRIPT_URL"
329     - Invoke-WebRequest -Uri $env:WINDOWS_CONTAINER_SCRIPT_URL -OutFile $env:WINDOWS_CONTAINER_SCRIPT_PATH
330
331     - "& $env:WINDOWS_CONTAINER_SCRIPT_PATH $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD $RUST_IMAGE $RUST_UPSTREAM_IMAGE $DOCKERFILE"
332     - |
333       if (!($?)) {
334         echo "Failed to build the image"
335         Exit 1
336       }
337
338 windows rust amd64 docker latest stable:
339   extends: '.windows rust docker build'
340   variables:
341     RUST_IMAGE: !reference [variables, "WINDOWS_RUST_LATEST_IMAGE"]
342     RUST_UPSTREAM_IMAGE: !reference [variables, "WINDOWS_RUST_LATEST_UPSTREAM_IMAGE"]
343     RUST_VERSION: !reference [variables, "RUST_LATEST_VERSION"]
344
345 windows rust amd64 docker minimum supported version:
346   extends: '.windows rust docker build'
347   variables:
348     RUST_IMAGE: !reference [variables, "WINDOWS_RUST_MINIMUM_IMAGE"]
349     RUST_UPSTREAM_IMAGE: !reference [variables, "WINDOWS_RUST_MINIMUM_UPSTREAM_IMAGE"]
350     RUST_VERSION: !reference [variables, "RUST_MINIMUM_VERSION"]
351
352
353
354 # ---- Preparation ----- #
355 #
356 # gst-indent!!
357 #
358 gst indent:
359   image: $INDENT_IMAGE
360   stage: 'preparation'
361   script:
362     # man indent. grep RETURN VALUE, grab a beer on my behalf...
363     - indent --version || true
364     - ./scripts/gst-indent-all
365     - |
366       if git diff --quiet -- ':!subprojects/gst-integration-testsuites/medias' .; then
367           echo "Code is properly formatted"
368       else
369           git diff --color=always -- ':!subprojects/gst-integration-testsuites/medias' .
370           echo 'style diverges, please run gst-indent first'
371           exit 1
372       fi
373
374   rules:
375     # If the MR is assigned to the Merge bot, trigger the pipeline automatically
376     - if: '$CI_MERGE_REQUEST_ASSIGNEES == "gstreamer-merge-bot"'
377     # When the assignee isn't the merge bot, require an explicit action to trigger the pipeline
378     # to avoid wasting CI resources
379     - if: '$CI_MERGE_REQUEST_ASSIGNEES != "gstreamer-merge-bot"'
380       when: 'manual'
381       allow_failure: false
382     # If this matches, it means the pipeline is running against either the main
383     # or a stable branch, so make it manual
384     - if: '$CI_COMMIT_BRANCH == $GST_UPSTREAM_BRANCH'
385       when: 'manual'
386
387 #
388 # Check "allow-edit" checkbox on merge requests with ci-fairy
389 #
390 check allow-edit:
391   extends: '.fdo.ci-fairy'
392   needs: []
393   stage: 'preparation'
394   script:
395     - ci-fairy check-merge-request --require-allow-collaboration
396   rules:
397     - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
398
399 #
400 # build setup templates
401 #
402 .build_template: &build
403   - echo $MESON_ARGS
404
405   - meson build/ $MESON_ARGS
406   - ninja -C build/
407   - ccache --show-stats
408
409 .build_ccache_vars:
410   variables:
411     CCACHE_COMPILERCHECK: 'content'
412     CCACHE_COMPRESS: 'true'
413     CCACHE_BASEDIR: '/cache/gstreamer/gstreamer'
414     CCACHE_DIR: '/cache/gstreamer/gstreamer/ccache/'
415     # shared across everything really
416     CCACHE_MAXSIZE: '10G'
417     CARGO_HOME: '/cache/gstreamer/cargo'
418
419 .simple_fedora_build: &simple_build >-
420   ${DEFAULT_MESON_ARGS}
421   -Dsharp=enabled
422   -Domx=enabled
423   -Dgst-omx:target=generic
424   -Ddoc=disabled
425   -Drs=disabled
426   ${MESON_BUILDTYPE_ARGS}
427   ${MESON_GST_WERROR}
428
429 .build:
430   stage: 'build'
431   extends:
432     - '.build_ccache_vars'
433   needs:
434     - "gst indent"
435   # Taking into account the slowest shared runner + time needed to upload the binaries to artifacts
436   # Also need to take into account I/O of pulling docker images and uploading artifacts
437   timeout: '45min'
438   variables:
439     MESON_ARGS: "${DEFAULT_MESON_ARGS} ${MESON_BUILDTYPE_ARGS} ${MESON_GST_WERROR}"
440   script:
441     *build
442   after_script:
443     - mv build/meson-logs/ meson-logs
444   artifacts:
445     expire_in: "7 days"
446     when: "always"
447     paths:
448       - 'meson-logs/'
449
450 .base_modules_changes: &modules_changes
451   - .gitlab-ci.yml
452   - meson.build
453   - subprojects/*.wrap
454   - subprojects/gst-devtools/**/*
455   - subprojects/gst-editing-services/**/*
456   - subprojects/gst-integration-testsuites/**/*
457   - subprojects/gst-libav/**/*
458   - subprojects/gst-omx/**/*
459   - subprojects/gst-plugins-bad/**/*
460   - subprojects/gst-plugins-base/**/*
461   - subprojects/gst-plugins-good/**/*
462   - subprojects/gst-plugins-ugly/**/*
463   - subprojects/gst-python/**/*
464   - subprojects/gstreamer/**/*
465   - subprojects/gstreamer-sharp/**/*
466   - subprojects/gstreamer-vaapi/**/*
467   - subprojects/gst-rtsp-server/**/*
468
469 .simple_fedora_build: &simple_build >-
470   ${DEFAULT_MESON_ARGS}
471   -Dsharp=enabled
472   -Domx=enabled
473   -Dgst-omx:target=generic
474   -Ddoc=disabled
475   -Drs=disabled
476   ${MESON_BUILDTYPE_ARGS}
477   ${MESON_GST_WERROR}
478
479 .build:
480   stage: 'build'
481   extends:
482     - '.build_ccache_vars'
483   # Taking into account the slowest shared runner + time needed to upload the binaries to artifacts
484   # Also need to take into account I/O of pulling docker images and uploading artifacts
485   timeout: '45min'
486   variables:
487     MESON_ARGS: "${DEFAULT_MESON_ARGS} ${MESON_BUILDTYPE_ARGS} ${MESON_GST_WERROR}"
488   before_script:
489     - ci/scripts/handle-subprojects-cache.py subprojects/
490     # Update subprojects to respect `.wrap` content
491     - meson subprojects update --reset
492   script:
493     *build
494   after_script:
495     - mv build/meson-logs/ meson-logs
496   artifacts:
497     expire_in: "7 days"
498     when: "always"
499     paths:
500       - 'meson-logs/'
501
502 .build fedora x86_64:
503   extends: '.build'
504   image: $FEDORA_IMAGE
505   variables:
506     MESON_ARGS: *simple_build
507   rules:
508     - changes:
509         *modules_changes
510
511 build nodebug fedora x86_64:
512   extends: '.build'
513   image: $FEDORA_IMAGE
514   variables:
515     MESON_ARGS: "${DEFAULT_MESON_ARGS} -Dsharp=enabled -Dgstreamer:gst_debug=false -Domx=enabled -Dgst-omx:target=generic ${MESON_BUILDTYPE_ARGS} ${MESON_GST_WERROR}"
516
517 build static fedora x86_64:
518   extends: '.build fedora x86_64'
519   variables:
520     MESON_BUILDTYPE_ARGS: "--default-library=static -Dintrospection=disabled -Ddoc=disabled"
521
522 build static nodebug fedora x86_64:
523   extends: 'build nodebug fedora x86_64'
524   variables:
525     MESON_BUILDTYPE_ARGS: "--default-library=static -Dintrospection=disabled -Ddoc=disabled"
526
527 build clang fedora x86_64:
528   extends: '.build fedora x86_64'
529   variables:
530     CC: 'ccache clang'
531     CXX: 'ccache clang++'
532
533 .build windows:
534   image: $WINDOWS_IMAGE
535   stage: 'build'
536   tags:
537     - 'docker'
538     - 'windows'
539     - '1809'
540   needs:
541     - "gst indent"
542   timeout: '45min'
543   variables:
544     MESON_ARGS: >
545       ${DEFAULT_MESON_ARGS}
546       -Dpython=disabled
547       -Dlibav=disabled
548       -Dvaapi=disabled
549       -Dgst-plugins-base:pango=enabled
550       -Dgst-plugins-good:cairo=enabled
551   rules:
552     - changes:
553         *modules_changes
554   before_script:
555     - ci/scripts/handle-subprojects-cache.py subprojects/
556   script:
557     # For some reason, options are separated by newline instead of space, so we
558     # have to replace them first.
559     - $env:MESON_ARGS = $env:MESON_ARGS.replace("`n"," ")
560     - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
561         meson build $env:MESON_ARGS &&
562         ninja -C build"
563   # XXX: Re-enable when uploading stops timing out
564   #artifacts:
565   #  expire_in: "7 days"
566   #  when: "always"
567   #  paths:
568   #    - 'build/meson-logs/'
569
570 build vs2017 amd64:
571   extends: '.build windows'
572   variables:
573     ARCH: 'amd64'
574
575 build vs2017 x86:
576   extends: '.build windows'
577   variables:
578     ARCH: 'x86'
579
580 build msys2 :
581   extends: '.build windows'
582   timeout: '60min'
583   rules:
584     - changes:
585         *modules_changes
586       allow_failure: true
587       when: 'manual'
588   script:
589     # Make sure powershell exists on errors
590     # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6
591     - $ErrorActionPreference = "Stop"
592
593     # For some reason docker build hangs if this is included in the image, needs more troubleshooting
594     - $env:PATH += ';C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\msys64\mingw32\bin'
595     # Copied from https://github.com/msys2/setup-msys2/blob/master/main.js#L98
596     - C:\msys64\usr\bin\bash -c "pacman-key --init && pacman-key --populate msys2 && pacman-key --refresh-keys || true"
597     - C:\msys64\usr\bin\bash -c "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
598     - echo "Updating MSYS2"
599     - C:\msys64\usr\bin\bash -c "pacman -Syuu --noconfirm || echo Update failed, ignoring"
600     - echo "Killing all MSYS2 processes"
601     - taskkill /F /FI "MODULES eq msys-2.0.dll"
602     - echo "Completing MSYS2 update"
603     - C:\msys64\usr\bin\bash -c "pacman -Suu --noconfirm"
604     - echo "Installing needed MSYS2 packages"
605     - C:\msys64\usr\bin\bash -c "pacman -Sy --noconfirm --needed mingw-w64-x86_64-toolchain ninja"
606
607     # For some reason, options are separated by newline instead of space, so we
608     # have to replace them first.
609     - $env:MESON_ARGS = $env:MESON_ARGS.replace("`n"," ")
610     # Replace forward slashes with backwards so bash doesn't complain
611     - $env:_PROJECT_DIR = $env:CI_PROJECT_DIR.replace('\','/')
612     - C:\msys64\usr\bin\bash -c "meson build $env:MESON_ARGS && ninja -C build"
613
614 # ---- Tests ----- #
615
616 .test:
617   stage: 'test'
618   extends:
619     - '.build_ccache_vars'
620   needs:
621     - "gst indent"
622   variables:
623     MESON_ARGS: *simple_build
624
625     # Disable colored output to avoid weird rendering issues
626     GST_DEBUG_NO_COLOR: "true"
627     CI_ARTIFACTS_URL: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/validate-logs/"
628     GST_VALIDATE_LAUNCHER_FORCE_COLORS: "true"
629     TIMEOUT_FACTOR: "2"
630     CARGO_HOME: "/cache/gstreamer/cargo"
631     # Enable the fault handler so we get backtraces on segfaults.
632     # any non-empty string will do
633     PYTHONFAULTHANDLER: "enabled"
634   rules:
635     - changes:
636         *modules_changes
637   script:
638     - *build
639
640     - echo "-> Running ${TEST_SUITE}"
641     - >
642       ./gst-env.py
643       gst-validate-launcher ${TEST_SUITE}
644       --dump-on-failure
645       --mute
646       --shuffle
647       --no-display
648       --meson-no-rebuild
649       --timeout-factor "${TIMEOUT_FACTOR}"
650       --fail-on-testlist-change
651       -l "${CI_PROJECT_DIR}/validate-logs/"
652       --xunit-file "${CI_PROJECT_DIR}/validate-logs/xunit.xml"
653       ${EXTRA_VALIDATE_ARGS}
654   after_script:
655     - mv build/meson-logs/ meson-logs
656   artifacts:
657     expire_in: '14 days'
658     when: always
659     paths:
660       - 'meson-logs/'
661       - 'validate-logs'
662     reports:
663       junit:
664         - "validate-logs/*.xml"
665
666 .test fedora x86_64:
667   image: $FEDORA_IMAGE
668   extends: '.test'
669   tags: ['gstreamer']
670
671 check fedora:
672   extends: '.test fedora x86_64'
673   variables:
674     TEST_SUITE: "check.gst*"
675
676 integration testsuites fedora:
677   extends: '.test fedora x86_64'
678   parallel: 4
679   variables:
680     EXTRA_VALIDATE_ARGS: "--timeout-factor=2 --retry-on-failures --check-bugs --parts=${CI_NODE_TOTAL} --part-index=${CI_NODE_INDEX}"
681     TEST_SUITE: "validate ges"
682
683 # gstreamer-full:
684 # introspection has been disabled as the static build does not support it.
685 # See https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/162
686 gstreamer-full:
687   extends: 'build static fedora x86_64'
688   stage: integrate
689   variables:
690     MESON_ARGS: >
691       --default-library=static
692       -Dintrospection=disabled
693       $MESON_GST_WERROR
694   rules:
695     - changes:
696       - "*"
697       - scripts/*
698       - subprojects/gst-ci/**/*
699
700   script:
701   - *build
702   - meson test -C build -v test-gst-full
703   artifacts:
704     expire_in: "7 days"
705     when: "always"
706     paths:
707       - 'meson-logs/'
708
709 gstreamer-full-minimal:
710   extends: 'build static fedora x86_64'
711   stage: integrate
712   variables:
713     MESON_ARGS: >
714       --default-library=static
715       -Dauto_features=disabled
716       -Dgstreamer:check=enabled
717       -Dtests=enabled
718       -Dgst-plugins-base:alsa=enabled
719       -Dgst-plugins-base:typefind=enabled
720       -Dgst-plugins-base:pbtypes=enabled
721       -Dgst-full-elements=coreelements:filesrc,fakesink,identity,input-selector
722       -Dgst-full-typefind-functions=typefindfunctions:wav,flv
723       -Dgst-full-device-providers=alsa:alsadeviceprovider
724       -Dgst-full-dynamic-types=pbtypes:video_multiview_flagset
725       $MESON_GST_WERROR
726   rules:
727     - if: '$CI_PROJECT_NAME =~ /^(gst-build|gst-ci)$/'
728
729   script:
730   - *build
731   - meson test -C build -v test-gst-full
732   - meson test -C build test-gst-full-features --test-args "-e filesrc,identity,fakesink -E filesink,capsfilter -t audio/x-wav -T video/vivo -d alsadeviceprovider -D v4l2deviceprovider -l GstVideoMultiviewFlagsSet"
733   - strip build/libgstreamer-full-1.0.so
734   - ls -l build/libgstreamer-full-1.0.so
735   artifacts:
736     expire_in: "7 days"
737     when: "always"
738     paths:
739       - 'meson-logs/'
740
741 # Valgrind
742 .valgrind fedora x86_64:
743   extends: '.test fedora x86_64'
744   stage: 'test'
745   variables:
746     EXTRA_VALIDATE_ARGS: "--valgrind"
747
748 valgrind core:
749   extends: '.valgrind fedora x86_64'
750   variables:
751     TEST_SUITE: "check.gstreamer\\..*"
752   rules:
753     - changes:
754       - "*"
755       - scripts/*
756       - subprojects/gst-ci/**/*
757       - subprojects/gst-devtools/**/*
758       - subprojects/gstreamer/**/*
759
760 valgrind base:
761   extends: '.valgrind fedora x86_64'
762   variables:
763     TEST_SUITE: "check.gst-plugins-base\\..*"
764   rules:
765     - changes:
766       - "*"
767       - scripts/*
768       - subprojects/gst-ci/**/*
769       - subprojects/gst-devtools/**/*
770       - subprojects/gstreamer/**/*
771       - subprojects/gst-plugins-base/**/*
772
773 valgrind good:
774   extends: '.valgrind fedora x86_64'
775   variables:
776     TEST_SUITE: "check.gst-plugins-good\\..*"
777     # take longer time due to splitmux unit test
778     TIMEOUT_FACTOR: "4"
779   rules:
780     - changes:
781       - "*"
782       - scripts/*
783       - subprojects/gst-ci/**/*
784       - subprojects/gst-devtools/**/*
785       - subprojects/gstreamer/**/*
786       - subprojects/gst-plugins-base/**/*
787       - subprojects/gst-plugins-good/**/*
788
789 valgrind ugly:
790   extends: '.valgrind fedora x86_64'
791   variables:
792     TEST_SUITE: "check.gst-plugins-ugly\\..*"
793   rules:
794     - changes:
795       - "*"
796       - scripts/*
797       - subprojects/gst-ci/**/*
798       - subprojects/gst-devtools/**/*
799       - subprojects/gstreamer/**/*
800       - subprojects/gst-plugins-base/**/*
801       - subprojects/gst-plugins-good/**/*
802       - subprojects/gst-plugins-ugly/**/*
803
804 valgrind bad:
805   extends: '.valgrind fedora x86_64'
806   variables:
807     TEST_SUITE: "check.gst-plugins-bad\\..*"
808   rules:
809     - changes:
810       - "*"
811       - scripts/*
812       - subprojects/gst-ci/**/*
813       - subprojects/gst-devtools/**/*
814       - subprojects/gstreamer/**/*
815       - subprojects/gst-plugins-base/**/*
816       - subprojects/gst-plugins-good/**/*
817       - subprojects/gst-plugins-bad/**/*
818
819 valgrind ges:
820   extends: '.valgrind fedora x86_64'
821   variables:
822     TEST_SUITE: "check.gst-editing-services\\..*"
823   rules:
824     - changes:
825       - "*"
826       - scripts/*
827       - subprojects/gst-ci/**/*
828       - subprojects/gst-devtools/**/*
829       - subprojects/gstreamer/**/*
830       - subprojects/gst-plugins-base/**/*
831       - subprojects/gst-plugins-good/**/*
832       - subprojects/gst-plugins-bad/**/*
833       - subprojects/gst-editing-services/**/*
834
835 # ---- Integration ----- #
836
837 .documentation:
838   image: $FEDORA_DOCS_IMAGE
839   extends:
840     - '.build_ccache_vars'
841   variables:
842     MESON_ARGS: *simple_build
843     MESON_BUILDTYPE_ARGS: "-Ddoc=enabled"
844     CI_ARTIFACTS_URL: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/"
845   script:
846   - pip3 install --upgrade hotdoc
847   - *build
848   - ./gst-env.py ninja -C build/ plugins_doc_caches
849   - ./ci/scripts/check-documentation-diff.py
850   - ./gst-env.py hotdoc run --conf-file=build/subprojects/gst-docs/GStreamer-doc.json --fatal-warnings
851   - mv build/subprojects/gst-docs/GStreamer-doc/html documentation/
852
853   artifacts:
854     when: always
855     expire_in: "7 days"
856     paths:
857     - documentation/
858     - plugins-cache-diffs/
859
860 documentation:
861   stage: integrate
862   extends:
863     - '.documentation'
864   needs: []
865   rules:
866     - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == "main"'
867
868 build documentation:
869   extends:
870     - '.documentation'
871   stage: build
872   needs:
873     - "gst indent"
874
875   stage: build
876   rules:
877     - changes:
878       - .gitlab-ci.yml
879       - ci/gitlab/freedesktop_doc_importer.sh
880       - subprojects/*.wrap
881       - subprojects/gst-docs/**/*
882       - subprojects/gst-devtools/**/*
883       - subprojects/gst-editing-services/**/*
884       - subprojects/gst-libav/**/*
885       - subprojects/gst-omx/**/*
886       - subprojects/gst-plugins-bad/**/*
887       - subprojects/gst-plugins-base/**/*
888       - subprojects/gst-plugins-good/**/*
889       - subprojects/gst-plugins-ugly/**/*
890       - subprojects/gstreamer/**/*
891       - subprojects/gstreamer-vaapi/**/*
892       - subprojects/gst-rtsp-server/**/*
893
894 # FIXME: Using trigger: causes permission issues, workaround using old REST API.
895 # https://gitlab.com/gitlab-org/gitlab/-/issues/341737
896 cerbero trigger:
897   stage: build
898   image: $FEDORA_IMAGE
899   script:
900     - python3 -m pip install --user python-gitlab
901     - ci/gitlab/trigger_cerbero_pipeline.py
902
903   variables:
904     # Use GST_UPSTREAM_BRANCH
905     UPSTREAM_BRANCH: 'main'
906
907   rules:
908     - changes:
909       - .gitlab-ci.yml
910       - ci/gitlab/tigger_cerbero_pipeline.py
911       - subprojects/gst-devtools/**/*
912       - subprojects/gst-editing-services/**/*
913       - subprojects/gst-libav/**/*
914       - subprojects/gst-plugins-bad/**/*
915       - subprojects/gst-plugins-base/**/*
916       - subprojects/gst-plugins-good/**/*
917       - subprojects/gst-plugins-ugly/**/*
918       - subprojects/gst-python/**/*
919       - subprojects/gstreamer/**/*
920       - subprojects/gst-rtsp-server/**/*
921       - subprojects/gst-examples/**/*