summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: f10d2f7159fa12ebc4f0f3bd9472a8abd28a9a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
include:
  - project: 'freedesktop/ci-templates'
    ref: "801093be0b88f23c8dbabe9cfce7134548f7ccdc"
    file: '/templates/fedora.yml'
  - project: 'freedesktop/ci-templates'
    ref: "801093be0b88f23c8dbabe9cfce7134548f7ccdc"
    file: '/templates/debian.yml'
  ###
  # IMPORTANT
  # These are the version tags for the docker images the CI runs against.
  # If you are hacking on them or need a them to rebuild, you need to change
  # the appropriate version string in this file which will cause a rebuild.
  ###
  - local: '.gitlab-image-tags.yml'

stages:
  - 'preparation'
  - 'build'
  - 'test'
  # Use the resulting binaries
  - 'integrate'

variables:
  GIT_DEPTH: 1

  # Branch to track for modules that have no ref specified in the manifest
  GST_UPSTREAM_BRANCH: 'main'

  FDO_UPSTREAM_REPO: 'gstreamer/gstreamer'

  MESON_COMMIT:
    description: "Overwrite the meson version installed on the CI images with the specified meson commit"
    value: ""

  FEDORA_AMD64_SUFFIX: 'amd64/fedora'
  DEBIAN_AMD64_SUFFIX: 'amd64/debian'
  INDENT_AMD64_SUFFIX: 'amd64/gst-indent'
  COMMITLINT_AMD64_SUFFIX: 'amd64/commitlint'
  WINDOWS_AMD64_SUFFIX: 'amd64/windows'

  WINDOWS_IMAGE: "$CI_REGISTRY_IMAGE/$WINDOWS_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH"
  WINDOWS_UPSTREAM_IMAGE: "$CI_REGISTRY/$FDO_UPSTREAM_REPO/$WINDOWS_AMD64_SUFFIX:$WINDOWS_TAG-$GST_UPSTREAM_BRANCH"

  DEFAULT_MESON_ARGS: >-
    -Dlibnice:tests=disabled
    -Dlibnice:examples=disabled
    -Dlibnice:gupnp=disabled
    -Dopenh264:tests=disabled
    -Dgst-plugins-base:opus=enabled
    -Dgst-plugins-good:soup-lookup-dep=true
    -Dgst-plugins-good:vpx=enabled
    -Dpygobject:tests=false
    -Dpython=enabled
    -Dlibav=enabled
    -Dugly=enabled
    -Dbad=enabled
    -Ddevtools=enabled
    -Dges=enabled
    -Drtsp_server=enabled
    -Dvaapi=enabled
    -Dsharp=disabled
    -Drs=disabled
    -Dgpl=enabled
    -Dintrospection=enabled

  SIMPLE_BUILD: >-
    ${DEFAULT_MESON_ARGS}
    -Dsharp=enabled
    -Ddoc=disabled

workflow:
  # https://docs.gitlab.com/ee/ci/yaml/index.html#switch-between-branch-pipelines-and-merge-request-pipelines
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
      variables:
        GIT_FETCH_EXTRA_FLAGS: '--no-tags'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      variables:
        GIT_FETCH_EXTRA_FLAGS: '--no-tags'
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_COMMIT_BRANCH'
      variables:
        GIT_FETCH_EXTRA_FLAGS: '--no-tags'

#
# Global CI policy
#
# This can be used to configure global behaviour our our jobs.
#
default:
  retry:
    max: 2
    when:
      - 'runner_system_failure'
      - 'stuck_or_timeout_failure'
      - 'scheduler_failure'
      - 'api_failure'
  interruptible: true

# This is an empty job that is used to trigger the pipeline.
trigger:
  image: alpine:latest
  stage: 'preparation'
  variables:
    GIT_STRATEGY: none
  tags: [ 'placeholder-job' ]
  script:
    - echo "Trigger job done, now running the pipeline."
  rules:
    # If this pipeline is triggered by a schedule, run automatically
    - if: $CI_PIPELINE_SOURCE == "schedule"
    # If the MR is assigned to the Merge bot, trigger the pipeline automatically
    - if: '$CI_MERGE_REQUEST_ASSIGNEES == "gstreamer-merge-bot"'
    # Require explicit action to trigger tests post merge, but we want to
    # automatically trigger the integratation stage
    - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == $GST_UPSTREAM_BRANCH && $CI_JOB_STAGE != "integrate"'
      when: 'manual'
    # When the assignee isn't the merge bot, require an explicit action to trigger the pipeline
    # to avoid wasting CI resources
    - if: '$CI_MERGE_REQUEST_ASSIGNEES != "gstreamer-merge-bot"'
      when: 'manual'
      allow_failure: false

