dist: focal
language: C
services:
    - docker

matrix:
    include:
        # 32 bit build
        - os: linux
          env: DISTRO=debian:stable VARIANT=i386 ARCH=i386
          compiler: gcc

        # cross compilation builds
        - os: linux
          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=ppc64el
          compiler: powerpc64le-linux-gnu-gcc

        - os: linux
          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=arm64
          compiler: aarch64-linux-gnu-gcc

        - os: linux
          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=s390x
          compiler: s390x-linux-gnu-gcc

        # musl
        - os: linux
          env: DISTRO=alpine:latest
          compiler: gcc

        # glibc (gcc/clang)
        - os: linux
          env: DISTRO=opensuse/tumbleweed
          compiler: clang

        - os: linux
          env: DISTRO=opensuse/leap
          compiler: gcc

        - os: linux
          env: DISTRO=ubuntu:jammy
          compiler: gcc

        - os: linux
          env: DISTRO=ubuntu:focal
          compiler: clang

        - os: linux
          env: DISTRO=fedora:latest
          compiler: clang

        - os: linux
          env: REPO="quay.io/centos/" DISTRO="${REPO}centos:stream8" WAIT="travis_wait 30 "
          compiler: clang

        - os: linux
          env: DISTRO=debian:testing
          compiler: clang

        - os: linux
          env: DISTRO=debian:stable
          compiler: gcc

        - os: linux
          env: REPO="docker.io/library/" DISTRO="${REPO}alt:sisyphus" CONTAINER=podman CONTAINER_ARGS="--runtime=/usr/bin/crun --network=host" WAIT="travis_wait 30 "
          compiler: gcc

before_install:
    - CONTAINER="${CONTAINER:-docker}"
    - >
        if [ "$CONTAINER" = "podman" ]; then
            # podman
            . /etc/os-release
            sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
            wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -
            sudo apt update
            sudo apt -y install fuse-overlayfs podman slirp4netns crun
        fi
    - $CONTAINER info

    - DIR="/usr/src/tpm2"
    - printf "FROM $DISTRO\nRUN mkdir -p $DIR\nWORKDIR $DIR\nCOPY . $DIR\n" > Dockerfile
    - cat Dockerfile
    - $CONTAINER build $CONTAINER_ARGS -t tpm2 .

script:
    - INSTALL="${DISTRO#${REPO}}"
    - INSTALL="${INSTALL%%:*}"
    - INSTALL="${INSTALL%%/*}"
    # if VARIANT is set to a cross compile, don't run the regression test, therefore don't install the SW TPM
    - $WAIT $CONTAINER run $CONTAINER_ARGS -t tpm2 /bin/sh -c "cd ci && if [ \"$VARIANT\" ]; then ARCH=\"$ARCH\" ./$INSTALL.$VARIANT.sh; fi && ARCH=\"$ARCH\" CC=\"$CC\" ./$INSTALL.sh && if [ ! \"$VARIANT\" ]; then ../ci/install-ibmtpm.sh; fi && CC=\"$CC\" VARIANT=\"$VARIANT\" ../build.sh"
