ci: use ci-fairy to generate the template, not a custom script
[platform/upstream/libinput.git] / .gitlab-ci / gitlab-ci.tmpl
1 # vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0 filetype=yaml:
2
3 {# You're looking at the template here, so you can ignore the below
4    warning. This is the right file to edit #}
5 ########################################
6 #                                      #
7 # THIS FILE IS GENERATED, DO NOT EDIT  #
8 #                                      #
9 ########################################
10
11 #
12 # This is a bit complicated for two reasons:
13 # - we really want to run dnf/apt/... only once, updating on the test runner for
14 #   each job takes forever. So we create a container image for each distribution
15 #   tested, then run the tests on this container image.
16 #
17 #   Creating a container image is time-consuming, so we only do so for pushes to
18 #   libinput directly (not merge requests) and if the current image is 'old'.
19 #
20 # - GitLab only allows one script: set per job but we have a bunch of commands
21 #   we need to re-run for each build (meson && ninja && etc). YAML cannot merge
22 #   arrays templates so we're screwed.
23 #
24 #   So instead we use a default_build template and override everything with
25 #   variables. The only two variables that matter:
26 #     MESON_ARGS=-Denable-something=true
27 #     NINJA_ARGS=dist ... to run 'ninja -C builddir dist'
28 #   Note that you cannot use scripts: in any target if you expect default_build
29 #   to work.
30 #
31 #
32 # All jobs must follow the naming scheme of
33 # <distribution>:<version>@activity:
34 #  e.g. fedora:31@build-default
35
36 .templates_sha: &template_sha 395535ce90eb48e260c0dff12c35d9237e22c539 # see https://docs.gitlab.com/ee/ci/yaml/#includefile
37
38 include:
39   {% for distro in distributions|sort(attribute="name") %}
40   {% if distro.ci_templates %}
41   # {{ distro.name.capitalize() }} container builder template
42   - project: 'freedesktop/ci-templates'
43     ref: *template_sha
44     file: '/templates/{{distro.name}}.yml'
45   {% endif %}
46   {% endfor %}
47
48 stages:
49   - prep             # prep work like rebuilding the container images if there is a change
50   - build            # for actually building and testing things in a container
51   - VM               # for running the test suite in a VM
52   - valgrind         # for running the test suite under valgrind in a VM
53   - distro           # distribs test
54   - deploy           # trigger wayland's website generation
55   - container_clean  # clean up unused container images
56
57 variables:
58   ###############################################################################
59   # This is the list of packages required to build libinput with the default    #
60   # configuration.                                                              #
61   #                                                                             #
62   # Run dnf install/apt-get install/.. with the list of packages for your       #
63   # distribution                                                                #
64   #                                                                             #
65   # See the documentation here:                                                 #
66   # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html  #
67   ###############################################################################
68   FEDORA_PACKAGES:    'git gcc gcc-c++ pkgconf-pkg-config meson check-devel libudev-devel libevdev-devel doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx_rtd_theme python3-pytest-xdist libwacom-devel cairo-devel   gtk3-devel   glib2-devel    mtdev-devel diffutils'
69   FEDORA_QEMU_RPMS:   'git gcc gcc-c++ pkgconf-pkg-config meson check-devel libudev-devel libevdev-devel doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx_rtd_theme python3-pytest-xdist libwacom-devel cairo-devel   gtk3-devel   glib2-devel    mtdev-devel diffutils valgrind'
70   UBUNTU_PACKAGES:    'git gcc g++     pkg-config         meson check       libudev-dev   libevdev-dev   doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx-rtd-theme python3-pytest-xdist libwacom-dev   libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev'
71   ARCH_PACKAGES:      'git gcc         pkgconfig          meson check       libsystemd    libevdev       doxygen graphviz python-sphinx  python-recommonmark  python-sphinx_rtd_theme  python-pytest-xdist  libwacom                     gtk3                        mtdev      diffutils'
72   FREEBSD_BUILD_PKGS: 'meson'
73   FREEBSD_PKGS:       'libepoll-shim                                        libudev-devd  libevdev                                                                                     libwacom                     gtk3                        libmtdev   '
74   ALPINE_PACKAGES:    'git gcc build-base pkgconfig       meson check-dev   eudev-dev     libevdev-dev                                                                                 libwacom-dev   cairo-dev     gtk+3.0-dev  mtdev-dev bash'
75   ############################ end of package lists #############################
76
77   # these tags should be updated each time the list of packages is updated
78   # changing these will force rebuilding the associated image
79   # Note: these tags have no meaning and are not tied to a particular
80   # libinput version
81 {% for distro in distributions %}
82   {{"%-13s"| format(distro.name.upper() + '_TAG:')}}'{{distro.tag}}'
83 {% endfor %}
84 {% for distro in distributions %}
85 {% if distro.want_qemu %}
86   QEMU_TAG:    'qemu-vm-{{distro.tag}}'
87 {% endif %}
88 {% endfor %}
89
90   UBUNTU_EXEC: "bash .gitlab-ci/ubuntu_install.sh $UBUNTU_CUSTOM_DEBS"
91
92   FREEBSD_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/freebsd/11.2:$FREEBSD_TAG
93   FDO_UPSTREAM_REPO: libinput/libinput
94
95   MESON_BUILDDIR: "build dir"
96   NINJA_ARGS: ''
97   MESON_ARGS: ''
98   MESON_TEST_ARGS: '--no-suite=hardware'
99
100   # udev isn't available/working properly in the containers
101   UDEV_NOT_AVAILABLE: 1
102   GIT_DEPTH: 1
103
104 .policy:
105   retry:
106     max: 2
107     when:
108       - runner_system_failure
109       - stuck_or_timeout_failure
110   # cancel run when a newer version is pushed to the branch
111   interruptible: true
112
113 .default_artifacts:
114   artifacts:
115     name: "meson-logs-$CI_JOB_NAME"
116     when: always
117     expire_in: 1 week
118     paths:
119       - $MESON_BUILDDIR/meson-logs
120     reports:
121       junit: $MESON_BUILDDIR/junit-*.xml
122
123 #################################################################
124 #                                                               #
125 #                          prep stage                           #
126 #                                                               #
127 #################################################################
128
129 # Re-generate the CI script and make sure it's the one currently checked in
130 # If this job fails, re-generate the gitlab-ci.yml script, see
131 # $SRCDIR/.gitlab-ci/generate-gitlab-ci.py
132 #
133 check-ci-script:
134   image: golang:alpine
135   stage: prep
136   before_script:
137     - apk add python3 git
138     - pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
139   script:
140     - ci-fairy generate-template --config .gitlab-ci/config.yml .gitlab-ci/gitlab-ci.tmpl -o .gitlab-ci.yml
141     - git diff --exit-code && exit 0 || true
142     - echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
143     - exit 1
144
145 #
146 # Verify that commit messages are as expected, signed-off, etc.
147 #
148
149 check-commit:
150   image: golang:alpine
151   stage: prep
152   before_script:
153     - apk add python3 git
154   script:
155     - pip3 install GitPython
156     - pip3 install pytest
157     - |
158       pytest --junitxml=results.xml \
159              --tb=line \
160              --assert=plain \
161              ./.gitlab-ci/check-commit.py
162   except:
163     - master@libinput/libinput
164   variables:
165     GIT_DEPTH: 100
166   artifacts:
167     reports:
168       junit: results.xml
169
170 #
171 # This stage will recreate the container images only if the image
172 # is too old or if it is missing some dependencies.
173 #
174
175 .rebuild_for_schedule:
176   before_script:
177     # force rebuild if schedule, reuse otherwise
178     - if [[ $CI_PIPELINE_SOURCE == "schedule" ]] ; then export FDO_FORCE_REBUILD=1; fi
179
180 fedora:30@qemu-prep:
181   extends:
182     - .fdo.qemu-build@fedora
183     - .policy
184     - .rebuild_for_schedule
185   stage: prep
186   tags:
187     - kvm
188   variables:
189     GIT_STRATEGY: none
190     FDO_DISTRIBUTION_VERSION: 30
191     FDO_DISTRIBUTION_TAG: $QEMU_TAG
192     FDO_DISTRIBUTION_PACKAGES: $FEDORA_QEMU_RPMS
193   allow_failure: true
194
195 {% for distro in distributions %}
196 {% for version in distro.versions %}
197 {{distro.name}}:{{version}}@container-prep:
198   extends:
199     - .fdo.container-build@{{distro.name}}
200     - .policy
201     - .rebuild_for_schedule
202   stage: prep
203   variables:
204     GIT_STRATEGY: none
205     FDO_DISTRIBUTION_VERSION: '{{version}}'
206     FDO_DISTRIBUTION_PACKAGES: ${{distro.name.upper()}}_PACKAGES
207     FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG
208  {% if version == 'ubuntu'%}
209     FDO_DISTRIBUTION_EXEC: $UBUNTU_EXEC
210  {% endif %}
211
212 {% endfor %}
213 {% endfor %}
214
215
216 # Note that we want to use the latest buildah image, and for that
217 # we use one of the .fdo.container-build@distribution by replacing the
218 # `script`.
219 .freebsd@container-prep:
220   extends:
221     - .policy
222     - .fdo.container-build@fedora
223   stage: prep
224   script:
225     # log in to the registry
226     - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
227
228     # get the full container image name
229     - export IMAGE=freebsd/$FREEBSD_VERSION:$FREEBSD_TAG
230
231     # force rebuild if schedule, reuse otherwise
232     - if [[ $CI_PIPELINE_SOURCE == "schedule" ]] ; then touch .scheduled; fi
233
234     # pull the latest upstream image if it exists
235     - test -e .scheduled || skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD
236                                  docker://$CI_REGISTRY/$FDO_UPSTREAM_REPO/$IMAGE
237                                  docker://$CI_REGISTRY_IMAGE/$IMAGE && exit 0 || true ;
238
239     # check if our image is already in the current registry
240     - test -e .scheduled || skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
241
242     - export BUILDAH_RUN="buildah run --isolation chroot"
243     - export BUILDAH_COMMIT="buildah commit --format docker"
244     - buildcntr=$(buildah from --quiet  myfreeweb/freebsd-cross:latest)
245     - $BUILDAH_RUN $buildcntr apk add --no-cache $FREEBSD_BUILD_PKGS
246     - $BUILDAH_RUN $buildcntr pkg -r /freebsd update -f
247     - $BUILDAH_RUN $buildcntr pkg -r /freebsd install -y $FREEBSD_PKGS
248     - buildah config --workingdir /app $buildcntr
249     # tag the current container
250     - $BUILDAH_COMMIT $buildcntr $FREEBSD_CONTAINER_IMAGE
251     # clean up the working container
252     - buildah rm $buildcntr
253
254     # push the container image to the libinput registry
255     - podman push --quiet $FREEBSD_CONTAINER_IMAGE
256     - skopeo copy --dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD
257         docker://$FREEBSD_CONTAINER_IMAGE
258         docker://$CI_REGISTRY_IMAGE/freebsd/$FREEBSD_VERSION:$CI_JOB_ID
259
260 freebsd:11.2@container-prep:
261   extends:
262     - .freebsd@container-prep
263   variables:
264     GIT_STRATEGY: none
265     FREEBSD_VERSION: "11.2"
266
267
268 #################################################################
269 #                                                               #
270 #                   container clean stage                       #
271 #                 run during the clean stage                    #
272 #                                                               #
273 #################################################################
274
275 #
276 # This stage will look for the container images we currently have in
277 # the registry and will remove any that are not tagged with the provided
278 # $container_image:$tag
279 #
280 .container-clean:
281   stage: container_clean
282   extends:
283     - .policy
284   image: golang:alpine
285   before_script:
286     - apk add python3 git
287     - pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
288   script:
289     # Go to your Profile, Settings, Access Tokens
290     # Create a personal token with 'api' scope, copy the value.
291     # Go to CI/CD, Schedules, schedule a new monthly job (or edit the existing one)
292     # Define a variable of type File named AUTHFILE. Content is that token
293     # value.
294     - ci-fairy -v --authfile $AUTHFILE delete-image
295             --repository $FDO_DISTRIBUTION_NAME/$FDO_DISTRIBUTION_VERSION
296             --exclude-tag $FDO_DISTRIBUTION_TAG
297   dependencies: []
298   allow_failure: true
299   only:
300     - schedules
301
302 {% for distro in distributions %}
303 {% for version in distro.versions %}
304 {{distro.name}}:{{version}}@container-clean:
305   extends:
306     - .container-clean
307   variables:
308     GIT_STRATEGY: none
309     {{distro.name.upper()}}_VERSION: '{{version}}'
310     CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/{{distro.name}}/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG
311     FDO_DISTRIBUTION_VERSION: '{{version}}'
312     FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG
313
314 {% endfor %}
315 {% endfor %}
316
317 freebsd:11.2@container-clean:
318   extends:
319     - .container-clean
320   variables:
321     GIT_STRATEGY: none
322     CURRENT_CONTAINER_IMAGE: $FREEBSD_CONTAINER_IMAGE
323
324 #################################################################
325 #                                                               #
326 #                       build stage                             #
327 #                                                               #
328 #################################################################
329
330 .build@template:
331   extends:
332     - .policy
333     - .default_artifacts
334   stage: build
335   script:
336     - .gitlab-ci/meson-build.sh
337   dependencies: []
338
339 #
340 # Fedora
341 #
342
343 .check_tainted: &check_tainted |
344   # make sure the kernel is not tainted
345   if [[ "$(ssh localhost -p 5555 cat /proc/sys/kernel/tainted)" -gt 0 ]];
346   then
347     echo tainted kernel ;
348     exit 1 ;
349   fi
350
351 # Run in a test suite. Special variables:
352 # - SUITES: the meson test suites to run, or
353 # - SUITE_NAMES: all elements will be expanded to libinput-test-suite-$value
354 # Set one or the other, not both.
355 .test-suite-vm:
356   extends:
357     - .policy
358     - .fdo.distribution-image@fedora
359   stage: VM
360   tags:
361     - kvm
362   variables:
363     MESON_BUILDDIR: build_dir
364     # remove the global --no-suite=hardware
365     MESON_TEST_ARGS: ''
366   before_script:
367     - if ! [[ -z $SUITE_NAMES ]]; then SUITES=$(echo $SUITE_NAMES | sed 's/\([^ ]*\)/libinput-test-suite-\1/g'); fi
368     - echo "Testing $SUITES"
369   script:
370     # start our vm, no args required
371     - /app/start_vm.sh || (echo "Error - Failed to start the VM." && exit 1)
372
373     - *check_tainted
374
375     - "scp -P 5555 -r $PWD localhost:"
376     - echo "CI_JOB_ID=\"$CI_JOB_ID\"" > sshenv
377     - echo "CI_JOB_NAME=\"$CI_JOB_NAME\"" >> sshenv
378     - echo "MESON_ARGS=\"$MESON_ARGS\"" >> sshenv
379     - echo "MESON_BUILDDIR=\"$MESON_BUILDDIR\"" >> sshenv
380     - echo "MESON_TEST_ARGS=\"$MESON_TEST_ARGS $SUITES\"" >> sshenv
381     - echo "NINJA_ARGS=\"$NINJA_ARGS\"" >> sshenv
382     - "scp -P 5555 sshenv localhost:~/$CI_PROJECT_NAME/.meson_environment"
383     - ssh localhost -p 5555 "cd $CI_PROJECT_NAME ; .gitlab-ci/meson-build.sh" && touch .success || true
384     # no matter the results of the tests, we want to fetch the logs
385     - scp -P 5555 -r localhost:$CI_PROJECT_NAME/$MESON_BUILDDIR .
386
387     - *check_tainted
388
389     - ssh localhost -p 5555 halt || true
390     - sleep 2
391     - pkill qemu || true
392
393     - if [[ ! -e .success ]] ;
394       then
395         exit 1 ;
396       fi
397   artifacts:
398     name: "qemu-meson-logs-$CI_JOB_NAME"
399     when: always
400     expire_in: 1 week
401     paths:
402       - $MESON_BUILDDIR/meson-logs
403       - console.out
404     reports:
405       junit: $MESON_BUILDDIR/junit-*.xml
406
407   allow_failure: true
408   retry:
409     max: 2
410     when: script_failure
411
412
413 .fedora:30@test-suite-vm:
414   extends:
415     - .test-suite-vm
416   variables:
417     FDO_DISTRIBUTION_VERSION: 30
418     FDO_DISTRIBUTION_TAG: $QEMU_TAG
419   needs: ['fedora:30@qemu-prep']
420
421
422 {% for suite in test_suites %}
423 vm-{{suite.name}}:
424   extends:
425     - .fedora:30@test-suite-vm
426   variables:
427     SUITE_NAMES: '{{suite.suites}}'
428
429 vm-{{suite.name}}-no-libwacom:
430   extends:
431     - vm-{{suite.name}}
432   variables:
433     MESON_ARGS: '-Dlibwacom=false'
434
435 {% endfor %}
436
437 {% for suite in test_suites %}
438 vm-valgrind-{{suite.name}}:
439   stage: valgrind
440   extends:
441     - vm-{{suite.name}}
442   variables:
443     MESON_TEST_ARGS: '--setup=valgrind'
444
445 {% endfor %}
446
447
448 .fedora-build@template:
449   extends:
450     - .fdo.distribution-image@fedora
451     - .build@template
452   variables:
453     FDO_DISTRIBUTION_VERSION: '30'
454     FDO_DISTRIBUTION_TAG: $FEDORA_TAG
455   needs: ['fedora:30@container-prep']
456
457 default-build-release@fedora:30:
458   stage: distro
459   extends:
460     - .fedora-build@template
461   variables:
462     MESON_ARGS: "-Dbuildtype=release"
463     CFLAGS: "-Werror"
464
465 scan-build@fedora:30:
466   extends:
467     - .fedora-build@template
468   variables:
469     NINJA_ARGS: scan-build
470     MESON_TEST_ARGS: ''
471   before_script:
472     - dnf install -y clang-analyzer findutils
473   after_script:
474     - test ! -d "$MESON_BUILDDIR"/meson-logs/scanbuild && exit 0
475     - test $(find "$MESON_BUILDDIR"/meson-logs/scanbuild -maxdepth 0 ! -empty -exec echo "not empty" \; | wc -l) -eq 0 && exit 0
476     - echo "Check scan-build results"
477     - /bin/false
478
479 # Below jobs are build option combinations. We only
480 # run them on one image, they shouldn't fail on one distro
481 # when they succeed on another.
482
483 build-no-libwacom@fedora:30:
484   extends:
485     - .fedora-build@template
486   variables:
487     MESON_ARGS: "-Dlibwacom=false"
488
489 build-no-libwacom-nodeps@fedora:30:
490   extends:
491     - .fedora-build@template
492   variables:
493     MESON_ARGS: "-Dlibwacom=false"
494   before_script:
495     - dnf remove -y libwacom libwacom-devel
496
497 build-no-docs@fedora:30:
498   extends:
499     - .fedora-build@template
500   variables:
501     MESON_ARGS: "-Ddocumentation=false"
502
503 build-no-docs-nodeps@fedora:30:
504   extends:
505     - .fedora-build@template
506   variables:
507     MESON_ARGS: "-Ddocumentation=false"
508   before_script:
509     - dnf remove -y doxygen graphviz
510
511 build-no-debuggui@fedora:30:
512   extends:
513     - .fedora-build@template
514   variables:
515     MESON_ARGS: "-Ddebug-gui=false"
516
517 build-no-debuggui-nodeps@fedora:30:
518   extends:
519     - .fedora-build@template
520   variables:
521     MESON_ARGS: "-Ddebug-gui=false"
522   before_script:
523     - dnf remove -y gtk3-devel
524
525 build-no-tests@fedora:30:
526   extends:
527     - .fedora-build@template
528   variables:
529     MESON_ARGS: "-Dtests=false"
530
531 build-no-tests-nodeps@fedora:30:
532   extends:
533     - .fedora-build@template
534   variables:
535     MESON_ARGS: "-Dtests=false"
536   before_script:
537     - dnf remove -y check-devel
538
539 valgrind@fedora:30:
540   extends:
541     - .fedora-build@template
542   variables:
543     MESON_TEST_ARGS: '--suite=valgrind --no-suite=hardware --setup=valgrind'
544   before_script:
545     - dnf install -y valgrind
546
547 # Python checks, only run on Fedora
548
549 usr-bin-env-python@fedora:30:
550   extends:
551     - .fedora-build@template
552   script:
553     - |
554       if git grep -l '^#!/usr/bin/python'; then
555         echo "Use '/usr/bin/env python3' in the above files";
556         /bin/false
557       fi
558
559 flake8@fedora:30:
560   extends:
561     - .fedora-build@template
562   before_script:
563     - dnf install -y python3-flake8
564   script:
565     - flake8-3 --ignore=W501,E501,W504 $(git grep -l '^#!/usr/bin/env python3')
566
567 #################################################################
568 #                                                               #
569 #                        distro stage                           #
570 #                                                               #
571 #################################################################
572
573 {% for distro in distributions %}
574 {% for version in distro.versions %}
575 {{distro.name}}:{{version}}@default-build:
576   stage: distro
577   extends:
578     - .build@template
579     - .fdo.distribution-image@{{distro.name}}
580   variables:
581     FDO_DISTRIBUTION_VERSION: '{{version}}'
582     FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG
583     {# Where we have extra_variables defined, add them to the list #}
584     {% if distro.build is defined and distro.build.extra_variables is defined %}
585     {% for var in distro.build.extra_variables %}
586     {{var}}
587     {% endfor %}
588     {% endif %}
589   needs: ['{{distro.name}}:{{version}}@container-prep']
590
591
592 {% endfor %}
593 {% endfor %}
594
595 #
596 # FreeBSD
597 #
598 .freebsd@template:
599   stage: distro
600   extends:
601     - .build@template
602   image: $FREEBSD_CONTAINER_IMAGE
603   variables:
604     MESON_ARGS: '--cross-file freebsd -Ddocumentation=false -Dtests=false -Depoll-dir=/freebsd/usr/local/'
605     # Can't run FreeBSD tests on Linux machine, so MESON_TEST_ARGS shouldn't be "test"
606     MESON_TEST_ARGS: ''
607
608 freebsd:11.2@default-build:
609   extends:
610     - .freebsd@template
611   needs: ['freebsd:11.2@container-prep']
612
613 #
614 # deploy
615 #
616
617 wayland-web:
618   image: alpine:latest
619   stage: deploy
620   script:
621     - apk add curl
622     # Requirements:
623     # - variable WAYLAND_WEB_TOKEN defined as type File in libinput's CI/CD settings
624     # - content of that file is the token value, as generated by the Pipeline Triggers
625     #   of the wayland.freedesktop.org project.
626     - curl --request POST
627            --form "token=<$WAYLAND_WEB_TOKEN"
628            --form ref=master
629            https://gitlab.freedesktop.org/api/v4/projects/wayland${SLASH}wayland${DOT}freedesktop${DOT}org/trigger/pipeline
630   except:
631     refs:
632       - schedules
633   only:
634     refs:
635       - master
636     variables:
637       - $CI_PROJECT_PATH == "libinput/libinput"
638   dependencies: []
639   variables:
640     DOT: "%2E"
641     SLASH: "%2F"
642