.fedora image:
  variables:
    CCACHE_DIR: '/cache/gstreamer/gstreamer/ccache/'
    FDO_BASE_IMAGE: 'registry.fedoraproject.org/fedora-toolbox:34'
    FDO_DISTRIBUTION_VERSION: '34'
    FDO_REPO_SUFFIX: "$FEDORA_AMD64_SUFFIX"
    FDO_DISTRIBUTION_TAG: "$FEDORA_TAG-$GST_UPSTREAM_BRANCH"
    FDO_DISTRIBUTION_EXEC: 'GIT_BRANCH=$CI_COMMIT_REF_NAME GIT_URL=$CI_REPOSITORY_URL bash ci/docker/fedora/prepare.sh'

fedora amd64 docker:
  extends:
    - '.fedora image'
    - '.fdo.container-build@fedora'
  stage: 'preparation'
  needs: []
  # Note: assumption is that placeholder jobs run on a packet runner
  # (which has faster network connectivity to the registry).
  tags: [ 'placeholder-job' ]

.debian image:
  variables:
    CCACHE_DIR: '/cache/gstreamer/gstreamer/ccache_debian/'
    FDO_BASE_IMAGE: "quay.io/toolbx-images/debian-toolbox:12"
    FDO_DISTRIBUTION_VERSION: '12'
    FDO_REPO_SUFFIX: "$DEBIAN_AMD64_SUFFIX"
    FDO_DISTRIBUTION_TAG: "$DEBIAN_TAG-$GST_UPSTREAM_BRANCH"
    FDO_DISTRIBUTION_EXEC: 'GIT_BRANCH=$CI_COMMIT_REF_NAME GIT_URL=$CI_REPOSITORY_URL bash ci/docker/debian/prepare.sh'

debian amd64 docker:
  extends:
    - '.debian image'
    - '.fdo.container-build@debian'
  stage: 'preparation'
  needs: []
  # Note: assumption is that placeholder jobs run on a packet runner
  # (which has faster network connectivity to the registry).
  tags: [ 'placeholder-job' ]

.gst-indent image:
  tags: [ 'placeholder-job' ]
  variables:
    FDO_DISTRIBUTION_VERSION: 'bookworm'
    FDO_REPO_SUFFIX: "$INDENT_AMD64_SUFFIX"
    FDO_DISTRIBUTION_TAG: "$INDENT_TAG-$GST_UPSTREAM_BRANCH"
    FDO_DISTRIBUTION_PACKAGES: 'curl indent git findutils ca-certificates'
    FDO_DISTRIBUTION_EXEC: 'ci/docker/indent/prepare.sh'

gst-indent amd64 docker:
  extends:
    - '.gst-indent image'
    - '.fdo.container-build@debian'
  stage: 'preparation'
  # Do not depend on the trigger, as we want to run indent always
  needs: []

.commitlint image:
  tags: [ 'placeholder-job' ]
  variables:
    FDO_DISTRIBUTION_VERSION: '37'
    FDO_REPO_SUFFIX: "$COMMITLINT_AMD64_SUFFIX"
    FDO_DISTRIBUTION_TAG: "$LINT_TAG-$GST_UPSTREAM_BRANCH"
    FDO_DISTRIBUTION_PACKAGES: 'python3-pip git'
    FDO_DISTRIBUTION_EXEC: 'ci/docker/lint/prepare.sh'
    FDO_USER: "ciuser"

commitlint docker:
  extends:
    - '.commitlint image'
    - '.fdo.container-build@fedora'
  stage: 'preparation'
  # Do not depend on the trigger, as we want to run indent always
  needs: []

windows amd64 docker:
  stage: "preparation"
  timeout: '3h'
  variables:
    # Unlike the buildah/linux jobs, this file
    # needs to be relative to docker/windows/ subdir
    # as it makes life easier in the powershell script
    #
    # We also don't need a CONTEXT_DIR var as its also
    # hardcoded to be docker/windows/
    DOCKERFILE: "ci/docker/windows/Dockerfile"
  tags:
    - windows
    - shell
    - "2022"
  script:
    # We need to pass an array and to resolve the env vars, so we can't use a variable:
    - $DOCKER_BUILD_ARGS = @(`
        "--build-arg", "DEFAULT_BRANCH=$GST_UPSTREAM_BRANCH", `
        "--build-arg", "CI_PROJECT_NAMESPACE=$CI_PROJECT_NAMESPACE", `
        "--build-arg", "CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME" `
      )
    - ci/docker/windows/container.ps1 $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD $WINDOWS_IMAGE $WINDOWS_UPSTREAM_IMAGE $DOCKERFILE

