summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: cab0b5c2c281156d7f6714a56c9ea3990b0da8bf (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
# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0 filetype=yaml:

########################################
#                                      #
# THIS FILE IS GENERATED, DO NOT EDIT  #
#                                      #
########################################

.templates_sha: &template_sha b7030c2cd0d6ccc5f6d4f8299bafa4daa9240d71 # see https://docs.gitlab.com/ee/ci/yaml/#includefile

include:
  # Alpine container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/alpine.yml'
  # Arch container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/arch.yml'
  # Centos container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/centos.yml'
  # Debian container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/debian.yml'
  # Fedora container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/fedora.yml'
  # Ubuntu container builder template
  - project: 'wayland/ci-templates'
    ref: *template_sha
    file: '/templates/ubuntu.yml'

stages:
  - prep             # rebuild the container images if there is a change
  - build            # for actually building and testing things in a container
  - VM               # for running the test suite in a VM
  - autotools        # distribution builds with autotools
  - meson            # distribution builds with meson
  - tarballs         # tarball builds
  - container_clean  # clean up unused container images

variables:
  ###############################################################################
  # This is the list of packages required to build libevdev with the default    #
  # configuration.                                                              #
  #                                                                             #
  # Run dnf install/apt-get install/.. with the list of packages for your       #
  # distribution                                                                #
  ###############################################################################
  FEDORA_RPMS: 'git gcc gcc-c++ meson automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils doxygen xz clang-analyzer'
  CENTOS_RPMS: 'git gcc gcc-c++       automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils xz'
  UBUNTU_DEBS: 'git gcc g++     meson automake autoconf libtool make pkg-config python3 check       valgrind binutils doxygen xz-utils'
  DEBIAN_DEBS: $UBUNTU_DEBS
  ARCH_PKGS:   'git gcc         meson automake autoconf libtool make pkgconfig  python3 check       valgrind binutils doxygen'
  ALPINE_PKGS: 'git gcc g++     meson automake autoconf libtool make pkgconfig  python3 check-dev   valgrind binutils doxygen xz linux-headers'
  ############################ end of package lists #############################
  # these tags should be updated each time the list of packages is updated
  # changing these will force rebuilding the associated image
  # Note: these tags have no meaning and are not tied to a particular
  # libevdev version
  FEDORA_TAG: '2020-02-24.0'
  CENTOS_TAG: '2020-02-24.0'
  DEBIAN_TAG: '2020-02-24.0'
  UBUNTU_TAG: '2020-02-24.0'
  ARCH_TAG:   '2020-02-24.0'
  ALPINE_TAG: '2020-02-24.0'
  QEMU_TAG:   'qemu-2020-02-24.0'

  UPSTREAM_REPO: libevdev/libevdev
  BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
  FEDORA_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$FEDORA_TAG
  CENTOS_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/centos/$CENTOS_VERSION:$CENTOS_TAG
  UBUNTU_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$UBUNTU_VERSION:$UBUNTU_TAG
  DEBIAN_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/debian/$DEBIAN_VERSION:$DEBIAN_TAG
  ARCH_CONTAINER_IMAGE:   $CI_REGISTRY_IMAGE/archlinux/rolling:$ARCH_TAG
  ALPINE_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/alpine/latest:$ALPINE_TAG
  QEMU_CONTAINER_IMAGE:   $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$QEMU_TAG

  LIBEVDEV_SKIP_ROOT_TESTS: 1
  GIT_DEPTH: 1
  MESON_BUILDDIR: 'build dir'

.default_artifacts:
  artifacts:
    paths:
      - _build/test/test-suite.log
      - $MESON_BUILDDIR/meson-logs/
    expire_in: 1 week
    when: on_failure
    reports:
      junit: $MESON_BUILDDIR/junit-*.xml

.autotools_build:
  extends:
    - .default_artifacts
  script:
    - mkdir _build
    - pushd _build > /dev/null
    - ../autogen.sh --disable-silent-rules $CONFIGURE_FLAGS
    - make
    - make check
    - if ! [[ -z "$MAKE_ARGS" ]]; then make $MAKE_ARGS; fi
    - popd > /dev/null

.meson_build:
  extends:
    - .default_artifacts
  script:
    - .gitlab-ci/meson-build.sh

#################################################################
#                                                               #
#                          prep stage                           #
#                                                               #
#################################################################

# Re-generate the CI script and make sure it's the one currently checked in
# If this job fails, re-generate the gitlab-ci.yml script, see
# $SRCDIR/.gitlab-ci/generate-gitlab-ci.py
#
check-ci-script:
  image: golang:alpine
  stage: prep
  before_script:
    - apk add python3 git
    - pip3 install --user jinja2 PyYAML
  script:
    - python3 ./.gitlab-ci/generate-gitlab-ci.py
    - git diff --exit-code && exit 0 || true
    - echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
    - exit 1

check-commit:
  image: golang:alpine
  stage: prep
  before_script:
    - apk add python3 git
  script:
    - pip3 install GitPython
    - pip3 install pytest
    - |
      pytest --junitxml=results.xml \
             --tb=line \
             --assert=plain \
             ./.gitlab-ci/check-commit.py
  except:
    - master@libevdev/libevdev
  variables:
    GIT_DEPTH: 100
  artifacts:
    reports:
      junit: results.xml

.pull_upstream_or_rebuild:
  before_script:
    # log in to the registry
    - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # get the full container image name (DISTRIB_VERSION still has indirections)
    - IMAGE=$(eval echo "$DISTRIB_FLAVOR/$DISTRIB_VERSION:$TAG")

    - |
      # force rebuild if schedule, reuse otherwise
      if [[ $CI_PIPELINE_SOURCE != "schedule" ]] ;
      then
        # pull the latest upstream image if it exists
        skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE \
                    docker://$CI_REGISTRY_IMAGE/$IMAGE && exit 0 || true ;

        # check if our image is already in the current registry
        skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
      fi

fedora:31@qemu-prep:
  extends:
    - .fedora@qemu-build
    - .pull_upstream_or_rebuild
  stage: prep
  tags:
    - kvm
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 31
    FEDORA_TAG: $QEMU_TAG
    DISTRIB_FLAVOR: fedora
    DISTRIB_VERSION: $FEDORA_VERSION
    TAG: $QEMU_TAG
  allow_failure: true


### fedora 30
fedora:30@container-prep:
  extends:
    - .fedora@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: '30'
    DISTRIB_FLAVOR: fedora
    DISTRIB_VERSION: $FEDORA_VERSION
    TAG: $FEDORA_TAG


### fedora 31
fedora:31@container-prep:
  extends:
    - .fedora@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: '31'
    DISTRIB_FLAVOR: fedora
    DISTRIB_VERSION: $FEDORA_VERSION
    TAG: $FEDORA_TAG


### ubuntu 19.10
ubuntu:19.10@container-prep:
  extends:
    - .ubuntu@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: '19.10'
    DISTRIB_FLAVOR: ubuntu
    DISTRIB_VERSION: $UBUNTU_VERSION
    TAG: $UBUNTU_TAG


### ubuntu 19.04
ubuntu:19.04@container-prep:
  extends:
    - .ubuntu@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: '19.04'
    DISTRIB_FLAVOR: ubuntu
    DISTRIB_VERSION: $UBUNTU_VERSION
    TAG: $UBUNTU_TAG


### debian stable
debian:stable@container-prep:
  extends:
    - .debian@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    DEBIAN_VERSION: 'stable'
    DISTRIB_FLAVOR: debian
    DISTRIB_VERSION: $DEBIAN_VERSION
    TAG: $DEBIAN_TAG


### debian sid
debian:sid@container-prep:
  extends:
    - .debian@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    DEBIAN_VERSION: 'sid'
    DISTRIB_FLAVOR: debian
    DISTRIB_VERSION: $DEBIAN_VERSION
    TAG: $DEBIAN_TAG


### centos 7
centos:7@container-prep:
  extends:
    - .centos@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    CENTOS_VERSION: '7'
    DISTRIB_FLAVOR: centos
    DISTRIB_VERSION: $CENTOS_VERSION
    TAG: $CENTOS_TAG


### centos 8
centos:8@container-prep:
  extends:
    - .centos@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    CENTOS_VERSION: '8'
    DISTRIB_FLAVOR: centos
    DISTRIB_VERSION: $CENTOS_VERSION
    TAG: $CENTOS_TAG


### arch rolling
arch:rolling@container-prep:
  extends:
    - .arch@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    ARCH_VERSION: 'rolling'
    DISTRIB_FLAVOR: arch
    DISTRIB_VERSION: $ARCH_VERSION
    TAG: $ARCH_TAG


### alpine latest
alpine:latest@container-prep:
  extends:
    - .alpine@container-build
    - .pull_upstream_or_rebuild
  stage: prep
  variables:
    GIT_STRATEGY: none
    ALPINE_VERSION: 'latest'
    DISTRIB_FLAVOR: alpine
    DISTRIB_VERSION: $ALPINE_VERSION
    TAG: $ALPINE_TAG


#################################################################
#                                                               #
#                   container clean stage                       #
#                 run during the clean stage                    #
#                                                               #
#################################################################

#
# This stage will look for the container images we currently have in
# the registry and will remove any that are not tagged with the provided
# $container_image:$tag
#
.container-clean:
  stage: container_clean
  image: $BUILDAH_IMAGE
  script:
    # get the full container image name (CURRENT_CONTAINER_IMAGE still has indirections)
    - CONTAINER_IMAGE=$(eval echo "$CURRENT_CONTAINER_IMAGE")
    - GITLAB=$(echo $CI_PROJECT_URL | cut -f3 -d/)
    - REPOSITORY=$(echo $CONTAINER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
    - IMAGE_PATH=$(echo $CONTAINER_IMAGE | cut -f1 -d:)
    - LATEST_TAG=$(echo $CONTAINER_IMAGE | cut -f2 -d:)

    # log in to the registry (read only)
    - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # get the r/w token from the settings to access the registry
    #
    # each developer needs to register a secret variable that contains
    # a personal token with api access. The token
    # - must be named PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
    # - must be registered in the CI/CD Variables section as type file
    # - value must be a netrc file as a single-line string:
    #   default login <user> password <token value>
    #   e.g. "default login bentiss password 1235abcde"
    - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
    - netrcfile=$(eval echo "\$$tokenname")
    - if [[ ! -f "$netrcfile" ]]; then
         echo "No netrc file found or token is missing, skipping job" && false;
      fi

    # request a token for the registry API
    - REGISTRY_TOKEN=$(curl https://$GITLAB/jwt/auth --get
                             --silent --show-error
                             -d client_id=docker
                             -d offline_token=true
                             -d service=container_registry
                             -d "scope=repository:$REPOSITORY:pull,*"
                             --fail
                             --netrc-file "$netrcfile"
                             | sed -r 's/(\{"token":"|"\})//g')

    # get the digest of the latest image
    - LATEST_MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.Digest')

    # get the list of tags
    - TAGS=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.RepoTags[]')
    # FIXME: is the above command working properly? If not, use below:
    # - TAGS=$(curl -X GET -H "accept:application/vnd.docker.distribution.manifest.v2+json"
    #                      -H "authorization:Bearer $REGISTRY_TOKEN"
    #                      https://$CI_REGISTRY/v2/$REPOSITORY/tags/list | jq -r '.tags[]')

    # iterate over the tags
    - for tag in $TAGS;
      do
        MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$tag | jq -r '.Digest');
        if test x"$MANIFEST" != x"$LATEST_MANIFEST";
          then
            echo removing $tag as $MANIFEST;
            curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$MANIFEST --silent
                 -H "accept:application/vnd.docker.distribution.manifest.v2+json"
                 -H "authorization:Bearer $REGISTRY_TOKEN"
                 --fail --show-error -X DELETE || true
          ;fi
      ;done
  dependencies: []
  allow_failure: true
  only:
    - schedules


### fedora 30
fedora:30@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: '30'
    CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE


### fedora 31
fedora:31@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: '31'
    CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE


### ubuntu 19.10
ubuntu:19.10@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: '19.10'
    CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE


### ubuntu 19.04
ubuntu:19.04@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: '19.04'
    CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE


### debian stable
debian:stable@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    DEBIAN_VERSION: 'stable'
    CURRENT_CONTAINER_IMAGE: $DEBIAN_CONTAINER_IMAGE


### debian sid
debian:sid@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    DEBIAN_VERSION: 'sid'
    CURRENT_CONTAINER_IMAGE: $DEBIAN_CONTAINER_IMAGE


### centos 7
centos:7@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    CENTOS_VERSION: '7'
    CURRENT_CONTAINER_IMAGE: $CENTOS_CONTAINER_IMAGE


### centos 8
centos:8@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    CENTOS_VERSION: '8'
    CURRENT_CONTAINER_IMAGE: $CENTOS_CONTAINER_IMAGE


### arch rolling
arch:rolling@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    ARCH_VERSION: 'rolling'
    CURRENT_CONTAINER_IMAGE: $ARCH_CONTAINER_IMAGE


### alpine latest
alpine:latest@container-clean:
  extends: .container-clean
  variables:
    GIT_STRATEGY: none
    ALPINE_VERSION: 'latest'
    CURRENT_CONTAINER_IMAGE: $ALPINE_CONTAINER_IMAGE


#################################################################
#                                                               #
#                       build stage                             #
#                                                               #
#################################################################

.autotools-build@template:
  extends:
    - .autotools_build
  stage: build
  dependencies: []
  variables:
    MAKE_ARGS: "distcheck"

.meson-build@template:
  extends:
    - .meson_build
  stage: build
  dependencies: []
  variables:
    NINJA_ARGS: "dist"


fedora:30@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: '30'
  needs: ['fedora:30@container-prep']

fedora:30@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: '30'
  needs: ['fedora:30@container-prep']


fedora:31@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: '31'
  needs: ['fedora:31@container-prep']

fedora:31@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: '31'
  needs: ['fedora:31@container-prep']


ubuntu:19.10@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $UBUNTU_CONTAINER_IMAGE
  variables:
    UBUNTU_VERSION: '19.10'
  needs: ['ubuntu:19.10@container-prep']

ubuntu:19.10@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $UBUNTU_CONTAINER_IMAGE
  variables:
    UBUNTU_VERSION: '19.10'
  needs: ['ubuntu:19.10@container-prep']


ubuntu:19.04@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $UBUNTU_CONTAINER_IMAGE
  variables:
    UBUNTU_VERSION: '19.04'
  needs: ['ubuntu:19.04@container-prep']

ubuntu:19.04@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $UBUNTU_CONTAINER_IMAGE
  variables:
    UBUNTU_VERSION: '19.04'
  needs: ['ubuntu:19.04@container-prep']


debian:stable@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $DEBIAN_CONTAINER_IMAGE
  variables:
    DEBIAN_VERSION: 'stable'
  needs: ['debian:stable@container-prep']

debian:stable@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $DEBIAN_CONTAINER_IMAGE
  variables:
    DEBIAN_VERSION: 'stable'
  needs: ['debian:stable@container-prep']


debian:sid@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $DEBIAN_CONTAINER_IMAGE
  variables:
    DEBIAN_VERSION: 'sid'
  needs: ['debian:sid@container-prep']

debian:sid@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $DEBIAN_CONTAINER_IMAGE
  variables:
    DEBIAN_VERSION: 'sid'
  needs: ['debian:sid@container-prep']


centos:7@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $CENTOS_CONTAINER_IMAGE
  variables:
    CENTOS_VERSION: '7'
    MAKE_ARGS: ''  # disable distcheck, requires doxygen
  needs: ['centos:7@container-prep']



centos:8@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $CENTOS_CONTAINER_IMAGE
  variables:
    CENTOS_VERSION: '8'
    MAKE_ARGS: ''  # disable distcheck, requires doxygen
  needs: ['centos:8@container-prep']



arch:rolling@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $ARCH_CONTAINER_IMAGE
  variables:
    ARCH_VERSION: 'rolling'
  needs: ['arch:rolling@container-prep']

arch:rolling@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $ARCH_CONTAINER_IMAGE
  variables:
    ARCH_VERSION: 'rolling'
  needs: ['arch:rolling@container-prep']


alpine:latest@autotools-build:
  extends: .autotools-build@template
  stage: autotools
  image: $ALPINE_CONTAINER_IMAGE
  variables:
    ALPINE_VERSION: 'latest'
  needs: ['alpine:latest@container-prep']

alpine:latest@meson-build:
  extends: .meson-build@template
  stage: meson
  image: $ALPINE_CONTAINER_IMAGE
  variables:
    ALPINE_VERSION: 'latest'
  needs: ['alpine:latest@container-prep']


# Build argument tests
#
# We only run the build option combinations on one image
# because they're supposed to fail equally on all
.fedora-custom-build@autotools-template:
  extends: .autotools-build@template
  stage: build
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: 31
  needs: ['fedora:31@container-prep']

no-valgrind:autotools:
  extends: .fedora-custom-build@autotools-template
  before_script:
    - dnf remove -y valgrind

no-check:autotools:
  extends: .fedora-custom-build@autotools-template
  before_script:
    - dnf remove -y check check-devel

no-doxygen:autotools:
  extends: .fedora-custom-build@autotools-template
  before_script:
    - dnf remove -y doxygen
  variables:
    MAKE_ARGS: ''  # disable distcheck, requires doxygen

# doxygen is required for distcheck
no-doxygen-check-valgrind:autotools:
  extends: .fedora-custom-build@autotools-template
  before_script:
    - dnf remove -y doxygen valgrind check check-devel
  variables:
    MAKE_ARGS: ''  # disable distcheck, requires doxygen

no-nm:autotools:
  extends: .fedora-custom-build@autotools-template
  before_script:
    - mv /usr/bin/nm /usr/bin/nm.moved

enable-gcov:autotools:
  extends: .fedora-custom-build@autotools-template
  variables:
    CONFIGURE_FLAGS: "--enable-gcov"

.fedora-custom-build@meson-template:
  extends: .meson-build@template
  stage: build
  image: $FEDORA_CONTAINER_IMAGE
  variables:
    FEDORA_VERSION: 31
  needs: ['fedora:31@container-prep']

no-valgrind:meson:
  extends: .fedora-custom-build@meson-template
  before_script:
    - dnf remove -y valgrind

no-check:meson:
  extends: .fedora-custom-build@meson-template
  before_script:
    - dnf remove -y check check-devel
  variables:
    MESON_ARGS: -Dtests=disabled
    SKIP_MESON_TEST: 1

# doxygen is required for dist
no-doxygen:meson:
  extends: .fedora-custom-build@meson-template
  before_script:
    - dnf remove -y doxygen
  variables:
    MESON_ARGS: -Ddocumentation=disabled
    NINJA_ARGS: ''

# doxygen is required for dist
no-doxygen-check-valgrind:meson:
  extends: .fedora-custom-build@meson-template
  before_script:
    - dnf remove -y doxygen valgrind check check-devel
  variables:
    MESON_ARGS: -Dtests=disabled -Ddocumentation=disabled
    NINJA_ARGS: ''
    SKIP_MESON_TEST: 1

enable-gcov:meson:
  extends: .fedora-custom-build@meson-template
  variables:
    MESON_ARGS: '-Dcoverity=true'

scan-build:meson:
  extends: .fedora-custom-build@meson-template
  variables:
    NINJA_ARGS: 'scan-build'
    SKIP_MESON_TEST: 1

soname:
  stage: build
  image: $FEDORA_CONTAINER_IMAGE
  script:
  - ./autogen.sh --prefix=$PWD/prefix-autotools/
  - make install
  - ls -l $PWD/prefix-autotools/lib/libevdev.so.2.3.0
  - meson "$MESON_BUILDDIR" --prefix=$PWD/prefix-meson/
  - ninja -C "$MESON_BUILDDIR" install
  - ls -l $PWD/prefix-meson/lib64/libevdev.so.2.3.0
  variables:
    FEDORA_VERSION: 31
  needs: ['fedora:31@container-prep']

#################################################################
#                                                               #
#                          VM stage                             #
#                                                               #
#################################################################

.check_tainted: &check_tainted |
  # make sure the kernel is not tainted
  if [[ "$(ssh localhost -p 5555 cat /proc/sys/kernel/tainted)" -gt 0 ]];
  then
    echo tainted kernel ;
    exit 1 ;
  fi

.qemu@fedora:31:
  stage: VM
  image: $QEMU_CONTAINER_IMAGE
  tags:
    - kvm
  variables:
    FEDORA_VERSION: 31
    MESON_BUILDDIR: build_dir
  script:
    # start our vm, no args required
    - /app/start_vm.sh

    - *check_tainted

    - "scp -P 5555 -r $PWD localhost:"
    - echo "CI_JOB_ID=\"$CI_JOB_ID\"" > sshenv
    - echo "CI_JOB_NAME=\"$CI_JOB_NAME\"" >> sshenv
    - echo "MESON_BUILDDIR=\"$MESON_BUILDDIR\"" >> sshenv
    - echo "MESON_TEST_ARGS=\"$MESON_TEST_ARGS\"" >> sshenv
    - echo "NINJA_ARGS=\"$NINJA_ARGS\"" >> sshenv
    - "scp -P 5555 sshenv localhost:~/$CI_PROJECT_NAME/.meson_environment"
    - ssh localhost -p 5555 "cd $CI_PROJECT_NAME ; .gitlab-ci/meson-build.sh" && touch .success || true
    # no matter the results of the tests, we want to fetch the logs
    - scp -P 5555 -r localhost:$CI_PROJECT_NAME/"$MESON_BUILDDIR" .

    - *check_tainted

    - ssh localhost -p 5555 halt || true
    - sleep 2
    - pkill qemu || true

    - if [[ ! -e .success ]] ;
      then
        exit 1 ;
      fi
  artifacts:
    name: "qemu-meson-logs-$CI_JOB_NAME"
    when: always
    expire_in: 1 week
    paths:
      - $MESON_BUILDDIR/meson-logs
      - console.out
    reports:
      junit: $MESON_BUILDDIR/junit-*.xml

  allow_failure: true
  retry:
    max: 2
    when: script_failure
  needs: ['fedora:31@qemu-prep']

qemu:meson:
  extends: .qemu@fedora:31

qemu:meson:valgrind:
  extends: .qemu@fedora:31
  variables:
    MESON_TEST_ARGS: '--setup=valgrind'

meson-from-tarball:
  stage: tarballs
  image: $FEDORA_CONTAINER_IMAGE
  script:
    - export INSTALLDIR="$PWD/_inst"
    - mkdir _build
    - pushd _build > /dev/null
    - ../autogen.sh --disable-silent-rules $CONFIGURE_FLAGS
    - make
    - make distcheck
    - popd > /dev/null
    - mkdir -p _tarball_dir
    - tar xf _build/libevdev-*.tar.xz -C _tarball_dir
    - pushd _tarball_dir/libevdev-*/ > /dev/null
    - meson "$MESON_BUILDDIR" --prefix="$INSTALLDIR"
    - ninja -C "$MESON_BUILDDIR" test
    - ninja -C "$MESON_BUILDDIR" install
    - popd > /dev/null
    - ls -lR $INSTALLDIR
  variables:
    FEDORA_VERSION: 31
  needs: ['fedora:31@container-prep']

autotools-from-tarball:
  stage: tarballs
  image: $FEDORA_CONTAINER_IMAGE
  script:
    - export INSTALLDIR="$PWD/_inst"
    - meson "$MESON_BUILDDIR"
    - ninja -C "$MESON_BUILDDIR" dist
    - mkdir -p _tarball_dir
    - tar xf "$MESON_BUILDDIR"/meson-dist/libevdev-*.xz -C _tarball_dir
    - pushd _tarball_dir/libevdev-*/ > /dev/null
    - mkdir _build
    - pushd _build > /dev/null
    - ../autogen.sh --disable-silent-rules --prefix="$INSTALLDIR" $CONFIGURE_FLAGS
    - make
    - make install
    - make distcheck
    - popd > /dev/null
    - popd > /dev/null
    - ls -lR $INSTALLDIR
  variables:
    FEDORA_VERSION: 31
  needs: ['fedora:31@container-prep']