#!/bin/sh

# This is the expected entry point for Cockpit CI; will be called without
# arguments but with an appropriate $TEST_OS, and optionally $TEST_SCENARIO

set -eu

tools/make-bots
test/common/pixel-tests pull

TEST_SCENARIO=${TEST_SCENARIO:-verify}

case $TEST_SCENARIO in
    verify|devel|firefox|firefox-devel)
        OPTS="--track-naughties"
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%devel}" ] || export NODE_ENV=development
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%devel}" ] || OPTS="$OPTS --coverage"
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO##firefox}" ] || export TEST_BROWSER=firefox
        test/image-prepare --verbose $TEST_OS
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify ${OPTS}
        ;;
    dnf-copr*)
        bots/image-customize -v --run-command 'dnf -y copr enable rpmsoftwaremanagement/dnf-nightly && dnf -y --setopt=install_weak_deps=False update' $TEST_OS
        test/image-prepare --verbose --overlay $TEST_OS
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify --track-naughties
        ;;
    pybridge)
        test/image-prepare --verbose $TEST_OS
        make -C tmp/build-dist/ cockpit-bridge.pyz
        bots/image-customize -v --upload tmp/build-dist/cockpit-bridge.pyz:/usr/bin/cockpit-bridge $TEST_OS
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify --track-naughties
        ;;
    *)
        echo "Unknown test scenario: $TEST_SCENARIO"
        exit 1
esac