.macos image:
  image: "registry.freedesktop.org/gstreamer/gstreamer/macos-arm64/14-sonoma:2023-10-25.0"
  tags:
    - gst-mac-arm

# ---- Preparation ----- #
#
# gst-indent!!
#
gst indent:
  extends:
    - '.gst-indent image'
    - '.fdo.suffixed-image@debian'
  stage: 'preparation'
  needs:
    - job: 'gst-indent amd64 docker'
      artifacts: false
  script:
    - ./scripts/check-format-c
    - ./scripts/format-csharp --check
    # We want both wraps to use the same version, overkill to create a separate job for this
    - cmp subprojects/gtk-sharp.wrap subprojects/gstreamer-sharp/subprojects/gtk-sharp.wrap
  rules:
    - !reference [.upstream-branch-rules, rules]
    - if: '$CI_PROJECT_NAMESPACE != "gstreamer" || $CI_COMMIT_BRANCH != $GST_UPSTREAM_BRANCH'
      when: 'always'

rustfmt:
  extends:
    - '.fedora image'
    - '.fdo.suffixed-image@fedora'
  stage: 'preparation'
  needs:
    - "fedora amd64 docker"
  script:
    - export RUSTUP_HOME="/usr/local/rustup"
    - export PATH="/usr/local/cargo/bin:$PATH"
    - ./scripts/format-rust --check

commitlint:
  extends:
    - '.commitlint image'
    - '.fdo.suffixed-image@fedora'
  stage: 'preparation'
  variables:
    GIT_STRATEGY: fetch
    GIT_DEPTH: 100
  needs:
    - job: 'commitlint docker'
      artifacts: false
  before_script:
    - git config --global --add safe.directory $CI_PROJECT_DIR
  script:
    - echo $CI_MERGE_REQUEST_DIFF_BASE_SHA
    - gitlint --commits $CI_MERGE_REQUEST_DIFF_BASE_SHA..HEAD
  rules:
    # Only run on MR as we need CI_MERGE_REQUEST_DIFF_BASE_SHA to know
    # what commits to check
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

.build_ccache_vars:
  variables:
    CCACHE_COMPILERCHECK: 'content'
    CCACHE_COMPRESS: 'true'
    CCACHE_BASEDIR: '/cache/gstreamer/gstreamer'
    # shared across everything really
    CCACHE_MAXSIZE: '10G'

.base_modules_changes: &modules_changes
  - .gitlab-ci.yml
  - .gitlab-image-tags.yml
  - gst-env.py
  - ci/gitlab/*.py
  - ci/scripts/**/*
  - meson.build
  - subprojects/*.wrap
  - subprojects/gst-devtools/**/*
  - subprojects/gst-editing-services/**/*
  - subprojects/gst-integration-testsuites/**/*
  - subprojects/gst-libav/**/*
  - subprojects/gst-plugins-bad/**/*
  - subprojects/gst-plugins-base/**/*
  - subprojects/gst-plugins-good/**/*
  - subprojects/gst-plugins-ugly/**/*
  - subprojects/gst-python/**/*
  - subprojects/gstreamer/**/*
  - subprojects/gstreamer-sharp/**/*
  - subprojects/gst-rtsp-server/**/*

.upstream-branch-rules:
  rules:
    # If this matches, it means the pipeline is running against either the main
    # or a stable branch, so make it manual
    - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == $GST_UPSTREAM_BRANCH'
      when: manual

.build:
  stage: 'build'
  needs:
    - "trigger"
  # Taking into account the slowest shared runner + time needed to upload the binaries to artifacts
  # Also need to take into account I/O of pulling docker images and uploading artifacts
  timeout: '45min'
  variables:
    BUILD_GST_DEBUG: "-Dgstreamer:gst_debug=true"
    GST_WERROR: "true"
    MESON_ARGS: "${DEFAULT_MESON_ARGS}"
    SUBPROJECTS_CACHE_DIR: "/subprojects"
    # Avoid weird issue about cross-device links
    # https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3197
    GI_SCANNER_DISABLE_CACHE: "1"
  script:
    - $CI_PROJECT_DIR/ci/scripts/build.sh
    - ./gst-env.py gst-inspect-1.0 --version
    - ./gst-env.py gst-inspect-1.0
  after_script:
    - mv build/meson-logs/ meson-logs
  artifacts:
    expire_in: "7 days"
    when: "always"
    paths:
      - 'meson-logs/'
  rules:
    - !reference [.upstream-branch-rules, rules]
    - changes:
        *modules_changes
    - changes:
        - subprojects/gstreamer-vaapi/**/*

