#!/bin/bash

set -e

# defaults if not set
: "${SKIP_LINT:=0}"
: "${SKIP_TESTS:=0}"
: "${SKIP_TYPE_CHECKS:=0}"

# type checking
if [ "$SKIP_TYPE_CHECKS" -ne 1 ]; then
    echo 'Running mypy...'
    poetry run mypy --cache-dir=/dev/null store tests application.py dev.py
else
    echo 'Skipping type checks...'
fi

# run linting of python files
if [ "$SKIP_LINT" -ne 1 ]; then
    echo 'Running linting...'
    poetry run ruff check store tests application.py dev.py --no-cache
    echo 'Running ruff formatter check...'
    poetry run ruff format store tests application.py dev.py --diff --no-cache
else
    echo 'Skipping linting...'
fi

# run pytest with args set
if [ "$SKIP_TESTS" -ne 1 ]; then
    echo 'Running tests...'
    COVERAGE_FILE=.coverage \
        python -m pytest tests \
        $TEST_ARGS \
        --ignore=tests/integration \
        --ignore=tests/testutils \
        -p no:cacheprovider \
        --cov store \
        --cov-report xml:coverage.xml \
        --cov-report term \
        --junitxml=pyunit.xml
else
    echo 'Skipping tests...'
fi

echo 'Done!'
