Skip to content

Add 'macae-v4-unittestcases-kd' branch to push triggers in test workflow #861

Add 'macae-v4-unittestcases-kd' branch to push triggers in test workflow

Add 'macae-v4-unittestcases-kd' branch to push triggers in test workflow #861

Workflow file for this run

name: Test Workflow with Coverage
on:
push:
branches:
- main
- demo-v4
- dev-v4
- macae-v4-unittestcases-kd
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
branches:
- main
- demo-v4
- dev-v4
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r src/backend/requirements.txt
- name: Check if test files exist
id: check_tests
run: |
if [ -z "$(find src -type f -name 'test_*.py')" ]; then
echo "No test files found, skipping tests."
echo "skip_tests=true" >> $GITHUB_ENV
else
echo "Test files found, running tests."
echo "skip_tests=false" >> $GITHUB_ENV
fi
- name: Run backend tests with coverage
if: env.skip_tests == 'false'
run: |
python -m pytest src/tests/backend/test_app.py --cov=backend.app --cov-report= --cov-config=.coveragerc -q > /dev/null 2>&1
python -m pytest src/tests/backend --cov=backend --cov-append --cov-report=xml --cov-report= --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py 2>&1 | tee /tmp/pytest_output.txt
python -m coverage report --rcfile=.coveragerc
tail -1 /tmp/pytest_output.txt
# Check coverage threshold
if [ -f coverage.xml ]; then
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib['line-rate']) * 100)")
echo "Coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage is below 80%, failing the job."
exit 1
fi
fi
- name: Skip coverage report if no tests
if: env.skip_tests == 'true'
run: |
echo "Skipping coverage report because no tests were found."