#!/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}"
[ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%devel}" ] || export NODE_ENV=development
tools/webpack-jumpstart --partial || true

case "$TEST_SCENARIO" in
    verify|devel|firefox|firefox-devel|pybridge)
        RUN_OPTS="--track-naughties"
        PREPARE_OPTS=""
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%devel}" ] || RUN_OPTS="$RUN_OPTS --coverage"
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO%%pybridge}" ] || PREPARE_OPTS="$PREPARE_OPTS --python"
        [ "${TEST_SCENARIO}" = "${TEST_SCENARIO##firefox}" ] || export TEST_BROWSER=firefox

        test/image-prepare --verbose ${PREPARE_OPTS} "${TEST_OS}"
        test/common/run-tests --jobs ${TEST_JOBS:-1} --test-dir test/verify ${RUN_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
        ;;
    *)
        echo "Unknown test scenario: $TEST_SCENARIO"
        exit 1
esac
