libinput/.gitlab-ci.yml
Benjamin Tissoires 6d96d417a0 CI: simplify the logic for rebuilding the containers
right now the check_if_older_than_a_week rule does (in pseudo-code):
- get timestamp of current image or 0
- get timestamp of upstream image or 0
- if upstream image is newer than current image
  copy upstream image into current
- if we are in a scheduled pipeline, or if there is no current image
  (timestamp of 0), rebuild the current image

The ci-templates if-not-exists rule does:
- if there is a current image, exit
- if there is an upstream image, copy it to current and exit
- rebuild

Having the following is equivalent to the current behaviour and
can be used instead of check_if_older_than_a_week:
- if there is an upstream image, copy it to current and exit
- if there is a current image, exit
- rebuild

Because what matters is:

forks should be running the upstream image if available
forks should be running the latest upstream image in the libinput case
forks should be able to rebuild the images if there is no upstream
(change of the image tag)

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2019-04-01 04:11:20 +00:00

524 lines
17 KiB
YAML

# 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 container image for each distribution
# tested, then run the tests on this container image.
#
# Creating a container 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:29@build-default
include:
# Arch container builder template
- project: 'wayland/ci-templates'
ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
file: '/templates/arch.yml'
# Fedora container builder template
- project: 'wayland/ci-templates'
ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
file: '/templates/fedora.yml'
# Ubuntu container builder template
- project: 'wayland/ci-templates'
ref: c73dae8b84697ef18e2dbbf4fed7386d9652b0cd # see https://docs.gitlab.com/ee/ci/yaml/#includefile
file: '/templates/ubuntu.yml'
stages:
- container_prep # rebuild the container images if there is a change
- build # for actually building things
- deploy # trigger wayland's website generation
- container_clean # clean up unused container images
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 python3-sphinx python3-recommonmark libwacom-devel cairo-devel gtk3-devel glib2-devel mtdev-devel'
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'
ARCH_PKGS: 'git gcc pkgconfig meson check libsystemd libevdev doxygen graphviz python-sphinx python-recommonmark libwacom gtk3 mtdev diffutils'
FREEBSD_BUILD_PKGS: 'meson'
FREEBSD_PKGS: 'libepoll-shim libudev-devd libevdev libwacom gtk3 libmtdev '
############################ end of package lists #############################
# these tags should be updated each time the list of packages is updated
# changing these will force rebuilding the associated image
# Note: these tags have no meaning and are not tied to a particular
# libinput version
FEDORA_TAG: '2019-03-15.0'
UBUNTU_TAG: '2019-03-15.0'
ARCH_TAG: '2019-03-15.0'
FREEBSD_TAG: '2019-03-15.0'
UBUNTU_EXEC: "bash .gitlab-ci/ubuntu_install.sh $UBUNTU_CUSTOM_DEBS"
UPSTREAM_REPO: libinput/libinput
BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
FEDORA_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$FEDORA_TAG
UBUNTU_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$UBUNTU_VERSION:$UBUNTU_TAG
ARCH_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/archlinux/rolling:$ARCH_TAG
FREEBSD_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/freebsd/11.2:$FREEBSD_TAG
MESON_BUILDDIR: "build dir"
NINJA_ARGS: 'test'
MESON_ARGS: ''
# Until we have a VM with full access, we cannot run the test suite runner
SKIP_LIBINPUT_TEST_SUITE_RUNNER: 1
# udev isn't available/working properly in the containers
UDEV_NOT_AVAILABLE: 1
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
#################################################################
# #
# container prep stage #
# #
#################################################################
#
# This stage will recreate the container images only if the image
# is too old or if it is missing some dependencies.
#
.pull_upstream_or_rebuild: &pull_upstream_or_rebuild
before_script:
# log in to the registry
- podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# get the full container image name (DISTRIB_VERSION still has indirections)
- IMAGE=$(eval echo "$DISTRIB_FLAVOR/$DISTRIB_VERSION:$TAG")
- |
# force rebuild if schedule, reuse otherwise
if [[ $CI_PIPELINE_SOURCE != "schedule" ]] ;
then
# pull the latest upstream image if it exists
skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE \
docker://$CI_REGISTRY_IMAGE/$IMAGE && exit 0 || true ;
# check if our image is already in the current registry
skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
fi
fedora:28@container-prep:
extends: .fedora@container-build
stage: container_prep
variables:
GIT_STRATEGY: none
FEDORA_VERSION: 28
DISTRIB_FLAVOR: fedora
DISTRIB_VERSION: $FEDORA_VERSION
TAG: $FEDORA_TAG
<<: *pull_upstream_or_rebuild
fedora:29@container-prep:
extends: .fedora@container-build
stage: container_prep
variables:
GIT_STRATEGY: none
FEDORA_VERSION: 29
DISTRIB_FLAVOR: fedora
DISTRIB_VERSION: $FEDORA_VERSION
TAG: $FEDORA_TAG
<<: *pull_upstream_or_rebuild
ubuntu:18.10@container-prep:
extends: .ubuntu@container-build
stage: container_prep
variables:
GIT_STRATEGY: none
UBUNTU_VERSION: "18.10"
DISTRIB_FLAVOR: ubuntu
DISTRIB_VERSION: $UBUNTU_VERSION
TAG: $UBUNTU_TAG
<<: *pull_upstream_or_rebuild
ubuntu:18.04@container-prep:
extends: .ubuntu@container-build
stage: container_prep
variables:
GIT_STRATEGY: none
UBUNTU_VERSION: "18.04"
DISTRIB_FLAVOR: ubuntu
DISTRIB_VERSION: $UBUNTU_VERSION
TAG: $UBUNTU_TAG
<<: *pull_upstream_or_rebuild
arch:rolling@container-prep:
extends: .arch@container-build
stage: container_prep
variables:
GIT_STRATEGY: none
ARCH_VERSION: rolling
DISTRIB_FLAVOR: archlinux
DISTRIB_VERSION: $ARCH_VERSION
TAG: $ARCH_TAG
<<: *pull_upstream_or_rebuild
.freebsd@container-prep:
stage: container_prep
image: $BUILDAH_IMAGE
<<: *pull_upstream_or_rebuild
script:
- buildcntr=$(buildah from --quiet myfreeweb/freebsd-cross:latest)
- buildah run $buildcntr apk add --no-cache $FREEBSD_BUILD_PKGS
- buildah run $buildcntr pkg -r /freebsd update -f
- buildah run $buildcntr pkg -r /freebsd install -y $FREEBSD_PKGS
- buildah config --workingdir /app $buildcntr
# tag the current container
- buildah commit --quiet $buildcntr $FREEBSD_CONTAINER_IMAGE
# clean up the working container
- buildah rm $buildcntr
# push the container image to the libinput registry
- podman push --quiet $FREEBSD_CONTAINER_IMAGE
- skopeo copy docker://$FREEBSD_CONTAINER_IMAGE docker://$CI_REGISTRY_IMAGE/freebsd/$FREEBSD_VERSION:$CI_JOB_ID
freebsd:11.2@container-prep:
extends: .freebsd@container-prep
variables:
GIT_STRATEGY: none
FREEBSD_VERSION: "11.2"
DISTRIB_FLAVOR: freebsd
DISTRIB_VERSION: $FREEBSD_VERSION
TAG: $FREEBSD_TAG
#################################################################
# #
# container clean stage #
# run during the clean stage #
# #
#################################################################
#
# This stage will look for the container images we currently have in
# the registry and will remove any that are not tagged with the provided
# $container_image:$tag
#
.container-clean:
stage: container_clean
image: $BUILDAH_IMAGE
script:
# get the full container image name (CURRENT_CONTAINER_IMAGE still has indirections)
- CONTAINER_IMAGE=$(eval echo "$CURRENT_CONTAINER_IMAGE")
- GITLAB=$(echo $CI_PROJECT_URL | cut -f3 -d/)
- REPOSITORY=$(echo $CONTAINER_IMAGE | cut -f2- -d/ | cut -f1 -d:)
- IMAGE_PATH=$(echo $CONTAINER_IMAGE | cut -f1 -d:)
- LATEST_TAG=$(echo $CONTAINER_IMAGE | cut -f2 -d:)
# log in to the registry (read only)
- podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# 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/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=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.Digest')
# get the list of tags
- TAGS=$(skopeo inspect docker://$IMAGE_PATH:$LATEST_TAG | jq -r '.RepoTags[]')
# FIXME: is the above command working properly? If not, use below:
# - TAGS=$(curl -X GET -H "accept:application/vnd.docker.distribution.manifest.v2+json"
# -H "authorization:Bearer $REGISTRY_TOKEN"
# https://$CI_REGISTRY/v2/$REPOSITORY/tags/list | jq -r '.tags[]')
# iterate over the tags
- for tag in $TAGS;
do
MANIFEST=$(skopeo inspect docker://$IMAGE_PATH:$tag | jq -r '.Digest');
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 || true
;fi
;done
dependencies: []
allow_failure: true
only:
- schedules
fedora:28@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
FEDORA_VERSION: 28
CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
fedora:29@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
FEDORA_VERSION: 29
CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
ubuntu:18.10@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
UBUNTU_VERSION: "18.10"
CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
ubuntu:18.04@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
UBUNTU_VERSION: "18.04"
CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
arch:rolling@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
CURRENT_CONTAINER_IMAGE: $ARCH_CONTAINER_IMAGE
freebsd:11.2@container-clean:
extends: .container-clean
variables:
GIT_STRATEGY: none
CURRENT_CONTAINER_IMAGE: $FREEBSD_CONTAINER_IMAGE
#################################################################
# #
# build stage #
# #
#################################################################
.build@template:
stage: build
<<: *default_artifacts
<<: *default_build
dependencies: []
#
# Fedora
#
.fedora-build@template:
extends: .build@template
image: $FEDORA_CONTAINER_IMAGE
fedora:28@default-build:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 28
fedora:29@default-build:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
fedora:29@default-build-release:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Dbuildtype=release"
CFLAGS: "-Werror"
fedora:29@scan-build:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
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:29@build-no-libwacom:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Dlibwacom=false"
fedora:29@build-no-libwacom-nodeps:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Dlibwacom=false"
before_script:
- dnf remove -y libwacom libwacom-devel
fedora:29@build-no-docs:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Ddocumentation=false"
fedora:29@build-no-docs-nodeps:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Ddocumentation=false"
before_script:
- dnf remove -y doxygen graphviz
fedora:29@build-no-debuggui:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Ddebug-gui=false"
fedora:29@build-no-debuggui-nodeps:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Ddebug-gui=false"
before_script:
- dnf remove -y gtk3-devel
fedora:29@build-no-tests:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Dtests=false"
fedora:29@build-no-tests-nodeps:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
MESON_ARGS: "-Dtests=false"
before_script:
- dnf remove -y check-devel
fedora:29@valgrind:
extends: .fedora-build@template
variables:
FEDORA_VERSION: 29
before_script:
- dnf install -y valgrind
# note: we override the default_build here by providing a new script
script:
- rm -rf "$MESON_BUILDDIR"
- meson "$MESON_BUILDDIR" $MESON_ARGS
- meson configure "$MESON_BUILDDIR"
- meson test -C "$MESON_BUILDDIR" --setup=valgrind
#
# Ubuntu
#
.ubuntu@template:
extends: .build@template
image: $UBUNTU_CONTAINER_IMAGE
ubuntu:18.10@default-build:
extends: .ubuntu@template
variables:
UBUNTU_VERSION: "18.10"
ubuntu:18.04@default-build:
extends: .ubuntu@template
variables:
UBUNTU_VERSION: "18.04"
#
# Arch
#
.arch@template:
extends: .build@template
image: $ARCH_CONTAINER_IMAGE
arch:rolling@default-build:
extends: .arch@template
#
# FreeBSD
#
.freebsd@template:
extends: .build@template
image: $FREEBSD_CONTAINER_IMAGE
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: ''
freebsd:11.2@default-build:
extends: .freebsd@template
#
# deploy
#
wayland-web:
image: $BUILDAH_IMAGE
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"