.build simple:
  extends:
    - '.build'
    - '.build_ccache_vars'
  variables:
    GST_WERROR: "true"
    MESON_ARGS: "${SIMPLE_BUILD}"
    SUBPROJECTS_CACHE_DIR: "/subprojects"
  script:
    - $CI_PROJECT_DIR/ci/scripts/build.sh
    - ./gst-env.py gst-inspect-1.0 --version
    - ./gst-env.py gst-inspect-1.0
    - G_DEBUG=fatal_criticals ./gst-env.py gst-inspect-1.0 --print-all --gst-disable-registry-fork > /dev/null
    - meson install --destdir $CI_PROJECT_DIR/destdir -C build
    - rm -rf $CI_PROJECT_DIR/destdir

.build fedora x86_64:
  extends:
    - '.fedora image'
    - '.fdo.suffixed-image@fedora'
    - '.build simple'
  needs:
    - "trigger"
    - "fedora amd64 docker"

build fedora gcc:
  extends: '.build fedora x86_64'
  variables:
    CC: 'ccache gcc'
    CXX: 'ccache g++'
  parallel:
    matrix:
      - BUILD_TYPE: [ "--default-library=shared", "--default-library=both"]
        BUILD_GST_DEBUG: ["-Dgstreamer:gst_debug=true", "-Dgstreamer:gst_debug=false"]

      - BUILD_TYPE: ["--default-library=static"]
        BUILD_GST_DEBUG: ["-Dgstreamer:gst_debug=true", "-Dgstreamer:gst_debug=false"]
        # Passing Dpython=enabled prohibits us from -Dgst-editing-services:python=disabled which we
        # currently need to statically build ges.
        #
        # subprojects/gst-editing-services/meson.build:153:4: ERROR: Problem encountered: Want to build python based modules but it is not supported while static building
        # https://github.com/mesonbuild/meson/issues/5214
        # https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4281?commit_id=d1a687b61d8fbc5ae35b4bb62aa7fd1d091818f2#note_1875699
        #
        # VAAPI can't be build statically yet
        # subprojects/gstreamer-vaapi/meson.build:8:2: ERROR: Problem encountered: GStreamer-VAAPI plugin not supported with `static` builds yet.
        #
        # Disabling gstreamer-sharp tests because they download things as part of configure with
        # nuget which frequently fails on the CI (possibly because we're hammering the site)
        MESON_ARGS: "${DEFAULT_MESON_ARGS} -Dvaapi=disabled -Dpython=auto -Dgst-editing-services:python=disabled -Dintrospection=disabled -Ddoc=disabled -Dgstreamer-sharp:tests=disabled"

build fedora clang:
  extends: '.build fedora x86_64'
  variables:
    CC: 'ccache clang'
    CXX: 'ccache clang++'
  parallel:
    matrix:
      - BUILD_TYPE: [ "--default-library=shared", "--default-library=both"]
        BUILD_GST_DEBUG: ["-Dgstreamer:gst_debug=true", "-Dgstreamer:gst_debug=false"]
        MESON_ARGS: >-
          ${SIMPLE_BUILD}
          --force-fallback-for=glib

      - BUILD_TYPE: ["--default-library=static"]
        BUILD_GST_DEBUG: ["-Dgstreamer:gst_debug=true", "-Dgstreamer:gst_debug=false"]
        # VAAPI can't be build statically yet
        # subprojects/gstreamer-vaapi/meson.build:8:2: ERROR: Problem encountered: GStreamer-VAAPI plugin not supported with `static` builds yet.
        #
        # Disabling gstreamer-sharp tests because they download things as part of configure with
        # nuget which frequently fails on the CI (possibly because we're hammering the site)
        MESON_ARGS: >-
          ${DEFAULT_MESON_ARGS}
          -Dvaapi=disabled
          -Dintrospection=disabled
          -Dpython=disabled
          -Ddoc=disabled
          -Dgstreamer-sharp:tests=disabled
          --force-fallback-for=glib

build debian x86_64:
  extends:
    - '.debian image'
    - '.fdo.suffixed-image@debian'
    - '.build simple'
  needs:
    - "trigger"
    - "debian amd64 docker"
  variables:
    BUILD_TYPE: "--default-library=shared"
    BUILD_GST_DEBUG: "-Dgstreamer:gst_debug=true"

