include:
    - project: 'steam/steam-ci-pipeline'
      file: '/steam-gitlab-ci-common.yml'

    - project: 'steam/steam-ci-pipeline'
      file: '/steam-gitlab-ci-pipeline.yml'

variables:
    BUILD_IMAGE: docker.internal.steamos.cloud/steamrt/sdk:scout-latest
    STEAM_CI_USE_BINARIES_FROM: autopkgtest
    STEAM_CI_DEPENDENCIES: >-
        debhelper
        libglib2.0-dev
        libxau-dev
        locales
        meson
        pandoc
        python3
        python3.5
        zlib1g

    DEBIAN_FRONTEND: noninteractive

    SCOUT_DOCKER_REGISTRY: docker.steamos.cloud
    SCOUT_DOCKER_IMAGE: steamrt/sdk:scout
    SCOUT_APT_SOURCES_FILE: ''
    DEVEL_DOCKER_REGISTRY: docker.steamos.cloud
    DEVEL_DOCKER_IMAGE: steamos/package-builder:buster
    # Set non-empty to allow
    CI_ALLOW_MISSING_SOURCES: ''

    STEAM_RUNTIME_TOOLS_GIT_REPO: https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.steamos.cloud/steam/steam-runtime-tools.git
    STEAM_RUNTIME_TOOLS_GIT_BRANCH: master

build:
    variables:
        BUILD_IMAGE: docker.internal.steamos.cloud/steamos/package-builder:buster

build:devel:
    stage: build
    image: "${DEVEL_DOCKER_REGISTRY}/${DEVEL_DOCKER_IMAGE}"
    script:
        - |
            set -eux

            git clone \
            -b${STEAM_RUNTIME_TOOLS_GIT_BRANCH} \
            ${STEAM_RUNTIME_TOOLS_GIT_REPO} \
            subprojects/steam-runtime-tools

            meson _build
            ninja -C _build
            ninja -C _build install
            meson test --verbose -C _build

build:scout:
    stage: build
    image: "${SCOUT_DOCKER_REGISTRY}/${SCOUT_DOCKER_IMAGE}"
    script:
        - |
            set -eux

            if [ -n "${SCOUT_APT_SOURCES_FILE}" ]; then
                cp "${SCOUT_APT_SOURCES_FILE}" /etc/apt/sources.list
                echo >> /etc/apt/sources.list

                if [ -n "${STEAM_CI_EXTRA_APT_SOURCES-}" ]; then
                  echo "${STEAM_CI_EXTRA_APT_SOURCES}" | while read -r first rest; do
                    if [ "x$first" = xboth ]; then
                      echo "deb $rest" >> /etc/apt/sources.list
                      echo "deb-src $rest" >> /etc/apt/sources.list
                    else
                      echo "$first $rest" >> /etc/apt/sources.list
                    fi
                  done
                fi

                apt-get -y update
            fi

            apt-get -y --no-install-recommends install \
            bubblewrap \
            libcapsule0 \
            libcapsule-tools-relocatable:amd64 \
            libcapsule-tools-relocatable:i386 \
            libsteam-runtime-tools-0-dev \
            libsteam-runtime-tools-0-helpers:amd64 \
            libsteam-runtime-tools-0-helpers:i386 \
            libglib2.0-dev \
            libxau-dev \
            meson \
            steam-runtime-tools-bin
            ${NULL+}

            meson \
              --prefix="$(pwd)/_build/prefix" \
              -Dpython=python3.5 \
              -Dsrcdir=src \
              _build
            ninja -C _build
            meson test --verbose -C _build
            ninja -C _build install
            rm -fr _build/relocatable-install
            _build/prefix/bin/pressure-vessel-build-relocatable-install \
              --output _build/relocatable-install \
              --archive "$(pwd)/_build" \
              ${CI_ALLOW_MISSING_SOURCES:+--allow-missing-sources} \
              ${NULL+}
            prove -v ./tests/relocatable-install.py :: \
              "$(pwd)/_build/relocatable-install"

# Artifacts are currently disabled because uploading them to the
# coordinator results in HTTP 413 Request Entity Too Large.
#   artifacts:
#       paths:
#           - _build/pressure-vessel-*-bin.tar.gz
#           - _build/pressure-vessel-*-bin+src.tar.gz
