#!/usr/bin/env bash

set -e

# run linting of yaml files
echo 'Running yamllint...'
poetry run yamllint -s docker-compose.yaml

# run linting of python files
echo 'Running ruff linter...'
poetry run ruff check src tests --no-cache

echo "Running ruff formatter check..."
poetry run ruff format src tests --diff --no-cache

# set flags for pytest-cov
COVERAGE_ARGS=""
if [ "$COV_REPORT" != "off" ]; then
    COVERAGE_ARGS="--cov-report $COV_REPORT --cov=src"
fi

# run pytest with args set
echo 'Running tests...'
python -m pytest $TEST_ARGS --ignore=tests/integration/ tests/ $COVERAGE_ARGS

# serve out html coverage report
if [ "$COV_REPORT" = "html" ]; then
    echo "Serving out coverage report on port $COV_PORT..."
    python -m http.server --directory htmlcov $COV_PORT
fi

echo 'Done!'