1 # vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
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 docker image for each distribution
6 # tested, then run the tests on this docker image.
8 # Creating a docker 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'.
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.
15 # So instead we use a default_build template and override everything with
16 # variables. The only two variables that matter:
17 # MESON_PARAMS=-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
23 # All jobs must follow the naming scheme of
24 # <distribution>:<version>@activity:
25 # e.g. fedora:28@build-default
28 - docker_check # check if the current docker images are up to date
29 - docker_prep # rebuild the docker images if previous step failed
30 - build # for actually building things
33 ###############################################################################
34 # This is the list of packages required to build libinput with the default #
37 # Run dnf install/apt-get install/.. with the list of packages for your #
40 # See the documentation here: #
41 # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html #
42 ###############################################################################
43 FEDORA_RPMS: 'git gcc gcc-c++ meson check-devel libudev-devel libevdev-devel doxygen graphviz valgrind binutils libwacom-devel cairo-devel gtk3-devel glib2-devel mtdev-devel'
44 UBUNTU_DEBS: 'git gcc g++ meson check libudev-dev libevdev-dev doxygen graphviz valgrind binutils libwacom-dev libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev'
45 ############################ end of package lists #############################
46 MESON_BUILDDIR: builddir
49 FEDORA_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/fedora/$FEDORA_VERSION
50 UBUNTU_DOCKER_IMAGE: $CI_REGISTRY/libinput/$CI_PROJECT_NAME/ubuntu/$UBUNTU_VERSION
51 # When using docker-in-docker (dind), it's wise to use the overlayfs driver
52 # for improved performance.
53 DOCKER_DRIVER: overlay2
56 .default_artifacts: &default_artifacts
58 name: "meson-logs-$CI_JOB_NAME"
62 - $MESON_BUILDDIR/meson-logs
64 # The default build instructions
65 .default_build: &default_build
67 - rm -rf $MESON_BUILDDIR
68 - meson $MESON_BUILDDIR $MESON_PARAMS
69 - meson configure $MESON_BUILDDIR
70 - ninja -C $MESON_BUILDDIR $NINJA_ARGS
72 # special rule to not expose the docker creation runners to other users
73 # than those who have set up the CI to push on the registry.
74 # Users who have write access to libinput/libinput will have write
75 # access to the registry, so the libinput/libinput is a catch-all for
76 # our core developers.
78 # we can add as many users as we want by adding a new line like:
79 # - $GITLAB_USER_LOGIN == "someone"
80 .restrict_docker_creation: &restrict_docker_creation
83 # Note: this is a set of logical OR, not AND
84 - $CI_PROJECT_PATH == "libinput/libinput"
86 #################################################################
88 # docker check stage #
90 #################################################################
92 # we need a minimalist image capable of curl, jq, date and test.
93 # instead of using a full fedora and install the dependencies, we
94 # can reuse the one from https://github.com/endeveit/docker-jq with
95 # the following Dockerfile:
97 # MAINTAINER Nikita Vershinin <endeveit@gmail.com>
99 # RUN apk add --update --no-cache curl jq
103 .docker-check: &docker_check
105 image: registry.freedesktop.org/libinput/libinput/jq:latest
107 # get the full docker image name (CURRENT_DOCKER_IMAGE still has indirections)
108 - DOCKER_IMAGE=$(eval echo "$CURRENT_DOCKER_IMAGE")
109 - REPOSITORY=$(echo $DOCKER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
110 - TAG=$(echo $DOCKER_IMAGE | cut -f2 -d:)
112 # request a token for the registry API
113 - REGISTRY_TOKEN=$(curl https://gitlab.freedesktop.org/jwt/auth --get
114 --silent --show-error
116 -d offline_token=true
117 -d service=container_registry
118 -d "scope=repository:$REPOSITORY:pull,*"
120 --user $CI_REGISTRY_USER:$CI_JOB_TOKEN
121 | sed -r 's/(\{"token":"|"\})//g')
123 # get the date of the current image
124 - IMG_DATE=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$TAG --silent
125 -H "accept:application/vnd.docker.distribution.manifest.v1+json"
126 -H "authorization:Bearer $REGISTRY_TOKEN"
127 | jq -r '[.history[]]|map(.v1Compatibility|fromjson|.created)|sort|reverse|.[0]'
130 - TODAY_SECS=$(date -u +%s)
131 - IMG_SECS=$(date -u --date="$IMG_DATE" +%s)
132 - echo "today $TODAY_SECS, image $IMG_SECS"
134 # check if image is less than a week old
135 - test $(($IMG_SECS + 604800)) -gt $TODAY_SECS
137 # export an artefact telling the next stage that the image is valid
140 name: image $CURRENT_DOCKER_IMAGE check
145 <<: *restrict_docker_creation
148 # TODO: check that the RPMS/DEBS are all in the current images
150 fedora:28@docker-check:
154 CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE:latest
157 fedora:27@docker-check:
161 CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE:latest
164 ubuntu:17.10@docker-check:
167 UBUNTU_VERSION: "17.10"
168 CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE:latest
171 ubuntu:18.04@docker-check:
174 UBUNTU_VERSION: "18.04"
175 CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE:latest
179 #################################################################
181 # docker prep stage #
183 #################################################################
186 # This stage will recreate the docker images only if the previous
187 # stage had a build failure, i.e. the image is too old or if it is
188 # missing some dependencies.
190 .fedora@docker-prep: &fedora_docker_prep
195 # if the check was successful, we just skip recreating the docker image
196 - test -e .img_ready && exit 0
198 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
200 # create a Dockerfile with our dependencies
201 - echo "FROM fedora:$FEDORA_VERSION" > Dockerfile
202 - echo "WORKDIR /app" >> Dockerfile
203 - echo "RUN dnf upgrade -y ; dnf clean all" >> Dockerfile
204 - echo "RUN dnf install -y $FEDORA_RPMS ; dnf clean all" >> Dockerfile
206 # create the docker image
207 - docker build --tag $FEDORA_DOCKER_IMAGE:latest --tag $FEDORA_DOCKER_IMAGE:$CI_JOB_ID .
209 # push the docker image to the libinput registry
210 - docker push $FEDORA_DOCKER_IMAGE:latest
211 - docker push $FEDORA_DOCKER_IMAGE:$CI_JOB_ID
212 <<: *restrict_docker_creation
214 fedora:28@docker-prep:
218 <<: *fedora_docker_prep
220 # Note: we can not use $FEDORA_VERSION here
221 - fedora:28@docker-check
223 fedora:27@docker-prep:
227 <<: *fedora_docker_prep
229 # Note: we can not use $FEDORA_VERSION here
230 - fedora:27@docker-check
232 # FIXME: we should clean up the apt cache between each run
233 .ubuntu@docker-prep: &ubuntu_docker_prep
238 # if the check was successful, we just skip recreating the docker image
239 - test -e .img_ready && exit 0
241 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
243 # create a Dockerfile with our dependencies
244 - echo "FROM ubuntu:$UBUNTU_VERSION" > Dockerfile
245 - echo "WORKDIR /app" >> Dockerfile
246 - echo "RUN apt-get update" >> Dockerfile
247 - echo "RUN apt-get install -y software-properties-common" >> Dockerfile
248 - echo "RUN add-apt-repository universe" >> Dockerfile
249 - echo "RUN apt-get update" >> Dockerfile
250 - echo "RUN apt-get install -y $UBUNTU_DEBS" >> Dockerfile
252 # create the docker image
253 - docker build --tag $UBUNTU_DOCKER_IMAGE:latest --tag $UBUNTU_DOCKER_IMAGE:$CI_JOB_ID .
255 # push the docker image to the libinput registry
256 - docker push $UBUNTU_DOCKER_IMAGE:latest
257 - docker push $UBUNTU_DOCKER_IMAGE:$CI_JOB_ID
258 <<: *restrict_docker_creation
260 ubuntu:17.10@docker-prep:
263 UBUNTU_VERSION: "17.10"
264 <<: *ubuntu_docker_prep
266 # Note: we can not use $UBUNTU_VERSION here
267 - ubuntu:17.10@docker-check
269 ubuntu:18.04@docker-prep:
272 UBUNTU_VERSION: "18.04"
273 <<: *ubuntu_docker_prep
275 # Note: we can not use $UBUNTU_VERSION here
276 - ubuntu:18.04@docker-check
278 # Add some manual runners to be able to recreate the cache on a day
279 # the list of the rpms changed
281 fedora:28@force-docker-prep:
285 <<: *fedora_docker_prep
289 fedora:27@force-docker-prep:
293 <<: *fedora_docker_prep
297 ubuntu:17.10@force-docker-prep:
300 UBUNTU_VERSION: "17.10"
301 <<: *ubuntu_docker_prep
305 ubuntu:18.04@force-docker-prep:
308 UBUNTU_VERSION: "18.04"
309 <<: *ubuntu_docker_prep
313 #################################################################
315 # docker clean stage #
316 # run during the check stage #
318 #################################################################
321 # This stage will look for the docker images we currently have in
322 # the registry and will remove any that are not tagged as 'latest'
324 .docker-clean: &docker_clean
326 image: registry.freedesktop.org/libinput/libinput/jq:latest
328 # get the full docker image name (CURRENT_DOCKER_IMAGE still has indirections)
329 - DOCKER_IMAGE=$(eval echo "$CURRENT_DOCKER_IMAGE")
330 - REPOSITORY=$(echo $DOCKER_IMAGE | cut -f2- -d/)
332 # get the r/w token from the settings to access the registry
334 # each developer needs to register a secret variable that contains
335 # a personal token with api access in the form of:
336 # PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
337 - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
338 - token=$(eval echo "\$$tokenname")
340 # request a token for the registry API
341 - REGISTRY_TOKEN=$(curl https://gitlab.freedesktop.org/jwt/auth --get
342 --silent --show-error
344 -d offline_token=true
345 -d service=container_registry
346 -d "scope=repository:$REPOSITORY:pull,*"
348 --user $GITLAB_USER_LOGIN:$token
349 | sed -r 's/(\{"token":"|"\})//g')
351 # get the digest of the latest image
352 - LATEST_MANIFEST=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/latest --silent
353 -H "accept:application/vnd.docker.distribution.manifest.v2+json"
354 -H "authorization:Bearer $REGISTRY_TOKEN"
356 | grep -i "Docker-Content-Digest"
357 | grep -oi "sha256:\w\+")
359 # get the list of tags
360 - TAGS=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/tags/list --silent
361 -H "accept:application/vnd.docker.distribution.manifest.v2+json"
362 -H "authorization:Bearer $REGISTRY_TOKEN"
365 # iterate over the tags
368 MANIFEST=$(curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$tag --silent
369 -H "accept:application/vnd.docker.distribution.manifest.v2+json"
370 -H "authorization:Bearer $REGISTRY_TOKEN"
372 | grep -i "Docker-Content-Digest"
373 | grep -oi "sha256:\w\+");
374 if test x"$MANIFEST" != x"$LATEST_MANIFEST";
376 echo removing $tag as $MANIFEST;
377 curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$MANIFEST --silent
378 -H "accept:application/vnd.docker.distribution.manifest.v2+json"
379 -H "authorization:Bearer $REGISTRY_TOKEN"
380 --fail --show-error -X DELETE
385 <<: *restrict_docker_creation
387 fedora:28@docker-clean:
391 CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE
394 fedora:27@docker-clean:
398 CURRENT_DOCKER_IMAGE: $FEDORA_DOCKER_IMAGE
401 ubuntu:17.10@docker-clean:
404 UBUNTU_VERSION: "17.10"
405 CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE
408 ubuntu:18.04@docker-clean:
411 UBUNTU_VERSION: "18.04"
412 CURRENT_DOCKER_IMAGE: $UBUNTU_DOCKER_IMAGE
415 #################################################################
419 #################################################################
425 .fedora@template: &fedora_template
427 image: $FEDORA_DOCKER_IMAGE:latest
428 <<: *default_artifacts
431 fedora:27@default-build:
437 .fedora:28@template: &fedora_28_template
442 fedora:28@default-build:
443 <<: *fedora_28_template
446 # Below jobs are build option combinations. We only
447 # run them on one image, they shouldn't fail on one distro
448 # when they succeed on another.
450 fedora:28@build-no-libwacom:
451 <<: *fedora_28_template
455 MESON_PARAMS: "-Dlibwacom=false"
457 fedora:28@build-no-libwacom-nodeps:
458 <<: *fedora_28_template
462 MESON_PARAMS: "-Dlibwacom=false"
464 - dnf remove -y libwacom libwacom-devel
466 fedora:28@build-no-docs:
467 <<: *fedora_28_template
471 MESON_PARAMS: "-Ddocumentation=false"
473 fedora:28@build-no-docs-nodeps:
474 <<: *fedora_28_template
478 MESON_PARAMS: "-Ddocumentation=false"
480 - dnf remove -y doxygen graphviz
482 fedora:28@build-no-debuggui:
483 <<: *fedora_28_template
487 MESON_PARAMS: "-Ddebug-gui=false"
489 fedora:28@build-no-debuggui-nodeps:
490 <<: *fedora_28_template
494 MESON_PARAMS: "-Ddebug-gui=false"
496 - dnf remove -y gtk3-devel
498 fedora:28@build-no-tests:
499 <<: *fedora_28_template
503 MESON_PARAMS: "-Dtests=false"
505 fedora:28@build-no-tests-nodeps:
506 <<: *fedora_28_template
510 MESON_PARAMS: "-Dtests=false"
512 - dnf remove -y check-devel
514 fedora:28@scan-build:
515 <<: *fedora_28_template
519 NINJA_ARGS: scan-build
521 - dnf install -y clang-analyzer findutils
523 - test ! -d $MESON_BUILDDIR/meson-logs/scanbuild && exit 0
524 - test $(find $MESON_BUILDDIR/meson-logs/scanbuild -maxdepth 0 ! -empty -exec echo "not empty" \; | wc -l) -eq 0 && exit 0
525 - echo "Check scan-build results"
532 .ubuntu@template: &ubuntu_template
534 image: $UBUNTU_DOCKER_IMAGE:latest
535 <<: *default_artifacts
538 ubuntu:17.10@default-build:
540 UBUNTU_VERSION: "17.10"
544 ubuntu:18.04@default-build:
546 UBUNTU_VERSION: "17.10"