summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 315aae2e85ef08f9b88151cd5d8b396e82a02dc8 (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
# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
#
# This is a bit complicated for two reasons:
# - we really want to run dnf/apt/... only once, updating on the test runner for
#   each job takes forever. So we create a docker image for each distribution
#   tested, then run the tests on this docker image.
#
#   Creating a docker image is time-consuming, so we only do so for pushes to
#   libinput directly (not merge requests) and if the current image is 'old'.
#
# - GitLab only allows one script: set per job but we have a bunch of commands
#   we need to re-run for each build (meson && ninja && etc). YAML cannot merge
#   arrays templates so we're screwed.
#
#   So instead we use a default_build template and override everything with
#   variables. The only two variables that matter:
#     MESON_ARGS=-Denable-something=true
#     NINJA_ARGS=dist ... to run 'ninja -C builddir dist'
#   Note that you cannot use scripts: in any target if you expect default_build
#   to work.
#
#
# All jobs must follow the naming scheme of
# <distribution>:<version>@activity:
#  e.g. fedora:28@build-default

stages:
  - docker_check  # check if the current docker images are up to date
  - docker_prep   # rebuild the docker images if previous step failed
  - build         # for actually building things
  - deploy        # trigger wayland's website generation

variables:
  ###############################################################################
  # This is the list of packages required to build libinput with the default    #
  # configuration.                                                              #
  #                                                                             #
  # Run dnf install/apt-get install/.. with the list of packages for your       #
  # distribution                                                                #
  #                                                                             #
  # See the documentation here:                                                 #
  # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html  #
  ###############################################################################
  FEDORA_RPMS: 'git gcc gcc-c++ pkgconf-pkg-config meson check-devel libudev-devel libevdev-devel doxygen graphviz valgrind binutils libwacom-devel cairo-devel   gtk3-devel   glib2-devel    mtdev-devel'
  UBUNTU_DEBS: 'git gcc g++     pkg-config         meson check       libudev-dev   libevdev-dev   doxygen graphviz valgrind binutils libwacom-dev   libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev'
  ARCH_PKGS:   'git gcc         pkgconfig          meson check       libsystemd    libevdev       doxygen graphviz valgrind binutils libwacom                     gtk3                        mtdev      '
  FREEBSD_BUILD_PKGS: 'meson'
  FREEBSD_PKGS: 'libepoll-shim                                       libudev-devd  libevdev                                          libwacom                     gtk3                        libmtdev   '
  ############################ end of package lists #############################
  MESON_BUILDDIR: "build dir"
  NINJA_ARGS: 'test'
  MESON_ARGS: ''
  FEDORA_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/fedora/$FEDORA_VERSION
  UBUNTU_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/ubuntu/$UBUNTU_VERSION
  ARCH_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/arch/rolling
  FREEBSD_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/freebsd/11.2
  # Until we have a VM with full access, we cannot run the test suite runner
  SKIP_LIBINPUT_TEST_SUITE_RUNNER: 1
  # When using docker-in-docker (dind), it's wise to use the overlayfs driver
  # for improved performance.
  DOCKER_DRIVER: overlay2
  GIT_DEPTH: 1

.default_artifacts: &default_artifacts
  artifacts:
    name: "meson-logs-$CI_JOB_NAME"
    when: always
    expire_in: 1 week
    paths:
      - $MESON_BUILDDIR/meson-logs

# The default build instructions
.default_build: &default_build
  script:
   - rm -rf "$MESON_BUILDDIR"
   - meson "$MESON_BUILDDIR" $MESON_ARGS
   - meson configure "$MESON_BUILDDIR"
   - ninja -C "$MESON_BUILDDIR" $NINJA_ARGS

# special rule to not expose the docker creation runners to other users
# than those who have set up the CI to push on the registry.
# Users who have write access to libinput/libinput will have write
# access to the registry, so the libinput/libinput is a catch-all for
# our core developers.
#
# we can add as many users as we want by adding a new line like:
#   - $GITLAB_USER_LOGIN == "someone"
.restrict_docker_creation: &restrict_docker_creation
  only:
    variables:
      # Note: this is a set of logical OR, not AND
      - $CI_PROJECT_PATH == "libinput/libinput"

#################################################################
#                                                               #
#                     docker check stage                        #
#                                                               #
#################################################################

# we need a minimalist image capable of curl, jq, date and test.
# instead of using a full fedora and install the dependencies, we
# can reuse the one from https://github.com/endeveit/docker-jq with
# the following Dockerfile:
#   FROM alpine
#   MAINTAINER Nikita Vershinin <endeveit@gmail.com>
#
#   RUN apk add --update --no-cache curl jq
#
#   CMD ["sh"]

.docker-check: &docker_check
  stage: docker_check
  image: registry.freedesktop.org/libinput/libinput/jq:latest
  script:
    # get the full docker image name (CURRENT_DOCKER_IMAGE still has indirections)
    - DOCKER_IMAGE=$(eval echo "$CURRENT_DOCKER_IMAGE")
    - REPOSITORY=$(echo $DOCKER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
    - TAG=$(echo $DOCKER_IMAGE | cut -f2 -d:)

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

    # get the date of the current image
    - IMG_DATE=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$TAG --silent
                      -H "accept:application/vnd.docker.distribution.manifest.v1+json"
                      -H "authorization:Bearer $REGISTRY_TOKEN"
                      | jq -r '[.history[]]|map(.v1Compatibility|fromjson|.created)|sort|reverse|.[0]'
                      | cut -dT -f1)

    - TODAY_SECS=$(date -u +%s)
    - IMG_SECS=$(date -u --date="$IMG_DATE" +%s)
    - echo "today $TODAY_SECS, image $IMG_SECS"

    # check if image is less than a week old
    - test $(($IMG_SECS + 604800)) -gt $TODAY_SECS

    # export an artefact telling the next stage that the image is valid
    - touch .img_ready
  artifacts:
    name: image-$CURRENT_DOCKER_IMAGE-check
    expire_in: 20 min
    paths:
      - .img_ready
  allow_failure: true
  <<: *restrict_docker_creation


# TODO: check that the RPMS/DEBS are all in the current images

fedora:28@docker-check:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 28
    CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE:latest
  <<: *docker_check

fedora:27@docker-check:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 27
    CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE:latest
  <<: *docker_check

ubuntu:17.10@docker-check:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "17.10"
    CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE:latest
  <<: *docker_check

ubuntu:18.04@docker-check:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "18.04"
    CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE:latest
  <<: *docker_check

arch:rolling@docker-check:
  variables:
    GIT_STRATEGY: none
    CURRENT_DOCKER_IMAGE: $ARCH_DOCKER_IMAGE:latest
  <<: *docker_check

freebsd:11.2@docker-check:
  variables:
    GIT_STRATEGY: none
    CURRENT_DOCKER_IMAGE: $FREEBSD_DOCKER_IMAGE:latest
  <<: *docker_check

#################################################################
#                                                               #
#                     docker prep stage                         #
#                                                               #
#################################################################

#
# This stage will recreate the docker images only if the previous
# stage had a build failure, i.e. the image is too old or if it is
# missing some dependencies.
#
.fedora@docker-prep: &fedora_docker_prep
  stage: docker_prep
  services:
    - docker:dind
  script:
    # if the check was successful, we just skip recreating the docker image
    - test -e .img_ready && exit 0

    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # create a Dockerfile with our dependencies
    - echo "FROM fedora:$FEDORA_VERSION" > Dockerfile
    - echo "WORKDIR /app" >> Dockerfile
    - echo "RUN dnf upgrade -y ; dnf clean all" >> Dockerfile
    - echo "RUN dnf install -y $FEDORA_RPMS ; dnf clean all" >> Dockerfile

    # create the docker image
    - docker build --tag $FEDORA_DOCKER_IMAGE:latest --tag $FEDORA_DOCKER_IMAGE:$CI_JOB_ID .

    # push the docker image to the libinput registry
    - docker push $FEDORA_DOCKER_IMAGE:latest
    - docker push $FEDORA_DOCKER_IMAGE:$CI_JOB_ID
  <<: *restrict_docker_creation

fedora:28@docker-prep:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 28
  <<: *fedora_docker_prep
  dependencies:
    # Note: we can not use $FEDORA_VERSION here
    - fedora:28@docker-check

fedora:27@docker-prep:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 27
  <<: *fedora_docker_prep
  dependencies:
    # Note: we can not use $FEDORA_VERSION here
    - fedora:27@docker-check

# FIXME: we should clean up the apt cache between each run
.ubuntu@docker-prep: &ubuntu_docker_prep
  stage: docker_prep
  services:
    - docker:dind
  script:
    # if the check was successful, we just skip recreating the docker image
    - test -e .img_ready && exit 0

    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # create a Dockerfile with our dependencies
    - echo "FROM ubuntu:$UBUNTU_VERSION" > Dockerfile
    - echo "WORKDIR /app" >> Dockerfile
    - echo "RUN apt-get update" >> Dockerfile
    - echo "RUN apt-get install -y software-properties-common" >> Dockerfile
    - echo "RUN add-apt-repository universe" >> Dockerfile
    - echo "RUN apt-get update" >> Dockerfile
    - echo "RUN apt-get install -y $UBUNTU_DEBS" >> Dockerfile

    # create the docker image
    - docker build --tag $UBUNTU_DOCKER_IMAGE:latest --tag $UBUNTU_DOCKER_IMAGE:$CI_JOB_ID .

    # push the docker image to the libinput registry
    - docker push $UBUNTU_DOCKER_IMAGE:latest
    - docker push $UBUNTU_DOCKER_IMAGE:$CI_JOB_ID
  <<: *restrict_docker_creation

ubuntu:17.10@docker-prep:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "17.10"
  <<: *ubuntu_docker_prep
  dependencies:
    # Note: we can not use $UBUNTU_VERSION here
    - ubuntu:17.10@docker-check

ubuntu:18.04@docker-prep:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "18.04"
  <<: *ubuntu_docker_prep
  dependencies:
    # Note: we can not use $UBUNTU_VERSION here
    - ubuntu:18.04@docker-check

.arch@docker-prep: &arch_docker_prep
  stage: docker_prep
  services:
    - docker:dind
  script:
    # if the check was successful, we just skip recreating the docker image
    - test -e .img_ready && exit 0

    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # create a Dockerfile with our dependencies
    - echo "FROM base/archlinux" > Dockerfile
    - echo "WORKDIR /app" >> Dockerfile
    - echo "RUN pacman -S --refresh; pacman -S --sysupgrade --noconfirm; pacman -S --clean --noconfirm" >> Dockerfile
    - echo "RUN pacman -S --noconfirm $ARCH_PKGS; pacman -S --clean --noconfirm" >> Dockerfile

    # create the docker image
    - docker build --tag $ARCH_DOCKER_IMAGE:latest --tag $ARCH_DOCKER_IMAGE:$CI_JOB_ID .

    # push the docker image to the libinput registry
    - docker push $ARCH_DOCKER_IMAGE:latest
    - docker push $ARCH_DOCKER_IMAGE:$CI_JOB_ID
  <<: *restrict_docker_creation

arch:rolling@docker-prep:
  variables:
    GIT_STRATEGY: none
  <<: *arch_docker_prep
  dependencies:
    - arch:rolling@docker-check

.freebsd@docker-prep: &freebsd_docker_prep
  stage: docker_prep
  services:
    - docker:dind
  script:
    # if the check was successful, we just skip recreating the docker image
    - test -e .img_ready && exit 0

    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

    # create a Dockerfile with our dependencies
    - echo "FROM myfreeweb/freebsd-cross:latest" > Dockerfile
    - echo "WORKDIR /app" >> Dockerfile
    - echo "RUN apk add --no-cache $FREEBSD_BUILD_PKGS" >> Dockerfile
    - echo "RUN pkg -r /freebsd install -y $FREEBSD_PKGS" >> Dockerfile

    # create the docker image
    - docker build --tag $FREEBSD_DOCKER_IMAGE:latest --tag $FREEBSD_DOCKER_IMAGE:$CI_JOB_ID .

    # push the docker image to the libinput registry
    - docker push $FREEBSD_DOCKER_IMAGE:latest
    - docker push $FREEBSD_DOCKER_IMAGE:$CI_JOB_ID
  <<: *restrict_docker_creation

freebsd:11.2@docker-prep:
  variables:
    GIT_STRATEGY: none
  <<: *freebsd_docker_prep
  dependencies:
    # Note: we can not use $FREEBSD_VERSION here
    - freebsd:11.2@docker-check

# Add some manual runners to be able to recreate the cache on a day
# the list of the rpms changed

fedora:28@force-docker-prep:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 28
  <<: *fedora_docker_prep
  when: manual
  dependencies: []

fedora:27@force-docker-prep:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 27
  <<: *fedora_docker_prep
  when: manual
  dependencies: []

ubuntu:17.10@force-docker-prep:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "17.10"
  <<: *ubuntu_docker_prep
  when: manual
  dependencies: []

ubuntu:18.04@force-docker-prep:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "18.04"
  <<: *ubuntu_docker_prep
  when: manual
  dependencies: []

arch:rolling@force-docker-prep:
  variables:
    GIT_STRATEGY: none
  <<: *arch_docker_prep
  when: manual
  dependencies: []

freebsd:11.2@force-docker-prep:
  variables:
    GIT_STRATEGY: none
  <<: *freebsd_docker_prep
  when: manual
  dependencies: []

#################################################################
#                                                               #
#                     docker clean stage                        #
#                 run during the check stage                    #
#                                                               #
#################################################################

#
# This stage will look for the docker images we currently have in
# the registry and will remove any that are not tagged as 'latest'
#
.docker-clean: &docker_clean
  stage: docker_check
  image: registry.freedesktop.org/libinput/libinput/jq:latest
  script:
    # get the full docker image name (CURRENT_DOCKER_IMAGE still has indirections)
    - DOCKER_IMAGE=$(eval echo "$CURRENT_DOCKER_IMAGE")
    - REPOSITORY=$(echo $DOCKER_IMAGE | cut -f2- -d/)

    # 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 in the form of:
    # PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
    - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
    - token=$(eval echo "\$$tokenname")

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

    # get the digest of the latest image
    - LATEST_MANIFEST=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/latest --silent
                             -H "accept:application/vnd.docker.distribution.manifest.v2+json"
                             -H "authorization:Bearer $REGISTRY_TOKEN"
                             --head
                             | grep -i "Docker-Content-Digest"
                             | grep -oi "sha256:\w\+")

    # get the list of tags
    - TAGS=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/tags/list --silent
                  -H "accept:application/vnd.docker.distribution.manifest.v2+json"
                  -H "authorization:Bearer $REGISTRY_TOKEN"
                  | jq -r '.tags[]')

    # iterate over the tags
    - for tag in $TAGS;
      do
        MANIFEST=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$tag --silent
                             -H "accept:application/vnd.docker.distribution.manifest.v2+json"
                             -H "authorization:Bearer $REGISTRY_TOKEN"
                             --head
                             | grep -i "Docker-Content-Digest"
                             | grep -oi "sha256:\w\+");
        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
          ;fi
      ;done
  dependencies: []
  allow_failure: true
  <<: *restrict_docker_creation

