#!/usr/bin/env bash

set -e

: "${SKIP_LINT:=0}"
: "${SKIP_TYPE_CHECKS:=0}"
: "${SKIP_TESTS:=0}"

if [ "$SKIP_LINT" -ne 1 ]; then
    echo 'Running linting...'
    poetry run yamllint -s docker-compose.yml
    poetry run ruff check .
    echo 'Running formatter check...'
    poetry run ruff format . --diff --no-cache
fi

if [ "$SKIP_TYPE_CHECKS" -ne 1 ]; then
    echo 'Running mypy...'
    poetry run mypy --cache-dir=/dev/null src tests
fi

if [ "$SKIP_TESTS" -ne 1 ]; then
    echo 'Running tests...'
    mkdir -p build
    COVERAGE_FILE=build/.coverage \
        poetry run pytest tests \
            $TEST_ARGS \
            --ignore=tests/integration/ \
            -p no:cacheprovider \
            --cov src \
            --cov-report xml:build/coverage.xml \
            --cov-report term \
            --junitxml=build/pyunit.xml
fi

echo 'Done!'