.build windows:
  image: $WINDOWS_IMAGE
  stage: 'build'
  tags:
    - 'docker'
    - 'windows'
    - '2022'
  needs:
    - "trigger"
    - "windows amd64 docker"
  timeout: '90m'
  variables:
    MESON_ARGS: >-
      ${DEFAULT_MESON_ARGS}
      -Dlibav=disabled
      -Dvaapi=disabled
      -Dgst-plugins-base:pango=enabled
      -Dgst-plugins-good:cairo=enabled
      -Dgst-plugins-good:soup=enabled
      -Dgst-plugins-bad:d3d11-wgc=enabled
  rules:
    - !reference [.upstream-branch-rules, rules]
    - changes:
        *modules_changes
    - changes:
        - subprojects/win-*/*
  script:
    # Make sure powershell exits on errors
    # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6
    - $ErrorActionPreference = "Stop"

    # Set the code page to UTF-8
    - chcp 65001
    # Renormalize line endings
    - git add --renormalize subprojects/packagefiles
    - $env:PYTHONUNBUFFERED = '1'
    - ci/scripts/handle-subprojects-cache.py --cache-dir /subprojects subprojects/
    - $env:PYTHONUNBUFFERED = ''
    - echo $env:MESON_ARGS
    # We do not pick up any deps with cmake, so speed up dependency checks
    - $env:CMAKE = 'false'
  artifacts:
   expire_in: "7 days"
   when: "always"
   paths:
     - 'build/meson-logs/'

build vs2022 amd64:
  extends: '.build windows'
  script:
    - !reference [".build windows", "script"]
    - meson setup --vsenv build $env:MESON_ARGS
    - meson compile -C build --jobs $env:FDO_CI_CONCURRENT
    - .\gst-env.py gst-inspect-1.0.exe --version
    - .\gst-env.py gst-inspect-1.0.exe
    - mkdir destdir
    - meson install -C build --destdir installdir
    - Remove-Item -Recurse -Force build\installdir
  variables:
    # FIXME: https://github.com/mesonbuild/meson/pull/11007
    PKG_CONFIG: ${CI_PROJECT_DIR}/subprojects/win-pkgconfig/pkg-config.exe

build vs2022 amd64 full-static:
  extends: ".build windows"
  script:
    - !reference [".build windows", "script"]
    - echo $env:MESON_ARGS
    - cmd.exe /C "meson setup --vsenv build --default-library=static $env:MESON_ARGS"
    - meson compile -C build --jobs $env:FDO_CI_CONCURRENT
    - .\gst-env.py gst-inspect-1.0.exe --version
    - .\gst-env.py gst-inspect-1.0.exe
  variables:
    MESON_ARGS: >-
      -Dintrospection=disabled
      -Dpython=disabled
      -Dlibav=disabled
      -Ddoc=disabled
      -Dgst-full-target-type=static_library

.build windows cross:
  extends: '.build windows'
  script:
    - !reference [".build windows", "script"]
      # Setting up a cross build with MSVC is still non-trivial because
      # the --vsenv argument cannot be used to set it up
    - echo $env:MESON_CROSS_ARGS
    - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH && meson setup build $env:MESON_ARGS $env:MESON_CROSS_ARGS"
    - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH && meson compile -C build --jobs $env:FDO_CI_CONCURRENT"

build vs2022 x86:
  extends: '.build windows cross'
  variables:
    ARCH: 'x86'
    # Installed python is 64 bits instead of 32 bits
    MESON_CROSS_ARGS: >
      -Dpython=disabled
      -Dintrospection=disabled

build vs2022 arm64:
  extends: '.build windows cross'
  rules:
    - when: 'manual'
      allow_failure: true
  variables:
    ARCH: 'arm64'
    # pango pulls in cairo which pulls in pixman which doesn't build because of
    # https://github.com/mesonbuild/meson/issues/9889
    # libsoup requires glib-compile-resources, which isn't available in a cross
    # build
    MESON_CROSS_ARGS: >-
      -Dgst-plugins-base:pango=disabled
      -Dgst-plugins-good:cairo=disabled
      -Dgst-devtools:cairo=disabled
      -Dpython=disabled
      -Dintrospection=disabled
      --cross-file ci/meson/vs2022-paths.ini
      --cross-file ci/meson/vs2022-arm64-cross.ini
      --native-file ci/meson/vs2022-paths.ini
      --native-file ci/meson/vs2022-x64-native.ini

build msys2:
  extends: '.build windows'
  script:
    - !reference [".build windows", "script"]
    # Replace backslashes with forward so bash doesn't complain
    - $env:CI_PROJECT_DIR = $env:CI_PROJECT_DIR.replace('\','/')
    # Windows Graphics Capture currently requires Visual Studio
    - $env:MESON_ARGS = $env:MESON_ARGS.replace('-Dgst-plugins-bad:d3d11-wgc=enabled','') + ' -Dpython=disabled -Dintrospection=disabled'
    # Configure MSYS2 to use the UCRT64 environment, start in the same directory
    # and inherit PATH
    - C:\msys64\msys2_shell.cmd -ucrt64 -defterm -no-start -here -use-full-path -lc "meson setup build $env:MESON_ARGS && meson compile -C build --jobs $env:FDO_CI_CONCURRENT"

build macos:
  extends:
   - '.build'
   - '.macos image'
  variables:
    # gst-libav/ffmpeg throws Wundef errors
    GST_WERROR: "false"
    MESON_ARGS: "${DEFAULT_MESON_ARGS}"
    SUBPROJECTS_CACHE_DIR: "/Users/gst-ci/subprojects"
  rules:
    - !reference [.upstream-branch-rules, rules]
    - changes:
        *modules_changes
    - changes:
        - subprojects/macos-*/*
  parallel:
    matrix:
      - BUILD_TYPE: ["--default-library=both"]
        BUILD_GST_DEBUG: ["-Dgstreamer:gst_debug=true"]
        # FIXME: We currently don't have pkg-config required by gobject-introspection/pygobject/sharp
        # macos doesn't support vaapi
        MESON_ARGS: >-
          ${SIMPLE_BUILD}
          -Dintrospection=disabled
          -Dvaapi=disabled
          -Dsharp=disabled
          -Dpython=disabled
          -Ddoc=disabled
          -Dgst-plugins-base:pango=enabled
          -Dgst-plugins-good:cairo=enabled
          -Dgst-plugins-good:soup=enabled