fedora:28@docker-clean:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 28
    CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE
  <<: *docker_clean

fedora:27@docker-clean:
  variables:
    GIT_STRATEGY: none
    FEDORA_VERSION: 27
    CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE
  <<: *docker_clean

ubuntu:17.10@docker-clean:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "17.10"
    CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE
  <<: *docker_clean

ubuntu:18.04@docker-clean:
  variables:
    GIT_STRATEGY: none
    UBUNTU_VERSION: "18.04"
    CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE
  <<: *docker_clean

arch:rolling@docker-clean:
  variables:
    GIT_STRATEGY: none
    CURRENT_DOCKER_IMAGE: $ARCH_DOCKER_IMAGE
  <<: *docker_clean

freebsd:11.2@docker-clean:
  variables:
    GIT_STRATEGY: none
    CURRENT_DOCKER_IMAGE: $FREEBSD_DOCKER_IMAGE
  <<: *docker_clean

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

#
# Fedora
#

.fedora@template: &fedora_template
  stage: build
  image: $FEDORA_DOCKER_IMAGE:latest
  <<: *default_artifacts
  dependencies: []

fedora:27@default-build:
  variables:
    FEDORA_VERSION: 27
  <<: *fedora_template
  <<: *default_build

.fedora:28@template: &fedora_28_template
  variables:
    FEDORA_VERSION: 28
  <<: *fedora_template

