type: container

artifactory:
  package_type: rpm
  deploy_path: /fedora/36/x86_64/pcp

container:
  containerfile: |
    FROM registry.fedoraproject.org/fedora:36
    RUN dnf install -y systemd
    RUN useradd --create-home pcpbuild
    RUN echo 'pcpbuild ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/pcpbuild
    CMD ["/usr/sbin/init"]

tasks:
  setup: |
    sudo dnf install -y which hostname
    sudo dnf -y -b install $(qa/admin/list-packages -m -v -x cpan -x pip3 -x not4ci)
  build: |
    ./Makepkgs --verbose --check
    rpm -qp --requires $(echo pcp-*/build/rpm/pcp-*.src.rpm | sed 's/src/x86_64/') | grep -q libuv.so
  copy_build_artifacts: |
    cp pcp-*/build/rpm/*.rpm ../artifacts/build
  install: |
    sudo rpm -Uv pcp-*/build/rpm/*.rpm
    echo 'pcpqa ALL=(ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/pcpqa
  init_qa: |
    sudo systemctl start redis
    sudo -i -u pcpqa ./check 002
  qa_sanity: |
    set -o pipefail
    sudo -i -u pcpqa ./check -TT -g sanity -x not_in_ci -x not_in_container |& tee ../artifacts/test/test.log
  qa: |
    set -o pipefail
    DEFAULT_PCP_QA_ARGS="-x x11 -x remote -x not_in_ci -x not_in_container"
    sudo -i -u pcpqa ./check -TT ${PCP_QA_ARGS:-${DEFAULT_PCP_QA_ARGS}} |& tee ../artifacts/test/test.log
  copy_test_artifacts: |
    cp /var/lib/pcp/testsuite/check.timings ../artifacts/test
    # add current timestamp if the last QA test got stuck
    [ $(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 ../artifacts/test; [ -f ${test/.out.bad/.full} ] && cp ${test/.out.bad/.full} ../artifacts/test; done
    [ -x /var/lib/pcp/testsuite/admin/whatami ] && /var/lib/pcp/testsuite/admin/whatami >../artifacts/test/whatami