# ---- Tests ----- #

.test:
  stage: 'test'
  extends:
    - '.build_ccache_vars'
  needs:
    - "trigger"
  variables:
    GST_WERROR: "true"
    MESON_ARGS: "${SIMPLE_BUILD}"
    SUBPROJECTS_CACHE_DIR: "/subprojects"

    # Avoid weird issue about cross-device links
    # https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3197
    GI_SCANNER_DISABLE_CACHE: "1"

    # Disable colored output to avoid weird rendering issues
    GST_DEBUG_NO_COLOR: "true"
    CI_ARTIFACTS_URL: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/validate-logs/"
    GST_VALIDATE_LAUNCHER_FORCE_COLORS: "true"
    TIMEOUT_FACTOR: "2"
    # Enable the fault handler so we get backtraces on segfaults.
    # any non-empty string will do
    PYTHONFAULTHANDLER: "enabled"
  rules:
    - changes:
        *modules_changes
  script:
    # Disable gdb debugdir safeload
    # The CI will execute any code submitted to it anyway
    - mkdir -p ~/.config/gdb
    - echo "set auto-load safe-path /" >> ~/.config/gdb/gdbinit

    - $CI_PROJECT_DIR/ci/scripts/build.sh
    - $CI_PROJECT_DIR/ci/scripts/test.sh
  after_script:
    - mv build/meson-logs/ meson-logs
  artifacts:
    expire_in: '14 days'
    when: always
    paths:
      - 'meson-logs/'
      - "$CI_PROJECT_DIR/validate-logs"
    reports:
      junit:
        - "$CI_PROJECT_DIR/validate-logs/*.xml"

.test fedora x86_64:
  extends:
    - '.fedora image'
    - '.fdo.suffixed-image@fedora'
    - '.test'
  needs:
    - "trigger"
    - "fedora amd64 docker"
  tags: ['gstreamer']

check fedora:
  extends: '.test fedora x86_64'
  variables:
    TEST_SUITE: "check.gst*"
  rules:
    - changes:
        *modules_changes
    - changes:
        - subprojects/gstreamer-vaapi/**/*

integration testsuites fedora:
  extends: '.test fedora x86_64'
  parallel: 8
  variables:
    MESON_ARGS: >-
      ${SIMPLE_BUILD}
      -Dsharp=disabled
      -Dvaapi=disabled
      -Dexamples=disabled
      -Dgst-examples=disabled
      -Dtests=disabled
      -Dnls=disabled
      -Dqt5=disabled
      -Dgstreamer:benchmarks=disabled
      -Dgst-plugins-good:gtk3=disabled
      -Dgst-plugins-bad:microdns=disabled
      -Dgst-plugins-bad:avtp=disabled
      -Dgst-plugins-bad:opencv=disabled
      -Dgst-plugins-bad:webrtc=disabled
    EXTRA_VALIDATE_ARGS: "--timeout-factor=2 --retry-on-failures --parts=${CI_NODE_TOTAL} --part-index=${CI_NODE_INDEX} --sync"
    TEST_SUITE: "validate ges"

