gitlab CI: expire the results.xml artifacts
[platform/upstream/libevdev.git] / .gitlab-ci / gitlab-ci.tmpl
1 {# You're looking at the template here, so you can ignore the below
2    warning. This is the right file to edit #}
3 ########################################
4 #                                      #
5 # THIS FILE IS GENERATED, DO NOT EDIT  #
6 #                                      #
7 ########################################
8
9 .templates_sha: &template_sha 8410d3382c4ba5e83da76a027cb332169f2a95ad # see https://docs.gitlab.com/ee/ci/yaml/#includefile
10
11 include:
12   {% for distribution in distributions|map(attribute='name')|unique()|sort() %}
13   # {{ distribution.capitalize() }} container builder template
14   - project: 'wayland/ci-templates'
15     ref: *template_sha
16     file: '/templates/{{distribution}}.yml'
17   {% endfor %}
18
19 stages:
20   - prep             # rebuild the container images if there is a change
21   - build            # for actually building and testing things in a container
22   - VM               # for running the test suite in a VM
23   - autotools        # distribution builds with autotools
24   - meson            # distribution builds with meson
25   - tarballs         # tarball builds
26   - container_clean  # clean up unused container images
27
28 variables:
29   ###############################################################################
30   # This is the list of packages required to build libevdev with the default    #
31   # configuration.                                                              #
32   #                                                                             #
33   # Run dnf install/apt-get install/.. with the list of packages for your       #
34   # distribution                                                                #
35   ###############################################################################
36   FEDORA_RPMS: 'git gcc gcc-c++ meson automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils doxygen xz clang-analyzer'
37   CENTOS_RPMS: 'git gcc gcc-c++       automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils xz'
38   UBUNTU_DEBS: 'git gcc g++     meson automake autoconf libtool make pkg-config python3 check       valgrind binutils doxygen xz-utils'
39   DEBIAN_DEBS: $UBUNTU_DEBS
40   ARCH_PKGS:   'git gcc         meson automake autoconf libtool make pkgconfig  python3 check       valgrind binutils doxygen'
41   ALPINE_PKGS: 'git gcc g++     meson automake autoconf libtool make pkgconfig  python3 check-dev   valgrind binutils doxygen xz linux-headers'
42   ############################ end of package lists #############################
43   # these tags should be updated each time the list of packages is updated
44   # changing these will force rebuilding the associated image
45   # Note: these tags have no meaning and are not tied to a particular
46   # libevdev version
47   FEDORA_TAG: '2020-02-26.4'
48   CENTOS_TAG: '2020-02-26.4'
49   DEBIAN_TAG: '2020-02-26.4'
50   UBUNTU_TAG: '2020-02-26.4'
51   ARCH_TAG:   '2020-02-26.4'
52   ALPINE_TAG: '2020-02-26.4'
53   QEMU_TAG:   'qemu-2020-02-26.4'
54
55   UPSTREAM_REPO: libevdev/libevdev
56   BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
57   FEDORA_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$FEDORA_TAG
58   CENTOS_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/centos/$CENTOS_VERSION:$CENTOS_TAG
59   UBUNTU_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$UBUNTU_VERSION:$UBUNTU_TAG
60   DEBIAN_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/debian/$DEBIAN_VERSION:$DEBIAN_TAG
61   ARCH_CONTAINER_IMAGE:   $CI_REGISTRY_IMAGE/arch/rolling:$ARCH_TAG
62   ALPINE_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/alpine/latest:$ALPINE_TAG
63   QEMU_CONTAINER_IMAGE:   $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$QEMU_TAG
64
65   LIBEVDEV_SKIP_ROOT_TESTS: 1
66   GIT_DEPTH: 1
67   MESON_BUILDDIR: 'build dir'
68
69 .default_artifacts:
70   artifacts:
71     paths:
72       - _build/test/test-suite.log
73       - $MESON_BUILDDIR/meson-logs/
74     expire_in: 1 week
75     when: on_failure
76     reports:
77       junit: $MESON_BUILDDIR/junit-*.xml
78
79 .autotools_build:
80   extends:
81     - .default_artifacts
82   script:
83     - mkdir _build
84     - pushd _build > /dev/null
85     - ../autogen.sh --disable-silent-rules $CONFIGURE_FLAGS
86     - make
87     - make check
88     - if ! [[ -z "$MAKE_ARGS" ]]; then make $MAKE_ARGS; fi
89     - popd > /dev/null
90
91 .meson_build:
92   extends:
93     - .default_artifacts
94   script:
95     - .gitlab-ci/meson-build.sh
96
97 #################################################################
98 #                                                               #
99 #                          prep stage                           #
100 #                                                               #
101 #################################################################
102
103 # Re-generate the CI script and make sure it's the one currently checked in
104 # If this job fails, re-generate the gitlab-ci.yml script, see
105 # $SRCDIR/.gitlab-ci/generate-gitlab-ci.py
106 #
107 check-ci-script:
108   image: golang:alpine
109   stage: prep
110   before_script:
111     - apk add python3 git
112     - pip3 install --user jinja2 PyYAML
113   script:
114     - python3 ./.gitlab-ci/generate-gitlab-ci.py
115     - git diff --exit-code && exit 0 || true
116     - echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
117     - exit 1
118
119 check-commit:
120   image: golang:alpine
121   stage: prep
122   before_script:
123     - apk add python3 git
124   script:
125     - pip3 install GitPython
126     - pip3 install pytest
127     - |
128       pytest --junitxml=results.xml \
129              --tb=line \
130              --assert=plain \
131              ./.gitlab-ci/check-commit.py
132   except:
133     - master@libevdev/libevdev
134   variables:
135     GIT_DEPTH: 100
136   artifacts:
137     expire_in: 1 week
138     when: on_failure
139     paths:
140       - results.xml
141     reports:
142       junit: results.xml
143
144 .pull_upstream_or_rebuild:
145   before_script:
146     # log in to the registry
147     - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
148
149     # get the full container image name (DISTRIB_VERSION still has indirections)
150     - IMAGE=$(eval echo "$DISTRIB_NAME/$DISTRIB_VERSION:$TAG")
151
152     - |
153       # force rebuild if schedule, reuse otherwise
154       if [[ $CI_PIPELINE_SOURCE != "schedule" ]] ;
155       then
156         # pull the latest upstream image if it exists
157         skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE \
158                     docker://$CI_REGISTRY_IMAGE/$IMAGE && exit 0 || true ;
159
160         # check if our image is already in the current registry
161         skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
162       fi
163
164 fedora:31@qemu-prep:
165   extends:
166     - .fedora@qemu-build
167     - .pull_upstream_or_rebuild
168   stage: prep
169   tags:
170     - kvm
171   variables:
172     GIT_STRATEGY: none
173     FEDORA_VERSION: 31
174     FEDORA_TAG: $QEMU_TAG
175     DISTRIB_NAME: fedora
176     DISTRIB_VERSION: $FEDORA_VERSION
177     TAG: $QEMU_TAG
178   allow_failure: true
179
180 {% for distro in distributions %}
181
182 ### {{ distro.name }} {{ distro.version }}
183 {{ distro.name }}:{{ distro.version }}@container-prep:
184   extends:
185     - .{{ distro.name }}@container-build
186     - .pull_upstream_or_rebuild
187   stage: prep
188   variables:
189     GIT_STRATEGY: none
190     {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
191     DISTRIB_NAME: {{ distro.name }}
192     DISTRIB_VERSION: ${{ distro.name.upper() }}_VERSION
193     TAG: ${{ distro.name.upper() }}_TAG
194
195 {% endfor %}
196
197 #################################################################
198 #                                                               #
199 #                   container clean stage                       #
200 #                 run during the clean stage                    #
201 #                                                               #
202 #################################################################
203
204 #
205 # This stage will look for the container images we currently have in
206 # the registry and will remove any that are not tagged with the provided
207 # $container_image:$tag
208 #
209 .container-clean:
210   stage: container_clean
211   image: $BUILDAH_IMAGE
212   script:
213     # get the full container image name (CURRENT_CONTAINER_IMAGE still has indirections)
214     - CONTAINER_IMAGE=$(eval echo "$CURRENT_CONTAINER_IMAGE")
215     - GITLAB=$(echo $CI_PROJECT_URL | cut -f3 -d/)
216     - REPOSITORY=$(echo $CONTAINER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
217     - IMAGE_PATH=$(echo $CONTAINER_IMAGE | cut -f1 -d:)
218     - LATEST_TAG=$(echo $CONTAINER_IMAGE | cut -f2 -d:)
219
220     # log in to the registry (read only)
221     - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
222
223     # get the r/w token from the settings to access the registry
224     #
225     # each developer needs to register a secret variable that contains
226     # a personal token with api access. The token
227     # - must be named PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
228     # - must be registered in the CI/CD Variables section as type file
229     # - value must be a netrc file as a single-line string:
230     #   default login <user> password <token value>
231     #   e.g. "default login bentiss password 1235abcde"
232     - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
233     - netrcfile=$(eval echo "\$$tokenname")
234     - if [[ ! -f "$netrcfile" ]]; then
235          echo "No netrc file found or token is missing, skipping job" && false;
236       fi
237
238     # request a token for the registry API
239     - REGISTRY_TOKEN=$(curl https://$GITLAB/jwt/auth --get
240                              --silent --show-error
241                              -d client_id=docker
242                              -d offline_token=true
243                              -d service=container_registry
244                              -d "scope=repository:$REPOSITORY:pull,*"
245                              --fail
246                              --netrc-file "$netrcfile"
247                              | sed -r 's/(\{"token":"|"\})//g')
248
249     # get the digest of the latest image
250     - LATEST_MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.Digest')
251
252     # get the list of tags
253     - TAGS=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.RepoTags[]')
254     # FIXME: is the above command working properly? If not, use below:
255     # - TAGS=$(curl -X GET -H "accept:application/vnd.docker.distribution.manifest.v2+json"
256     #                      -H "authorization:Bearer $REGISTRY_TOKEN"
257     #                      https://$CI_REGISTRY/v2/$REPOSITORY/tags/list | jq -r '.tags[]')
258
259     # iterate over the tags
260     - for tag in $TAGS;
261       do
262         MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$tag | jq -r '.Digest');
263         if test x"$MANIFEST" != x"$LATEST_MANIFEST";
264           then
265             echo removing $tag as $MANIFEST;
266             curl https://$CI_REGISTRY/v2/$REPOSITORY/manifests/$MANIFEST --silent
267                  -H "accept:application/vnd.docker.distribution.manifest.v2+json"
268                  -H "authorization:Bearer $REGISTRY_TOKEN"
269                  --fail --show-error -X DELETE || true
270           ;fi
271       ;done
272   dependencies: []
273   allow_failure: true
274   only:
275     - schedules
276   variables:
277     GIT_STRATEGY: none
278
279 {% for distro in distributions %}
280
281 ### {{ distro.name }} {{ distro.version }}
282 {{ distro.name }}:{{ distro.version }}@container-clean:
283   extends: .container-clean
284   variables:
285     {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
286     CURRENT_CONTAINER_IMAGE: ${{ distro.name.upper() }}_CONTAINER_IMAGE
287
288 {% endfor %}
289
290 #################################################################
291 #                                                               #
292 #                       build stage                             #
293 #                                                               #
294 #################################################################
295
296 .autotools-build@template:
297   extends:
298     - .autotools_build
299   stage: build
300   dependencies: []
301   variables:
302     MAKE_ARGS: "distcheck"
303
304 .meson-build@template:
305   extends:
306     - .meson_build
307   stage: build
308   dependencies: []
309   variables:
310     NINJA_ARGS: "dist"
311
312 {% for distro in distributions %}
313
314 {{ distro.name }}:{{ distro.version }}@autotools-build:
315   extends: .autotools-build@template
316   stage: autotools
317   image: ${{ distro.name.upper() }}_CONTAINER_IMAGE
318   variables:
319     {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
320     {# Where we have extra_variables defined, add them to the list #}
321     {% if distro.build is defined and distro.build.extra_variables is defined %}
322       {% for key, value in distro.build.extra_variables.items() %}
323     {{ key }}: {{ value }}
324       {% endfor %}
325     {% endif %}
326   needs: ['{{ distro.name }}:{{ distro.version }}@container-prep']
327
328 {% if not distro.build is defined or distro.build.meson|default(True) %}
329 {{ distro.name }}:{{ distro.version }}@meson-build:
330   extends: .meson-build@template
331   stage: meson
332   image: ${{ distro.name.upper() }}_CONTAINER_IMAGE
333   variables:
334     {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
335     {# Where we have extra_variables defined, add them to the list #}
336     {% if distro.build is defined and distro.build.extra_variables is defined %}
337       {% for key, value in distro.build.extra_variables.items() %}
338     {{ key }}: {{ value }}
339       {% endfor %}
340     {% endif %}
341   needs: ['{{ distro.name }}:{{ distro.version }}@container-prep']
342 {% endif %}
343
344 {% endfor %}
345
346 # Build argument tests
347 #
348 # We only run the build option combinations on one image
349 # because they're supposed to fail equally on all
350 .fedora-custom-build@autotools-template:
351   extends: .autotools-build@template
352   stage: build
353   image: $FEDORA_CONTAINER_IMAGE
354   variables:
355     FEDORA_VERSION: 31
356   needs: ['fedora:31@container-prep']
357
358 no-valgrind:autotools:
359   extends: .fedora-custom-build@autotools-template
360   before_script:
361     - dnf remove -y valgrind
362
363 no-check:autotools:
364   extends: .fedora-custom-build@autotools-template
365   before_script:
366     - dnf remove -y check check-devel
367
368 no-doxygen:autotools:
369   extends: .fedora-custom-build@autotools-template
370   before_script:
371     - dnf remove -y doxygen
372   variables:
373     MAKE_ARGS: ''  # disable distcheck, requires doxygen
374
375 # doxygen is required for distcheck
376 no-doxygen-check-valgrind:autotools:
377   extends: .fedora-custom-build@autotools-template
378   before_script:
379     - dnf remove -y doxygen valgrind check check-devel
380   variables:
381     MAKE_ARGS: ''  # disable distcheck, requires doxygen
382
383 no-nm:autotools:
384   extends: .fedora-custom-build@autotools-template
385   before_script:
386     - mv /usr/bin/nm /usr/bin/nm.moved
387
388 enable-gcov:autotools:
389   extends: .fedora-custom-build@autotools-template
390   variables:
391     CONFIGURE_FLAGS: "--enable-gcov"
392
393 .fedora-custom-build@meson-template:
394   extends: .meson-build@template
395   stage: build
396   image: $FEDORA_CONTAINER_IMAGE
397   variables:
398     FEDORA_VERSION: 31
399   needs: ['fedora:31@container-prep']
400
401 no-valgrind:meson:
402   extends: .fedora-custom-build@meson-template
403   before_script:
404     - dnf remove -y valgrind
405
406 no-check:meson:
407   extends: .fedora-custom-build@meson-template
408   before_script:
409     - dnf remove -y check check-devel
410   variables:
411     MESON_ARGS: -Dtests=disabled
412     SKIP_MESON_TEST: 1
413
414 # doxygen is required for dist
415 no-doxygen:meson:
416   extends: .fedora-custom-build@meson-template
417   before_script:
418     - dnf remove -y doxygen
419   variables:
420     MESON_ARGS: -Ddocumentation=disabled
421     NINJA_ARGS: ''
422
423 # doxygen is required for dist
424 no-doxygen-check-valgrind:meson:
425   extends: .fedora-custom-build@meson-template
426   before_script:
427     - dnf remove -y doxygen valgrind check check-devel
428   variables:
429     MESON_ARGS: -Dtests=disabled -Ddocumentation=disabled
430     NINJA_ARGS: ''
431     SKIP_MESON_TEST: 1
432
433 enable-gcov:meson:
434   extends: .fedora-custom-build@meson-template
435   variables:
436     MESON_ARGS: '-Dcoverity=true'
437
438 scan-build:meson:
439   extends: .fedora-custom-build@meson-template
440   variables:
441     NINJA_ARGS: 'scan-build'
442     SKIP_MESON_TEST: 1
443
444 soname:
445   stage: build
446   image: $FEDORA_CONTAINER_IMAGE
447   script:
448   - ./autogen.sh --prefix=$PWD/prefix-autotools/
449   - make install
450   - ls -l $PWD/prefix-autotools/lib/libevdev.so.2.3.0
451   - meson "$MESON_BUILDDIR" --prefix=$PWD/prefix-meson/
452   - ninja -C "$MESON_BUILDDIR" install
453   - ls -l $PWD/prefix-meson/lib64/libevdev.so.2.3.0
454   variables:
455     FEDORA_VERSION: 31
456   needs: ['fedora:31@container-prep']
457
458 #################################################################
459 #                                                               #
460 #                          VM stage                             #
461 #                                                               #
462 #################################################################
463
464 .check_tainted: &check_tainted |
465   # make sure the kernel is not tainted
466   if [[ "$(ssh localhost -p 5555 cat /proc/sys/kernel/tainted)" -gt 0 ]];
467   then
468     echo tainted kernel ;
469     exit 1 ;
470   fi
471
472 .qemu@fedora:31:
473   stage: VM
474   image: $QEMU_CONTAINER_IMAGE
475   tags:
476     - kvm
477   variables:
478     FEDORA_VERSION: 31
479     MESON_BUILDDIR: build_dir
480   script:
481     # start our vm, no args required
482     - /app/start_vm.sh
483
484     - *check_tainted
485
486     - "scp -P 5555 -r $PWD localhost:"
487     - echo "CI_JOB_ID=\"$CI_JOB_ID\"" > sshenv
488     - echo "CI_JOB_NAME=\"$CI_JOB_NAME\"" >> sshenv
489     - echo "MESON_BUILDDIR=\"$MESON_BUILDDIR\"" >> sshenv
490     - echo "MESON_TEST_ARGS=\"$MESON_TEST_ARGS\"" >> sshenv
491     - echo "NINJA_ARGS=\"$NINJA_ARGS\"" >> sshenv
492     - "scp -P 5555 sshenv localhost:~/$CI_PROJECT_NAME/.meson_environment"
493     - ssh localhost -p 5555 "cd $CI_PROJECT_NAME ; .gitlab-ci/meson-build.sh" && touch .success || true
494     # no matter the results of the tests, we want to fetch the logs
495     - scp -P 5555 -r localhost:$CI_PROJECT_NAME/"$MESON_BUILDDIR" .
496
497     - *check_tainted
498
499     - ssh localhost -p 5555 halt || true
500     - sleep 2
501     - pkill qemu || true
502
503     - if [[ ! -e .success ]] ;
504       then
505         exit 1 ;
506       fi
507   artifacts:
508     name: "qemu-meson-logs-$CI_JOB_NAME"
509     when: always
510     expire_in: 1 week
511     paths:
512       - $MESON_BUILDDIR/meson-logs
513       - console.out
514     reports:
515       junit: $MESON_BUILDDIR/junit-*.xml
516
517   retry:
518     max: 2
519     when: script_failure
520   needs: ['fedora:31@qemu-prep']
521
522 qemu:meson:
523   extends: .qemu@fedora:31
524
525 qemu:meson:valgrind:
526   extends: .qemu@fedora:31
527   variables:
528     MESON_TEST_ARGS: '--setup=valgrind'
529
530 meson-from-tarball:
531   stage: tarballs
532   image: $FEDORA_CONTAINER_IMAGE
533   script:
534     - export INSTALLDIR="$PWD/_inst"
535     - mkdir _build
536     - pushd _build > /dev/null
537     - ../autogen.sh --disable-silent-rules $CONFIGURE_FLAGS
538     - make
539     - make distcheck
540     - popd > /dev/null
541     - mkdir -p _tarball_dir
542     - tar xf _build/libevdev-*.tar.xz -C _tarball_dir
543     - pushd _tarball_dir/libevdev-*/ > /dev/null
544     - meson "$MESON_BUILDDIR" --prefix="$INSTALLDIR"
545     - ninja -C "$MESON_BUILDDIR" test
546     - ninja -C "$MESON_BUILDDIR" install
547     - popd > /dev/null
548     - ls -lR $INSTALLDIR
549   variables:
550     FEDORA_VERSION: 31
551   needs: ['fedora:31@container-prep']
552
553 autotools-from-tarball:
554   stage: tarballs
555   image: $FEDORA_CONTAINER_IMAGE
556   script:
557     - export INSTALLDIR="$PWD/_inst"
558     - meson "$MESON_BUILDDIR"
559     - ninja -C "$MESON_BUILDDIR" dist
560     - mkdir -p _tarball_dir
561     - tar xf "$MESON_BUILDDIR"/meson-dist/libevdev-*.xz -C _tarball_dir
562     - pushd _tarball_dir/libevdev-*/ > /dev/null
563     - mkdir _build
564     - pushd _build > /dev/null
565     - ../autogen.sh --disable-silent-rules --prefix="$INSTALLDIR" $CONFIGURE_FLAGS
566     - make
567     - make install
568     - make distcheck
569     - popd > /dev/null
570     - popd > /dev/null
571     - ls -lR $INSTALLDIR
572   variables:
573     FEDORA_VERSION: 31
574   needs: ['fedora:31@container-prep']