fedora:28@default-build:
  <<: *fedora_28_template
  <<: *default_build

fedora:28@default-build-release:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Dbuildtype=release"
    CFLAGS: "-Werror"

fedora:28@scan-build:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    NINJA_ARGS: scan-build
  before_script:
    - dnf install -y clang-analyzer findutils
  after_script:
    - test ! -d "$MESON_BUILDDIR"/meson-logs/scanbuild && exit 0
    - test $(find "$MESON_BUILDDIR"/meson-logs/scanbuild -maxdepth 0 ! -empty -exec echo "not empty" \; | wc -l) -eq 0 && exit 0
    - echo "Check scan-build results"
    - /bin/false

# Below jobs are build option combinations. We only
# run them on one image, they shouldn't fail on one distro
# when they succeed on another.

fedora:28@build-no-libwacom:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Dlibwacom=false"

fedora:28@build-no-libwacom-nodeps:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Dlibwacom=false"
  before_script:
    - dnf remove -y libwacom libwacom-devel

fedora:28@build-no-docs:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Ddocumentation=false"

fedora:28@build-no-docs-nodeps:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Ddocumentation=false"
  before_script:
    - dnf remove -y doxygen graphviz

fedora:28@build-no-debuggui:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Ddebug-gui=false"

fedora:28@build-no-debuggui-nodeps:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Ddebug-gui=false"
  before_script:
    - dnf remove -y gtk3-devel

