bintray:
  repository:
    type: debian
    name: focal
    description: Performance Co-Pilot for Ubuntu 20.04 (focal fossa)
  params:
    deb_distribution: focal
    deb_component: main
    deb_architecture: amd64

container:
  init: /usr/bin/systemd
  containerfile: |
    FROM docker.io/library/ubuntu:20.04
    RUN apt-get update && apt-get install -y systemd sudo
    RUN useradd --create-home pcpbuild
    RUN echo 'pcpbuild ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/pcpbuild

    # allow services to be started during installation
    # pmcd will create the file /var/lib/pcp/pmns/stdpmid, which is required by QA tests
    RUN printf '#!/bin/sh\nexit 0\n' > /usr/sbin/policy-rc.d

tasks:
  update: |
    sudo apt-get -y update
    sudo ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade
  install_build_dependencies: |
    sudo apt-get -y update
    pkgs=$(./pcp/qa/admin/list-packages -m -v -x cpan -x pip3 -x not4ci)
    sudo DEBIAN_FRONTEND=noninteractive apt-get install -y $pkgs
  build: |
    cd ./pcp
    ./Makepkgs --nonrpm --verbose
    dpkg -I ./build/deb/pcp_*.deb | grep Depends | grep -q libuv1
  copy_build_artifacts: |
    cp ./pcp/build/deb/*.deb artifacts/build
  install: |
    sudo dpkg -i ./pcp/build/deb/*.deb
    echo 'pcpqa ALL=(ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/pcpqa
  init_qa: |
    sudo -i -u pcpqa ./check 002
  qa_sanity: |
    set -o pipefail
    if [ "$runner" = "container" ]; then
      sudo -i -u pcpqa ./check -TT -g sanity -x not_in_ci -x not_in_container |& tee ./artifacts/test/test.log
    else
      sudo -i -u pcpqa ./check -TT -g sanity -x not_in_ci |& tee ./artifacts/test/test.log
    fi
  qa: |
    set -o pipefail
    if [ "$runner" = "container" ]; then
      sudo -i -u pcpqa ./check -TT -x x11 -x remote -x not_in_ci -x not_in_container |& tee ./artifacts/test/test.log
    else
      sudo -i -u pcpqa ./check -TT -x x11 -x remote -x not_in_ci |& tee ./artifacts/test/test.log
    fi
  copy_test_artifacts: |
    cp /var/lib/pcp/testsuite/check.timings ./artifacts/test
    [ $(awk 'END{print NF}' ./artifacts/test/check.timings) = 2 ] && date '+%s' >> ./artifacts/test/check.timings
    shopt -s nullglob
    for test in /var/lib/pcp/testsuite/*.out.bad; do cp $test ${test/.out.bad/.full} ./artifacts/test || true; done
