Skip to content

Fix tests to work with improved code - all 82 tests pass #1

Fix tests to work with improved code - all 82 tests pass

Fix tests to work with improved code - all 82 tests pass #1

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unit tests
run: |
python -m pytest tests/test_models.py -v --cov=models --cov-report=xml --cov-report=term
- name: Run integration tests
run: |
python -m pytest tests/test_app.py -v --cov=app --cov-append --cov-report=xml --cov-report=term
- name: Run performance tests
run: |
python -m pytest tests/test_performance.py -v --tb=short -p no:warnings
continue-on-error: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
code-quality:
name: Code Quality Checks
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 flake8 pylint black
- name: Run flake8
run: |
flake8 app.py models.py --max-line-length=120 --ignore=E501,W503 --count --show-source --statistics || true
- name: Run black (check formatting)
run: |
black --check app.py models.py --line-length=120 || true
- name: Run pylint
run: |
pylint app.py models.py --max-line-length=120 --disable=C0111,C0103,R0903 || true
security-scan:
name: Security Scan
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 bandit safety
- name: Run Bandit security scan
run: |
bandit -r . -f json -o bandit-report.json || true
bandit -r . || true
- name: Run Safety check for vulnerable dependencies
run: |
safety check --json || true
coverage-report:
name: Generate Coverage Report
runs-on: ubuntu-latest
if: always() # Run even if tests fail
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 requirements.txt
- name: Generate full coverage report
run: |
python -m pytest tests/ -v --cov=. --cov-report=html --cov-report=term --cov-report=xml || echo "Tests had failures but continuing..."
continue-on-error: true
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
if: always() # Upload even if previous step had errors
with:
name: coverage-report
path: htmlcov/
if-no-files-found: warn
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
performance-benchmark:
name: Performance Benchmarks
runs-on: ubuntu-latest
if: always() # Run even if previous jobs fail
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 requirements.txt
- name: Run performance tests
run: |
python -m pytest tests/test_performance.py -v -s --tb=short -p no:warnings
continue-on-error: true
- name: Upload performance results
uses: actions/upload-artifact@v4
if: always()
with:
name: performance-results
path: |
*.prof
performance_*.txt
if-no-files-found: ignore
build-status:
name: Build Status Summary
runs-on: ubuntu-latest
needs: [code-quality, coverage-report]
if: always()
steps:
- name: Check build status
run: |
echo "Test Status: ${{ needs.test.result }}"
echo "Code Quality Status: ${{ needs.code-quality.result }}"
echo "Coverage Report Status: ${{ needs.coverage-report.result }}"
- name: Set badge status
run: |
if [ "${{ needs.test.result }}" == "success" ] && [ "${{ needs.code-quality.result }}" == "success" ]; then
echo "✅ Build Passed"
else
echo "❌ Build Failed"
fi