fedora:28@build-no-tests:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Dtests=false"

fedora:28@build-no-tests-nodeps:
  <<: *fedora_28_template
  <<: *default_build
  variables:
    FEDORA_VERSION: 28
    MESON_ARGS: "-Dtests=false"
  before_script:
    - dnf remove -y check-devel

fedora:28@valgrind:
  <<: *fedora_28_template
  variables:
    FEDORA_VERSION: 28
  script:
   - rm -rf "$MESON_BUILDDIR"
   - meson "$MESON_BUILDDIR" $MESON_ARGS
   - meson configure "$MESON_BUILDDIR"
   - meson test -C "$MESON_BUILDDIR" --setup=valgrind

#
# Ubuntu
#

.ubuntu@template: &ubuntu_template
  stage: build
  image: $UBUNTU_DOCKER_IMAGE:latest
  <<: *default_artifacts
  dependencies: []

ubuntu:17.10@default-build:
  variables:
    UBUNTU_VERSION: "17.10"
  <<: *ubuntu_template
  <<: *default_build

ubuntu:18.04@default-build:
  variables:
    UBUNTU_VERSION: "17.10"
  <<: *ubuntu_template
  <<: *default_build

#
# Arch
#
.arch@template: &arch_template
  stage: build
  image: $ARCH_DOCKER_IMAGE:latest
  <<: *default_artifacts
  dependencies: []

arch:rolling@default-build:
  <<: *arch_template
  <<: *default_build

#
# FreeBSD
#
.freebsd@template: &freebsd_template
  stage: build
  image: $FREEBSD_DOCKER_IMAGE:latest
  variables:
    MESON_ARGS: '--cross-file freebsd -Ddocumentation=false -Dtests=false -Depoll-dir=/freebsd/usr/local/'
    # Can't run FreeBSD tests on Linux machine, so NINJA_ARGS shouldn't be "test"
    NINJA_ARGS: ''
  <<: *default_artifacts
  dependencies: []

freebsd:11.2@default-build:
  <<: *freebsd_template
  <<: *default_build

#
# deploy
#

wayland-web:
  image: registry.freedesktop.org/libinput/libinput/jq:latest
  stage: deploy
  script:
    - curl --request POST
           --form "token=$WAYLAND_WEB_TOKEN"
           --form ref=master
           https://gitlab.freedesktop.org/api/v4/projects/wayland${SLASH}wayland${DOT}freedesktop${DOT}org/trigger/pipeline
  only:
    refs:
      - master
    variables:
      - $CI_PROJECT_PATH == "libinput/libinput"
  dependencies:
  variables:
    DOT: "%2E"
    SLASH: "%2F"