check video formats:
  stage: 'test'
  extends:
    - '.fedora image'
    - '.fdo.suffixed-image@fedora'
    - '.build_ccache_vars'
  needs:
    - "trigger"
    - "fedora amd64 docker"
  tags: ['gstreamer']
  variables:
    MESON_ARGS: "${SIMPLE_BUILD}"
    BUILD_GST_DEBUG: "-Dgstreamer:gst_debug=true"
    GST_WERROR: "true"
    VIDEO_TOKEN: "GST_VIDEO_FORMATS_ALL_STR"
    VIDEO_HEADER: "subprojects/gst-plugins-base/gst-libs/gst/video/video-format.h"
    WL_TOKEN: "GST_WL_VIDEO_FORMATS"
    WL_HEADER: "subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwlvideoformat.h"
  script:
    - $CI_PROJECT_DIR/ci/scripts/build.sh
    - $CI_PROJECT_DIR/ci/scripts/check-video-formats.sh
  rules:
    - changes:
      - ${VIDEO_HEADER}
      - ${WL_HEADER}

playbin3 integration:
  extends: 'integration testsuites fedora'
  variables:
    USE_PLAYBIN3: 1
  # Let's allow failures for now until we're 100% sure everything works
  allow_failure: true

# gstreamer-full:
gstreamer-full static build:
  extends: '.build fedora x86_64'
  stage: 'build'
  variables:
    BUILD_TYPE: "--default-library=static"
    MESON_ARGS: >-
      -Ddoc=disabled
    SUBPROJECTS_CACHE_DIR: "/subprojects"
  script:
  - $CI_PROJECT_DIR/ci/scripts/build.sh
  - meson test -C build -v test-gst-full

gstreamer-full-minimal static build:
  extends: 'gstreamer-full static build'
  stage: 'build'
  variables:
    BUILD_GST_DEBUG: "-Dgstreamer:gst_debug=false"
    GST_WERROR: "true"
    BUILD_TYPE: "--default-library=static"
    MESON_ARGS: >-
      -Ddoc=disabled
      -Dauto_features=disabled
      -Dgstreamer:check=enabled
      -Dtests=enabled
      -Dgst-plugins-base:alsa=enabled
      -Dgst-plugins-base:typefind=enabled
      -Dgst-plugins-base:pbtypes=enabled
      -Dgst-full-elements=coreelements:filesrc,fakesink,identity,input-selector
      -Dgst-full-typefind-functions=typefindfunctions:wav,flv
      -Dgst-full-device-providers=alsa:alsadeviceprovider
      -Dgst-full-dynamic-types=pbtypes:video_multiview_flagset
    SUBPROJECTS_CACHE_DIR: "/subprojects"

  script:
  - $CI_PROJECT_DIR/ci/scripts/build.sh
  - meson test -C build -v test-gst-full
  - 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"
  - strip build/libgstreamer-full-1.0.so
  - ls -l build/libgstreamer-full-1.0.so

# v4l2-stateless-decoders tests
fluster v4l2-stateless on visl:
  extends: 'gstreamer-full static build'
  stage: 'test'
  variables:
    BUILD_GST_DEBUG: '-Dgstreamer:gst_debug=false'
    GST_WERROR: "true"
    BUILD_TYPE: "--default-library=static"
    MESON_ARGS: >-
      -Dvirtme_kernel_image=/opt/linux/bzImage
      -Dauto_features=disabled
      -Dgstreamer:check=enabled
      -Ddoc=disabled
      -Dtests=enabled
      -Dtools=enabled
      -Dbase=enabled
      -Dbad=enabled
      -Dugly=disabled
      -Dlibav=disabled
      -Drtsp_server=disabled
      -Dges=disabled
      -Dgst-plugins-bad:debugutils=enabled
      -Dgst-plugins-bad:ivfparse=enabled
      -Dgst-plugins-bad:v4l2codecs=enabled
      -Dgst-plugins-bad:videoparsers=enabled
      -Dgst-plugins-base:app=enabled
      -Dgst-plugins-base:videoconvertscale=enabled
      -Dgst-plugins-base:typefind=enabled
      -Dgst-plugins-base:playback=enabled
      -Dgst-plugins-good:matroska=enabled
    SUBPROJECTS_CACHE_DIR: "/subprojects"
  script:
  - $CI_PROJECT_DIR/ci/scripts/build.sh
  - meson test -C build -v --suite v4l2-stateless-decoders
  artifacts:
    reports:
      junit: build/fluster-results-*.xml
  rules:
    - changes:
      - .gitlab-ci.yml
      - .gitlab-image-tags.yml
      - subprojects/gst-plugins-bad/sys/v4l2codecs/*
      - subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/*
      - subprojects/gst-plugins-bad/gst-libs/gst/codecs/*
      - subprojects/gst-plugins-bad/gst/videoparsers/*
      - tests/virtme/*
      - ci/scripts/build-linux.sh
      - ci/docker/fedora/*

# Valgrind
.valgrind fedora x86_64:
  extends: '.test fedora x86_64'
  stage: 'test'
  variables:
    EXTRA_VALIDATE_ARGS: "--valgrind"
  rules:
    - changes:
        *modules_changes
    - changes:
        - subprojects/gstreamer-vaapi/**/*

