CI: use templates for Ubuntu
[platform/upstream/libinput.git] / .gitlab-ci.yml
1 # vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
2 #
3 # This is a bit complicated for two reasons:
4 # - we really want to run dnf/apt/... only once, updating on the test runner for
5 #   each job takes forever. So we create a container image for each distribution
6 #   tested, then run the tests on this container image.
7 #
8 #   Creating a container image is time-consuming, so we only do so for pushes to
9 #   libinput directly (not merge requests) and if the current image is 'old'.
10 #
11 # - GitLab only allows one script: set per job but we have a bunch of commands
12 #   we need to re-run for each build (meson && ninja && etc). YAML cannot merge
13 #   arrays templates so we're screwed.
14 #
15 #   So instead we use a default_build template and override everything with
16 #   variables. The only two variables that matter:
17 #     MESON_ARGS=-Denable-something=true
18 #     NINJA_ARGS=dist ... to run 'ninja -C builddir dist'
19 #   Note that you cannot use scripts: in any target if you expect default_build
20 #   to work.
21 #
22 #
23 # All jobs must follow the naming scheme of
24 # <distribution>:<version>@activity:
25 #  e.g. fedora:29@build-default
26
27 include:
28   # Arch container builder template
29   - project: 'wayland/ci-templates'
30     ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
31     file: '/templates/arch.yml'
32   # Fedora container builder template
33   - project: 'wayland/ci-templates'
34     ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
35     file: '/templates/fedora.yml'
36   # Ubuntu container builder template
37   - project: 'wayland/ci-templates'
38     ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
39     file: '/templates/ubuntu.yml'
40
41 stages:
42   - container_prep   # rebuild the container images if there is a change
43   - build            # for actually building things
44   - deploy           # trigger wayland's website generation
45   - container_clean  # clean up unused container images
46
47 variables:
48   ###############################################################################
49   # This is the list of packages required to build libinput with the default    #
50   # configuration.                                                              #
51   #                                                                             #
52   # Run dnf install/apt-get install/.. with the list of packages for your       #
53   # distribution                                                                #
54   #                                                                             #
55   # See the documentation here:                                                 #
56   # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html  #
57   ###############################################################################
58   FEDORA_RPMS:        'git gcc gcc-c++ pkgconf-pkg-config meson check-devel libudev-devel libevdev-devel doxygen graphviz python3-sphinx python3-recommonmark                          libwacom-devel cairo-devel   gtk3-devel   glib2-devel    mtdev-devel'
59   UBUNTU_CUSTOM_DEBS: 'git gcc g++     pkg-config         meson check       libudev-dev   libevdev-dev   doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx-rtd-theme libwacom-dev   libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev'
60   ARCH_PKGS:          'git gcc         pkgconfig          meson check       libsystemd    libevdev       doxygen graphviz  python-sphinx  python-recommonmark                          libwacom                     gtk3                        mtdev      diffutils'
61   FREEBSD_BUILD_PKGS: 'meson'
62   FREEBSD_PKGS:       'libepoll-shim                                        libudev-devd  libevdev                                                                                     libwacom                     gtk3                        libmtdev   '
63   ############################ end of package lists #############################
64
65   # these tags should be updated each time the list of packages is updated
66   # changing these will force rebuilding the associated image
67   # Note: these tags have no meaning and are not tied to a particular
68   # libinput version
69   FEDORA_TAG: '2019-03-15.0'
70   UBUNTU_TAG: '2019-03-15.0'
71   ARCH_TAG: '2019-03-15.0'
72   FREEBSD_TAG: '2019-03-15.0'
73
74   UBUNTU_EXEC: "bash .gitlab-ci/ubuntu_install.sh $UBUNTU_CUSTOM_DEBS"
75
76   UPSTREAM_REPO: libinput/libinput
77   BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
78   FEDORA_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$FEDORA_TAG
79   UBUNTU_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$UBUNTU_VERSION:$UBUNTU_TAG
80   ARCH_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/archlinux/rolling:$ARCH_TAG
81   FREEBSD_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/freebsd/11.2:$FREEBSD_TAG
82
83   MESON_BUILDDIR: "build dir"
84   NINJA_ARGS: 'test'
85   MESON_ARGS: ''
86
87   # Until we have a VM with full access, we cannot run the test suite runner
88   SKIP_LIBINPUT_TEST_SUITE_RUNNER: 1
89   # udev isn't available/working properly in the containers
90   UDEV_NOT_AVAILABLE: 1
91   GIT_DEPTH: 1
92
93 .default_artifacts: &default_artifacts
94   artifacts:
95     name: "meson-logs-$CI_JOB_NAME"
96     when: always
97     expire_in: 1 week
98     paths:
99       - $MESON_BUILDDIR/meson-logs
100
101 # The default build instructions
102 .default_build: &default_build
103   script:
104    - rm -rf "$MESON_BUILDDIR"
105    - meson "$MESON_BUILDDIR" $MESON_ARGS
106    - meson configure "$MESON_BUILDDIR"
107    - ninja -C "$MESON_BUILDDIR" $NINJA_ARGS
108
109 #################################################################
110 #                                                               #
111 #                    container prep stage                       #
112 #                                                               #
113 #################################################################
114
115 #
116 # This stage will recreate the container images only if the image
117 # is too old or if it is missing some dependencies.
118 #
119
120 .check_if_older_than_a_week: &check_if_older_than_a_week
121   before_script:
122     # log in to the registry
123     - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
124
125     # get the full container image name (DISTRIB_VERSION still has indirections)
126     - IMAGE=$(eval echo "$DISTRIB_FLAVOR/$DISTRIB_VERSION:$TAG")
127
128     # check if our image is already in the current registry and get its date
129     - LOCAL_IMG_DATE=$(skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE | jq -r '.Created' | cut -dT -f1 ||
130                      echo 1970-01-01)
131
132     # get the date of the upstream image
133     - UPSTREAM_IMG_DATE=$(skopeo inspect docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE | jq -r '.Created' | cut -dT -f1 ||
134                         echo 1970-01-01)
135
136     - TODAY_SECS=$(date -u +%s)
137     - LOCAL_IMG_SECS=$(date -u --date="$LOCAL_IMG_DATE" +%s)
138     - UPSTREAM_IMG_SECS=$(date -u --date="$UPSTREAM_IMG_DATE" +%s)
139     - echo "today $TODAY_SECS, local image $LOCAL_IMG_SECS, upstream image $UPSTREAM_IMG_SECS"
140     - echo "image ages $(($TODAY_SECS - $LOCAL_IMG_SECS))s and $(($TODAY_SECS - $UPSTREAM_IMG_SECS))s"
141
142     # if the upstream image is more recent, use it
143     - if [[ $UPSTREAM_IMG_SECS -gt $LOCAL_IMG_SECS ]] ;
144       then
145         skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE
146                     docker://$CI_REGISTRY_IMAGE/$IMAGE ;
147         LOCAL_IMG_SECS=UPSTREAM_IMG_SECS ;
148       fi
149
150     # check if image is less than a week old
151     - test $(($LOCAL_IMG_SECS + 604800)) -gt $TODAY_SECS && exit 0
152
153
154 fedora:28@container-prep:
155   extends: .fedora@container-build
156   stage: container_prep
157   variables:
158     GIT_STRATEGY: none
159     FEDORA_VERSION: 28
160     DISTRIB_FLAVOR: fedora
161     DISTRIB_VERSION: $FEDORA_VERSION
162     TAG: $FEDORA_TAG
163   <<: *check_if_older_than_a_week
164
165 fedora:29@container-prep:
166   extends: .fedora@container-build
167   stage: container_prep
168   variables:
169     GIT_STRATEGY: none
170     FEDORA_VERSION: 29
171     DISTRIB_FLAVOR: fedora
172     DISTRIB_VERSION: $FEDORA_VERSION
173     TAG: $FEDORA_TAG
174   <<: *check_if_older_than_a_week
175
176
177 ubuntu:18.10@container-prep:
178   extends: .ubuntu@container-build
179   stage: container_prep
180   variables:
181     GIT_STRATEGY: none
182     UBUNTU_VERSION: "18.10"
183     DISTRIB_FLAVOR: ubuntu
184     DISTRIB_VERSION: $UBUNTU_VERSION
185     TAG: $UBUNTU_TAG
186   <<: *check_if_older_than_a_week
187
188 ubuntu:18.04@container-prep:
189   extends: .ubuntu@container-build
190   stage: container_prep
191   variables:
192     GIT_STRATEGY: none
193     UBUNTU_VERSION: "18.04"
194     DISTRIB_FLAVOR: ubuntu
195     DISTRIB_VERSION: $UBUNTU_VERSION
196     TAG: $UBUNTU_TAG
197   <<: *check_if_older_than_a_week
198
199
200 arch:rolling@container-prep:
201   extends: .arch@container-build
202   stage: container_prep
203   variables:
204     GIT_STRATEGY: none
205     ARCH_VERSION: rolling
206     DISTRIB_FLAVOR: archlinux
207     DISTRIB_VERSION: $ARCH_VERSION
208     TAG: $ARCH_TAG
209   <<: *check_if_older_than_a_week
210
211 .freebsd@container-prep:
212   stage: container_prep
213   image: $BUILDAH_IMAGE
214   <<: *check_if_older_than_a_week
215   script:
216     - buildcntr=$(buildah from --quiet  myfreeweb/freebsd-cross:latest)
217     - buildah run $buildcntr apk add --no-cache $FREEBSD_BUILD_PKGS
218     - buildah run $buildcntr pkg -r /freebsd update -f
219     - buildah run $buildcntr pkg -r /freebsd install -y $FREEBSD_PKGS
220     - buildah config --workingdir /app $buildcntr
221     # tag the current container
222     - buildah commit --quiet $buildcntr $FREEBSD_CONTAINER_IMAGE
223     # clean up the working container
224     - buildah rm $buildcntr
225
226     # push the container image to the libinput registry
227     - podman push --quiet $FREEBSD_CONTAINER_IMAGE
228     - skopeo copy docker://$FREEBSD_CONTAINER_IMAGE docker://$CI_REGISTRY_IMAGE/freebsd/$FREEBSD_VERSION:$CI_JOB_ID
229
230 freebsd:11.2@container-prep:
231   extends: .freebsd@container-prep
232   variables:
233     GIT_STRATEGY: none
234     FREEBSD_VERSION: "11.2"
235     DISTRIB_FLAVOR: freebsd
236     DISTRIB_VERSION: $FREEBSD_VERSION
237     TAG: $FREEBSD_TAG
238
239
240 #################################################################
241 #                                                               #
242 #                   container clean stage                       #
243 #                 run during the clean stage                    #
244 #                                                               #
245 #################################################################
246
247 #
248 # This stage will look for the container images we currently have in
249 # the registry and will remove any that are not tagged with the provided
250 # $container_image:$tag
251 #
252 .container-clean:
253   stage: container_clean
254   image: $BUILDAH_IMAGE
255   script:
256     # get the full container image name (CURRENT_CONTAINER_IMAGE still has indirections)
257     - CONTAINER_IMAGE=$(eval echo "$CURRENT_CONTAINER_IMAGE")
258     - GITLAB=$(echo $CI_PROJECT_URL | cut -f3 -d/)
259     - REPOSITORY=$(echo $CONTAINER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
260     - IMAGE_PATH=$(echo $CONTAINER_IMAGE | cut -f1 -d:)
261     - LATEST_TAG=$(echo $CONTAINER_IMAGE | cut -f2 -d:)
262
263     # log in to the registry (read only)
264     - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
265
266     # get the r/w token from the settings to access the registry
267     #
268     # each developer needs to register a secret variable that contains
269     # a personal token with api access in the form of:
270     # PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
271     - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
272     - token=$(eval echo "\$$tokenname")
273
274     # request a token for the registry API
275     - REGISTRY_TOKEN=$(curl https://$GITLAB/jwt/auth --get
276                              --silent --show-error
277                              -d client_id=docker
278                              -d offline_token=true
279                              -d service=container_registry
280                              -d "scope=repository:$REPOSITORY:pull,*"
281                              --fail
282                              --user $GITLAB_USER_LOGIN:$token
283                              | sed -r 's/(\{"token":"|"\})//g')
284
285     # get the digest of the latest image
286     - LATEST_MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.Digest')
287
288     # get the list of tags
289     - TAGS=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.RepoTags[]')
290     # FIXME: is the above command working properly? If not, use below:
291     # - TAGS=$(curl -X GET -H "accept:application/vnd.docker.distribution.manifest.v2+json"
292     #                      -H "authorization:Bearer $REGISTRY_TOKEN"
293     #                      https://$CI_REGISTRY/v2/$REPOSITORY/tags/list | jq -r '.tags[]')
294
295     # iterate over the tags
296     - for tag in $TAGS;
297       do
298         MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$tag | jq -r '.Digest');
299         if test x"$MANIFEST" != x"$LATEST_MANIFEST";
300           then
301             echo removing $tag as $MANIFEST;
302             curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$MANIFEST --silent
303                  -H "accept:application/vnd.docker.distribution.manifest.v2+json"
304                  -H "authorization:Bearer $REGISTRY_TOKEN"
305                  --fail --show-error -X DELETE || true
306           ;fi
307       ;done
308   dependencies: []
309   allow_failure: true
310
311 fedora:28@container-clean:
312   extends: .container-clean
313   variables:
314     GIT_STRATEGY: none
315     FEDORA_VERSION: 28
316     CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
317
318 fedora:29@container-clean:
319   extends: .container-clean
320   variables:
321     GIT_STRATEGY: none
322     FEDORA_VERSION: 29
323     CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
324
325 ubuntu:18.10@container-clean:
326   extends: .container-clean
327   variables:
328     GIT_STRATEGY: none
329     UBUNTU_VERSION: "18.10"
330     CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
331
332 ubuntu:18.04@container-clean:
333   extends: .container-clean
334   variables:
335     GIT_STRATEGY: none
336     UBUNTU_VERSION: "18.04"
337     CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
338
339 arch:rolling@container-clean:
340   extends: .container-clean
341   variables:
342     GIT_STRATEGY: none
343     CURRENT_CONTAINER_IMAGE: $ARCH_CONTAINER_IMAGE
344
345 freebsd:11.2@container-clean:
346   extends: .container-clean
347   variables:
348     GIT_STRATEGY: none
349     CURRENT_CONTAINER_IMAGE: $FREEBSD_CONTAINER_IMAGE
350
351 #################################################################
352 #                                                               #
353 #                       build stage                             #
354 #                                                               #
355 #################################################################
356
357 .build@template:
358   stage: build
359   <<: *default_artifacts
360   <<: *default_build
361   dependencies: []
362
363 #
364 # Fedora
365 #
366
367 .fedora-build@template:
368   extends: .build@template
369   image: $FEDORA_CONTAINER_IMAGE
370
371 fedora:28@default-build:
372   extends: .fedora-build@template
373   variables:
374     FEDORA_VERSION: 28
375
376 fedora:29@default-build:
377   extends: .fedora-build@template
378   variables:
379     FEDORA_VERSION: 29
380
381 fedora:29@default-build-release:
382   extends: .fedora-build@template
383   variables:
384     FEDORA_VERSION: 29
385     MESON_ARGS: "-Dbuildtype=release"
386     CFLAGS: "-Werror"
387
388 fedora:29@scan-build:
389   extends: .fedora-build@template
390   variables:
391     FEDORA_VERSION: 29
392     NINJA_ARGS: scan-build
393   before_script:
394     - dnf install -y clang-analyzer findutils
395   after_script:
396     - test ! -d "$MESON_BUILDDIR"/meson-logs/scanbuild && exit 0
397     - test $(find "$MESON_BUILDDIR"/meson-logs/scanbuild -maxdepth 0 ! -empty -exec echo "not empty" \; | wc -l) -eq 0 && exit 0
398     - echo "Check scan-build results"
399     - /bin/false
400
401 # Below jobs are build option combinations. We only
402 # run them on one image, they shouldn't fail on one distro
403 # when they succeed on another.
404
405 fedora:29@build-no-libwacom:
406   extends: .fedora-build@template
407   variables:
408     FEDORA_VERSION: 29
409     MESON_ARGS: "-Dlibwacom=false"
410
411 fedora:29@build-no-libwacom-nodeps:
412   extends: .fedora-build@template
413   variables:
414     FEDORA_VERSION: 29
415     MESON_ARGS: "-Dlibwacom=false"
416   before_script:
417     - dnf remove -y libwacom libwacom-devel
418
419 fedora:29@build-no-docs:
420   extends: .fedora-build@template
421   variables:
422     FEDORA_VERSION: 29
423     MESON_ARGS: "-Ddocumentation=false"
424
425 fedora:29@build-no-docs-nodeps:
426   extends: .fedora-build@template
427   variables:
428     FEDORA_VERSION: 29
429     MESON_ARGS: "-Ddocumentation=false"
430   before_script:
431     - dnf remove -y doxygen graphviz
432
433 fedora:29@build-no-debuggui:
434   extends: .fedora-build@template
435   variables:
436     FEDORA_VERSION: 29
437     MESON_ARGS: "-Ddebug-gui=false"
438
439 fedora:29@build-no-debuggui-nodeps:
440   extends: .fedora-build@template
441   variables:
442     FEDORA_VERSION: 29
443     MESON_ARGS: "-Ddebug-gui=false"
444   before_script:
445     - dnf remove -y gtk3-devel
446
447 fedora:29@build-no-tests:
448   extends: .fedora-build@template
449   variables:
450     FEDORA_VERSION: 29
451     MESON_ARGS: "-Dtests=false"
452
453 fedora:29@build-no-tests-nodeps:
454   extends: .fedora-build@template
455   variables:
456     FEDORA_VERSION: 29
457     MESON_ARGS: "-Dtests=false"
458   before_script:
459     - dnf remove -y check-devel
460
461 fedora:29@valgrind:
462   extends: .fedora-build@template
463   variables:
464     FEDORA_VERSION: 29
465   before_script:
466     - dnf install -y valgrind
467   # note: we override the default_build here by providing a new script
468   script:
469    - rm -rf "$MESON_BUILDDIR"
470    - meson "$MESON_BUILDDIR" $MESON_ARGS
471    - meson configure "$MESON_BUILDDIR"
472    - meson test -C "$MESON_BUILDDIR" --setup=valgrind
473
474 #
475 # Ubuntu
476 #
477
478 .ubuntu@template:
479   extends: .build@template
480   image: $UBUNTU_CONTAINER_IMAGE
481
482 ubuntu:18.10@default-build:
483   extends: .ubuntu@template
484   variables:
485     UBUNTU_VERSION: "18.10"
486
487 ubuntu:18.04@default-build:
488   extends: .ubuntu@template
489   variables:
490     UBUNTU_VERSION: "18.04"
491
492 #
493 # Arch
494 #
495 .arch@template:
496   extends: .build@template
497   image: $ARCH_CONTAINER_IMAGE
498
499 arch:rolling@default-build:
500   extends: .arch@template
501
502 #
503 # FreeBSD
504 #
505 .freebsd@template:
506   extends: .build@template
507   image: $FREEBSD_CONTAINER_IMAGE
508   variables:
509     MESON_ARGS: '--cross-file freebsd -Ddocumentation=false -Dtests=false -Depoll-dir=/freebsd/usr/local/'
510     # Can't run FreeBSD tests on Linux machine, so NINJA_ARGS shouldn't be "test"
511     NINJA_ARGS: ''
512
513 freebsd:11.2@default-build:
514   extends: .freebsd@template
515
516 #
517 # deploy
518 #
519
520 wayland-web:
521   image: $BUILDAH_IMAGE
522   stage: deploy
523   script:
524     - curl --request POST
525            --form "token=$WAYLAND_WEB_TOKEN"
526            --form ref=master
527            https://gitlab.freedesktop.org/api/v4/projects/wayland${SLASH}wayland${DOT}freedesktop${DOT}org/trigger/pipeline
528   only:
529     refs:
530       - master
531     variables:
532       - $CI_PROJECT_PATH == "libinput/libinput"
533   dependencies: []
534   variables:
535     DOT: "%2E"
536     SLASH: "%2F"