Auto-generate the gitlab CI script
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 14 Feb 2020 04:40:12 +0000 (14:40 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 17 Feb 2020 04:23:18 +0000 (14:23 +1000)
There is so much duplication between the various jobs that it's hard to keep
track of it manually. Let's employ a python script to generate those bits,
reducing the actual gitlab-ci.yml to the hand-written parts only.

The new script takes the .gitlab-ci/gitlab-ci.yml.in and simply appends the
generated parts to it. Most of it is straightforward, only centos needs some
custom parts because of missing doxygen.

The diff is a bit hard to review, thanks to the python script we now group
based on distribution, not based on name (i.e. all fedoras in one group
instead of all container-preps in one group).
And since we're generating anyway, some of the in-between stages were removed
(e.g. $DISTRO-build@template).

A new CI job is added to run a diff against the .gitlab-ci.yml that's checked
in and the one generated by this script. If they differ, we fail.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
.gitlab-ci.yml
.gitlab-ci/generate-gitlab-ci.py [new file with mode: 0755]
.gitlab-ci/gitlab-ci.tmpl [new file with mode: 0644]

index 25fc1c6d9b728275541a4a25aa8c6f0beff2a256..4019547d1f52af268544354c307af9eb81ceefd1 100644 (file)
@@ -1,4 +1,6 @@
 # vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
+#
+# THIS FILE IS GENERATED, DO NOT EDIT
 
 .templates_sha: &template_sha 01f2a6a8ab5cd31000c1c14a1acfff68ea98b59e # see https://docs.gitlab.com/ee/ci/yaml/#includefile
 
@@ -54,12 +56,12 @@ variables:
   # changing these will force rebuilding the associated image
   # Note: these tags have no meaning and are not tied to a particular
   # libevdev version
-  FEDORA_TAG: '2020-02-03.0'
-  CENTOS_TAG: '2020-02-03.0'
-  DEBIAN_TAG: '2020-02-03.0'
-  UBUNTU_TAG: '2020-02-03.0'
-  ARCH_TAG:   '2020-02-03.0'
-  ALPINE_TAG: '2020-02-03.0'
+  FEDORA_TAG: '2020-02-17.0'
+  CENTOS_TAG: '2020-02-17.0'
+  DEBIAN_TAG: '2020-02-17.0'
+  UBUNTU_TAG: '2020-02-17.0'
+  ARCH_TAG:   '2020-02-17.0'
+  ALPINE_TAG: '2020-02-17.0'
 
   UPSTREAM_REPO: libevdev/libevdev
   BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
@@ -100,6 +102,22 @@ variables:
 #                                                               #
 #################################################################
 
+# Re-generate the CI script and make sure it's the one currently checked in
+# If this job fails, re-generate the gitlab-ci.yml script, see
+# $SRCDIR/.gitlab-ci/generate-gitlab-ci.py
+#
+check-ci-script:
+  image: golang:alpine
+  stage: prep
+  before_script:
+    - apk add python3 git
+    - pip3 install --user jinja2
+  script:
+    - python3 ./.gitlab-ci/generate-gitlab-ci.py
+    - git diff --exit-code && exit 0 || true
+    - echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
+    - exit 1
+
 check-commit:
   image: golang:alpine
   stage: prep
@@ -141,6 +159,8 @@ check-commit:
         skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
       fi
 
+
+### fedora 30
 fedora:30@container-prep:
   extends:
     - .fedora@container-build
@@ -148,11 +168,13 @@ fedora:30@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    FEDORA_VERSION: 30
+    FEDORA_VERSION: '30'
     DISTRIB_FLAVOR: fedora
     DISTRIB_VERSION: $FEDORA_VERSION
     TAG: $FEDORA_TAG
 
+
+### fedora 31
 fedora:31@container-prep:
   extends:
     - .fedora@container-build
@@ -160,11 +182,13 @@ fedora:31@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    FEDORA_VERSION: 31
+    FEDORA_VERSION: '31'
     DISTRIB_FLAVOR: fedora
     DISTRIB_VERSION: $FEDORA_VERSION
     TAG: $FEDORA_TAG
 
+
+### ubuntu 19.10
 ubuntu:19.10@container-prep:
   extends:
     - .ubuntu@container-build
@@ -172,11 +196,13 @@ ubuntu:19.10@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    UBUNTU_VERSION: "19.10"
+    UBUNTU_VERSION: '19.10'
     DISTRIB_FLAVOR: ubuntu
     DISTRIB_VERSION: $UBUNTU_VERSION
     TAG: $UBUNTU_TAG
 
+
+### ubuntu 19.04
 ubuntu:19.04@container-prep:
   extends:
     - .ubuntu@container-build
@@ -184,11 +210,13 @@ ubuntu:19.04@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    UBUNTU_VERSION: "19.04"
+    UBUNTU_VERSION: '19.04'
     DISTRIB_FLAVOR: ubuntu
     DISTRIB_VERSION: $UBUNTU_VERSION
     TAG: $UBUNTU_TAG
 
+
+### debian stable
 debian:stable@container-prep:
   extends:
     - .debian@container-build
@@ -196,11 +224,13 @@ debian:stable@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    DEBIAN_VERSION: stable
+    DEBIAN_VERSION: 'stable'
     DISTRIB_FLAVOR: debian
     DISTRIB_VERSION: $DEBIAN_VERSION
     TAG: $DEBIAN_TAG
 
+
+### debian sid
 debian:sid@container-prep:
   extends:
     - .debian@container-build
@@ -208,33 +238,41 @@ debian:sid@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    DEBIAN_VERSION: sid
+    DEBIAN_VERSION: 'sid'
     DISTRIB_FLAVOR: debian
     DISTRIB_VERSION: $DEBIAN_VERSION
     TAG: $DEBIAN_TAG
 
-.centos@container-prep:
+
+### centos 7
+centos:7@container-prep:
   extends:
     - .centos@container-build
     - .pull_upstream_or_rebuild
   stage: prep
   variables:
     GIT_STRATEGY: none
-    CENTOS_VERSION: 7
+    CENTOS_VERSION: '7'
     DISTRIB_FLAVOR: centos
     DISTRIB_VERSION: $CENTOS_VERSION
     TAG: $CENTOS_TAG
 
-centos:7@container-prep:
-  extends: .centos@container-prep
-  variables:
-    CENTOS_VERSION: 7
 
+### centos 8
 centos:8@container-prep:
-  extends: .centos@container-prep
+  extends:
+    - .centos@container-build
+    - .pull_upstream_or_rebuild
+  stage: prep
   variables:
-    CENTOS_VERSION: 8
+    GIT_STRATEGY: none
+    CENTOS_VERSION: '8'
+    DISTRIB_FLAVOR: centos
+    DISTRIB_VERSION: $CENTOS_VERSION
+    TAG: $CENTOS_TAG
 
+
+### arch rolling
 arch:rolling@container-prep:
   extends:
     - .arch@container-build
@@ -242,11 +280,13 @@ arch:rolling@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    ARCH_VERSION: rolling
+    ARCH_VERSION: 'rolling'
     DISTRIB_FLAVOR: archlinux
     DISTRIB_VERSION: $ARCH_VERSION
     TAG: $ARCH_TAG
 
+
+### alpine latest
 alpine:latest@container-prep:
   extends:
     - .alpine@container-build
@@ -254,11 +294,12 @@ alpine:latest@container-prep:
   stage: prep
   variables:
     GIT_STRATEGY: none
-    ALPINE_VERSION: latest
+    ALPINE_VERSION: 'latest'
     DISTRIB_FLAVOR: alpine
     DISTRIB_VERSION: $ALPINE_VERSION
     TAG: $ALPINE_TAG
 
+
 #################################################################
 #                                                               #
 #                   container clean stage                       #
@@ -339,76 +380,97 @@ alpine:latest@container-prep:
   only:
     - schedules
 
+
+### fedora 30
 fedora:30@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    FEDORA_VERSION: 30
+    FEDORA_VERSION: '30'
     CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
 
+
+### fedora 31
 fedora:31@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    FEDORA_VERSION: 31
+    FEDORA_VERSION: '31'
     CURRENT_CONTAINER_IMAGE: $FEDORA_CONTAINER_IMAGE
 
+
+### ubuntu 19.10
 ubuntu:19.10@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    UBUNTU_VERSION: "19.10"
+    UBUNTU_VERSION: '19.10'
     CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
 
+
+### ubuntu 19.04
 ubuntu:19.04@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    UBUNTU_VERSION: "19.04"
+    UBUNTU_VERSION: '19.04'
     CURRENT_CONTAINER_IMAGE: $UBUNTU_CONTAINER_IMAGE
 
+
+### debian stable
 debian:stable@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    DEBIAN_VERSION: stable
+    DEBIAN_VERSION: 'stable'
     CURRENT_CONTAINER_IMAGE: $DEBIAN_CONTAINER_IMAGE
 
+
+### debian sid
 debian:sid@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
-    DEBIAN_VERSION: sid
+    DEBIAN_VERSION: 'sid'
     CURRENT_CONTAINER_IMAGE: $DEBIAN_CONTAINER_IMAGE
 
-.centos@container-clean:
+
+### centos 7
+centos:7@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
+    CENTOS_VERSION: '7'
     CURRENT_CONTAINER_IMAGE: $CENTOS_CONTAINER_IMAGE
 
-centos:7@container-clean:
-  extends: .centos@container-clean
-  variables:
-    CENTOS_VERSION: 7
 
+### centos 8
 centos:8@container-clean:
-  extends: .centos@container-clean
+  extends: .container-clean
   variables:
-    CENTOS_VERSION: 8
+    GIT_STRATEGY: none
+    CENTOS_VERSION: '8'
+    CURRENT_CONTAINER_IMAGE: $CENTOS_CONTAINER_IMAGE
+
 
+### arch rolling
 arch:rolling@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
+    ARCH_VERSION: 'rolling'
     CURRENT_CONTAINER_IMAGE: $ARCH_CONTAINER_IMAGE
 
+
+### alpine latest
 alpine:latest@container-clean:
   extends: .container-clean
   variables:
     GIT_STRATEGY: none
+    ALPINE_VERSION: 'latest'
     CURRENT_CONTAINER_IMAGE: $ALPINE_CONTAINER_IMAGE
 
+
 #################################################################
 #                                                               #
 #                       build stage                             #
@@ -423,94 +485,87 @@ alpine:latest@container-clean:
   variables:
     MAKE_ARGS: "distcheck"
 
-.fedora-build@template:
-  stage: distro
-  extends: .build@template
-  image: $FEDORA_CONTAINER_IMAGE
 
 fedora:30@default-build:
+  extends: .build@template
   stage: distro
-  extends: .fedora-build@template
+  image: $FEDORA_CONTAINER_IMAGE
   variables:
-    FEDORA_VERSION: 30
+    FEDORA_VERSION: '30'
   needs: ['fedora:30@container-prep']
 
 fedora:31@default-build:
+  extends: .build@template
   stage: distro
-  extends: .fedora-build@template
+  image: $FEDORA_CONTAINER_IMAGE
   variables:
-    FEDORA_VERSION: 31
+    FEDORA_VERSION: '31'
   needs: ['fedora:31@container-prep']
 
-.ubuntu@template:
-  stage: distro
+ubuntu:19.10@default-build:
   extends: .build@template
+  stage: distro
   image: $UBUNTU_CONTAINER_IMAGE
-
-ubuntu:19.10@default-build:
-  extends: .ubuntu@template
   variables:
-    UBUNTU_VERSION: "19.10"
+    UBUNTU_VERSION: '19.10'
   needs: ['ubuntu:19.10@container-prep']
 
 ubuntu:19.04@default-build:
-  extends: .ubuntu@template
+  extends: .build@template
+  stage: distro
+  image: $UBUNTU_CONTAINER_IMAGE
   variables:
-    UBUNTU_VERSION: "19.04"
+    UBUNTU_VERSION: '19.04'
   needs: ['ubuntu:19.04@container-prep']
 
-.debian@template:
-  stage: distro
+debian:stable@default-build:
   extends: .build@template
+  stage: distro
   image: $DEBIAN_CONTAINER_IMAGE
-
-debian:stable@default-build:
-  extends: .debian@template
   variables:
-    DEBIAN_VERSION: stable
+    DEBIAN_VERSION: 'stable'
   needs: ['debian:stable@container-prep']
 
 debian:sid@default-build:
-  extends: .debian@template
+  extends: .build@template
+  stage: distro
+  image: $DEBIAN_CONTAINER_IMAGE
   variables:
-    DEBIAN_VERSION: sid
+    DEBIAN_VERSION: 'sid'
   needs: ['debian:sid@container-prep']
 
-.centos-build@template:
-  stage: distro
+centos:7@default-build:
   extends: .build@template
+  stage: distro
   image: $CENTOS_CONTAINER_IMAGE
-
-centos:7@default-build:
-  extends: .centos-build@template
   variables:
-    CENTOS_VERSION: 7
+    CENTOS_VERSION: '7'
     MAKE_ARGS: ''  # disable distcheck, requires doxygen
   needs: ['centos:7@container-prep']
 
 centos:8@default-build:
-  extends: .centos-build@template
+  extends: .build@template
+  stage: distro
+  image: $CENTOS_CONTAINER_IMAGE
   variables:
-    CENTOS_VERSION: 8
+    CENTOS_VERSION: '8'
     MAKE_ARGS: ''  # disable distcheck, requires doxygen
   needs: ['centos:8@container-prep']
 
-.arch@template:
-  stage: distro
+arch:rolling@default-build:
   extends: .build@template
+  stage: distro
   image: $ARCH_CONTAINER_IMAGE
-
-arch:rolling@default-build:
-  extends: .arch@template
+  variables:
+    ARCH_VERSION: 'rolling'
   needs: ['arch:rolling@container-prep']
 
-.alpine@template:
-  stage: distro
+alpine:latest@default-build:
   extends: .build@template
+  stage: distro
   image: $ALPINE_CONTAINER_IMAGE
-
-alpine:latest@default-build:
-  extends: .alpine@template
+  variables:
+    ALPINE_VERSION: 'latest'
   needs: ['alpine:latest@container-prep']
 
 # Build argument tests
@@ -518,8 +573,9 @@ alpine:latest@default-build:
 # We only run the build option combinations on one image
 # because they're supposed to fail equally on all
 .fedora-custom-build@template:
+  extends: .build@template
   stage: build
-  extends: .fedora-build@template
+  image: $FEDORA_CONTAINER_IMAGE
   variables:
     FEDORA_VERSION: 31
   needs: ['fedora:31@container-prep']
@@ -557,4 +613,4 @@ fedora:31@no-nm:
 fedora:31@enable-gcov:
   extends: .fedora-custom-build@template
   variables:
-    CONFIGURE_FLAGS: "--enable-gcov"
+    CONFIGURE_FLAGS: "--enable-gcov"
\ No newline at end of file
diff --git a/.gitlab-ci/generate-gitlab-ci.py b/.gitlab-ci/generate-gitlab-ci.py
new file mode 100755 (executable)
index 0000000..cabf926
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+# vim: set expandtab shiftwidth=4:
+
+# This file generates the .gitlab-ci.yml file that defines the pipeline.
+
+import jinja2
+
+distributions = [
+    {'name': 'fedora', 'version': '30'},
+    {'name': 'fedora', 'version': '31'},
+    {'name': 'ubuntu', 'version': '19.10'},
+    {'name': 'ubuntu', 'version': '19.04'},
+    {'name': 'debian', 'version': 'stable'},
+    {'name': 'debian', 'version': 'sid'},
+    {
+        'name': 'centos', 'version': '7',
+        'build': {
+            'extra_variables': {
+                'MAKE_ARGS': ('\'\'  # disable distcheck, requires doxygen'),
+            }
+        },
+    },
+    {
+        'name': 'centos', 'version': '8',
+        'build': {
+            'extra_variables': {
+                'MAKE_ARGS': ('\'\'  # disable distcheck, requires doxygen'),
+            }
+        },
+    },
+    {'name': 'arch', 'version': 'rolling',
+     'flavor': 'archlinux' },  # see https://gitlab.freedesktop.org/wayland/ci-templates/merge_requests/19
+    {'name': 'alpine', 'version': 'latest'},
+]
+
+
+def generate_template():
+    env = jinja2.Environment(loader=jinja2.FileSystemLoader('./.gitlab-ci'),
+                             trim_blocks=True, lstrip_blocks=True)
+
+    template = env.get_template('gitlab-ci.tmpl')
+    config = {'distributions': distributions}
+    with open('.gitlab-ci.yml', 'w') as fd:
+        template.stream(config).dump(fd)
+
+
+if __name__ == '__main__':
+    generate_template()
diff --git a/.gitlab-ci/gitlab-ci.tmpl b/.gitlab-ci/gitlab-ci.tmpl
new file mode 100644 (file)
index 0000000..bd731f9
--- /dev/null
@@ -0,0 +1,347 @@
+# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
+#
+# THIS FILE IS GENERATED, DO NOT EDIT
+
+.templates_sha: &template_sha 01f2a6a8ab5cd31000c1c14a1acfff68ea98b59e # see https://docs.gitlab.com/ee/ci/yaml/#includefile
+
+include:
+  # Alpine container builder template
+  - project: 'wayland/ci-templates'
+    file: '/templates/alpine.yml'
+  # Arch container builder template
+  - project: 'wayland/ci-templates'
+    ref: *template_sha
+    file: '/templates/arch.yml'
+  # Fedora container builder template
+  - project: 'wayland/ci-templates'
+    ref: *template_sha
+    file: '/templates/fedora.yml'
+  # Ubuntu container builder template
+  - project: 'wayland/ci-templates'
+    ref: *template_sha
+    file: '/templates/ubuntu.yml'
+  # Debian container builder template
+  - project: 'wayland/ci-templates'
+    ref: *template_sha
+    file: '/templates/debian.yml'
+  # CentOS container builder template
+  - project: 'wayland/ci-templates'
+    ref: *template_sha
+    file: '/templates/centos.yml'
+
+stages:
+  - prep             # rebuild the container images if there is a change
+  - build            # for actually building and testing things in a container
+  - VM               # for running the test suite in a VM
+  - distro           # distribs test
+  - deploy           # trigger wayland's website generation
+  - container_clean  # clean up unused container images
+
+variables:
+  ###############################################################################
+  # This is the list of packages required to build libevdev with the default    #
+  # configuration.                                                              #
+  #                                                                             #
+  # Run dnf install/apt-get install/.. with the list of packages for your       #
+  # distribution                                                                #
+  ###############################################################################
+  FEDORA_RPMS: 'git gcc gcc-c++ automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils doxygen xz'
+  CENTOS_RPMS: 'git gcc gcc-c++ automake autoconf libtool make pkgconfig  python3 check-devel valgrind binutils xz'
+  UBUNTU_DEBS: 'git gcc g++     automake autoconf libtool make pkg-config python3 check       valgrind binutils doxygen xz-utils'
+  DEBIAN_DEBS: $UBUNTU_DEBS
+  ARCH_PKGS:   'git gcc         automake autoconf libtool make pkgconfig  python3 check       valgrind binutils doxygen'
+  ALPINE_PKGS: 'git gcc g++     automake autoconf libtool make pkgconfig  python3 check-dev   valgrind binutils doxygen xz linux-headers'
+  ############################ 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
+  # libevdev version
+  FEDORA_TAG: '2020-02-17.0'
+  CENTOS_TAG: '2020-02-17.0'
+  DEBIAN_TAG: '2020-02-17.0'
+  UBUNTU_TAG: '2020-02-17.0'
+  ARCH_TAG:   '2020-02-17.0'
+  ALPINE_TAG: '2020-02-17.0'
+
+  UPSTREAM_REPO: libevdev/libevdev
+  BUILDAH_IMAGE: $CI_REGISTRY/wayland/ci-templates/buildah:latest
+  FEDORA_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FEDORA_VERSION:$FEDORA_TAG
+  CENTOS_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/centos/$CENTOS_VERSION:$CENTOS_TAG
+  UBUNTU_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$UBUNTU_VERSION:$UBUNTU_TAG
+  DEBIAN_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/debian/$DEBIAN_VERSION:$DEBIAN_TAG
+  ARCH_CONTAINER_IMAGE:   $CI_REGISTRY_IMAGE/archlinux/rolling:$ARCH_TAG
+  ALPINE_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/alpine/latest:$ALPINE_TAG
+
+  LIBEVDEV_SKIP_ROOT_TESTS: 1
+  GIT_DEPTH: 1
+
+.default_artifacts:
+  artifacts:
+    paths:
+      - _build/test/test-suite.log
+    expire_in: 1 week
+    when: on_failure
+    reports:
+      junit: junit-*.xml
+
+.autotools_build:
+  extends:
+    - .default_artifacts
+  script:
+    - mkdir _build
+    - pushd _build > /dev/null
+    - ../autogen.sh --disable-silent-rules $CONFIGURE_FLAGS
+    - make
+    - make check
+    - if ! [[ -z "$MAKE_ARGS" ]]; then make $MAKE_ARGS; fi
+    - popd > /dev/null
+
+#################################################################
+#                                                               #
+#                          prep stage                           #
+#                                                               #
+#################################################################
+
+# Re-generate the CI script and make sure it's the one currently checked in
+# If this job fails, re-generate the gitlab-ci.yml script, see
+# $SRCDIR/.gitlab-ci/generate-gitlab-ci.py
+#
+check-ci-script:
+  image: golang:alpine
+  stage: prep
+  before_script:
+    - apk add python3 git
+    - pip3 install --user jinja2
+  script:
+    - python3 ./.gitlab-ci/generate-gitlab-ci.py
+    - git diff --exit-code && exit 0 || true
+    - echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
+    - exit 1
+
+check-commit:
+  image: golang:alpine
+  stage: prep
+  before_script:
+    - apk add python3 git
+  script:
+    - pip3 install GitPython
+    - pip3 install pytest
+    - |
+      pytest --junitxml=results.xml \
+             --tb=line \
+             --assert=plain \
+             ./.gitlab-ci/check-commit.py
+  except:
+    - master@libevdev/libevdev
+  variables:
+    GIT_DEPTH: 100
+  artifacts:
+    reports:
+      junit: results.xml
+
+.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
+
+{% for distro in distributions %}
+
+### {{ distro.name }} {{ distro.version }}
+{{ distro.name }}:{{ distro.version }}@container-prep:
+  extends:
+    - .{{ distro.name }}@container-build
+    - .pull_upstream_or_rebuild
+  stage: prep
+  variables:
+    GIT_STRATEGY: none
+    {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
+    DISTRIB_FLAVOR: {{ distro.flavor|default(distro.name) }}
+    DISTRIB_VERSION: ${{ distro.name.upper() }}_VERSION
+    TAG: ${{ distro.name.upper() }}_TAG
+
+{% endfor %}
+
+#################################################################
+#                                                               #
+#                   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. The token
+    # - must be named PERSONAL_TOKEN_$USER (for example PERSONAL_TOKEN_bentiss)
+    # - must be registered in the CI/CD Variables section as type file
+    # - value must be a netrc file as a single-line string:
+    #   default login <user> password <token value>
+    #   e.g. "default login bentiss password 1235abcde"
+    - tokenname="PERSONAL_TOKEN_$GITLAB_USER_LOGIN"
+    - netrcfile=$(eval echo "\$$tokenname")
+    - if [[ ! -f "$netrcfile" ]]; then
+         echo "No netrc file found or token is missing, skipping job" && false;
+      fi
+
+    # 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
+                             --netrc-file "$netrcfile"
+                             | 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
+
+{% for distro in distributions %}
+
+### {{ distro.name }} {{ distro.version }}
+{{ distro.name }}:{{ distro.version }}@container-clean:
+  extends: .container-clean
+  variables:
+    GIT_STRATEGY: none
+    {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
+    CURRENT_CONTAINER_IMAGE: ${{ distro.name.upper() }}_CONTAINER_IMAGE
+
+{% endfor %}
+
+#################################################################
+#                                                               #
+#                       build stage                             #
+#                                                               #
+#################################################################
+
+.build@template:
+  extends:
+    - .autotools_build
+  stage: build
+  dependencies: []
+  variables:
+    MAKE_ARGS: "distcheck"
+
+{% for distro in distributions %}
+
+{{ distro.name }}:{{ distro.version }}@default-build:
+  extends: .build@template
+  stage: distro
+  image: ${{ distro.name.upper() }}_CONTAINER_IMAGE
+  variables:
+    {{ distro.name.upper() }}_VERSION: '{{ distro.version }}'
+    {# Where we have extra_variables defined, add them to the list #}
+    {% if distro.build is defined and distro.build.extra_variables is defined %}
+      {% for key, value in distro.build.extra_variables.items() %}
+    {{ key }}: {{ value }}
+      {% endfor %}
+    {% endif %}
+  needs: ['{{ distro.name }}:{{ distro.version }}@container-prep']
+{% endfor %}
+
+# Build argument tests
+#
+# We only run the build option combinations on one image
+# because they're supposed to fail equally on all
+.fedora-custom-build@template:
+  extends: .build@template
+  stage: build
+  image: $FEDORA_CONTAINER_IMAGE
+  variables:
+    FEDORA_VERSION: 31
+  needs: ['fedora:31@container-prep']
+
+fedora:31@no-valgrind:
+  extends: .fedora-custom-build@template
+  before_script:
+    - dnf remove -y valgrind
+
+fedora:31@no-check:
+  extends: .fedora-custom-build@template
+  before_script:
+    - dnf remove -y check check-devel
+
+fedora:31@no-doxygen:
+  extends: .fedora-custom-build@template
+  before_script:
+    - dnf remove -y doxygen
+  variables:
+    MAKE_ARGS: ''  # disable distcheck, requires doxygen
+
+# doxygen is required for distcheck
+fedora:31@no-doxygen-check-valgrind:
+  extends: .fedora-custom-build@template
+  before_script:
+    - dnf remove -y doxygen valgrind check check-devel
+  variables:
+    MAKE_ARGS: ''  # disable distcheck, requires doxygen
+
+fedora:31@no-nm:
+  extends: .fedora-custom-build@template
+  before_script:
+    - mv /usr/bin/nm /usr/bin/nm.moved
+
+fedora:31@enable-gcov:
+  extends: .fedora-custom-build@template
+  variables:
+    CONFIGURE_FLAGS: "--enable-gcov"