valgrind core:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gstreamer\\..*"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*

valgrind base:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gst-plugins-base\\..*"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci//**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-plugins-base/**/*

valgrind good:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gst-plugins-good\\..*"
    # take longer time due to splitmux unit test
    TIMEOUT_FACTOR: "4"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*

valgrind ugly:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gst-plugins-ugly\\..*"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*
      - subprojects/gst-plugins-ugly/**/*

valgrind bad:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gst-plugins-bad\\..*"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*
      - subprojects/gst-plugins-bad/**/*

valgrind ges:
  extends: '.valgrind fedora x86_64'
  variables:
    TEST_SUITE: "check.gst-editing-services\\..*"
  rules:
    - changes:
      - "*"
      - scripts/*
      - ci/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*
      - subprojects/gst-plugins-bad/**/*
      - subprojects/gst-editing-services/**/*
      - subprojects/gst-python/**/*
  # valgrind ges jobs are racy across the board and simply fail too often.
  # Someone needs to go through job logs and figure out which jobs to mark
  # as flaky. Until then, just ignore failures.
  allow_failure: true

# ---- Integration ----- #

.documentation:
  extends: '.build fedora x86_64'
  variables:
    # Disable svthevcenc until the following MR is merged
    # https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5447
    MESON_ARGS: >-
      ${SIMPLE_BUILD}
      -Ddoc=enabled
      -Drs=enabled
      -Dgst-docs:fatal_warnings=true
      -Dgst-plugins-bad:svthevcenc=disabled
    # Disable werror for the docs build, we don't need it
    GST_WERROR: 'false'
    SUBPROJECTS_CACHE_DIR: "/subprojects"
    CI_ARTIFACTS_URL: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/"
  script:
    - $CI_PROJECT_DIR/ci/scripts/build-docs.sh
  artifacts:
    when: always
    expire_in: "7 days"
    paths:
    - documentation/
    - diffs/

#
# This jobs runs in gstreamer namespace when after the merge into main branch.
# The produced artifact is later used to automatically update the web page.
#
documentation:
  stage: integrate
  extends:
    - '.documentation'
  needs:
    - "fedora amd64 docker"
  rules:
    - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == "main"'

#
# This job is run in users namespace to validate documentation before merging
# MR.
#
build documentation:
  extends:
    - '.documentation'
  stage: build
  needs:
    - "trigger"
    - "fedora amd64 docker"
  rules:
    # Never run post merge, we have the `documentation` always running for that
    - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == $GST_UPSTREAM_BRANCH'
      when: never
    - changes:
      - .gitlab-ci.yml
      - .gitlab-image-tags.yml
      - ci/gitlab/*.py
      - subprojects/*.wrap
      - subprojects/gst-docs/**/*
      - subprojects/gst-devtools/**/*
      - subprojects/gst-editing-services/**/*
      - subprojects/gst-libav/**/*
      - subprojects/gst-plugins-bad/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*
      - subprojects/gst-plugins-ugly/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gstreamer-vaapi/**/*
      - subprojects/gst-rtsp-server/**/*

# FIXME: Using trigger: causes permission issues, workaround using old REST API.
# https://gitlab.com/gitlab-org/gitlab/-/issues/341737
cerbero trigger:
  stage: build
  timeout: '4h'
  tags:
    - placeholder-job
  extends:
    - '.fedora image'
    - '.fdo.suffixed-image@fedora'
  needs:
    - "trigger"
    - "fedora amd64 docker"
  script:
    - ci/gitlab/trigger_cerbero_pipeline.py

  rules:
    - if: '$MESON_COMMIT'
    # Never run post merge
    - if: '$CI_PROJECT_NAMESPACE == "gstreamer" && $CI_COMMIT_BRANCH == $GST_UPSTREAM_BRANCH'
      when: never
    - changes:
      - .gitlab-ci.yml
      - ci/gitlab/*.py
      - subprojects/gst-devtools/**/*
      - subprojects/gst-editing-services/**/*
      - subprojects/gst-libav/**/*
      - subprojects/gst-plugins-bad/**/*
      - subprojects/gst-plugins-base/**/*
      - subprojects/gst-plugins-good/**/*
      - subprojects/gst-plugins-ugly/**/*
      - subprojects/gst-python/**/*
      - subprojects/gstreamer/**/*
      - subprojects/gst-rtsp-server/**/*
      - subprojects/gst-examples/**/*