name: Code Quality on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] workflow_dispatch: jobs: python-quality: name: Python Code Quality 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.10 - name: Cache pip packages 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 pip install -r requirements-dev.txt - name: Run Black formatting check run: | black --check --diff backend/ - name: Run isort import sorting check run: | isort --check-only --diff backend/ - name: Run Flake8 linting run: | flake8 backend/ --format=junit-xml --output-file=flake8-report.xml - name: Run Pylint static analysis run: | pylint backend/ --exit-zero --output-format=pylint_junit.JunitReporter --output-file=pylint-report.xml - name: Run MyPy type checking run: | mypy backend/ --ignore-missing-imports --junit-xml=mypy-report.xml - name: Run Bandit security linting run: | bandit -r backend/ -f json -o bandit-report.json - name: Run Radon code complexity analysis run: | pip install radon radon cc backend/ -a -nb -o json > radon-report.json - name: Run vulture dead code detection run: | pip install vulture vulture backend/ --min-confidence 70 --format json > vulture-report.json - name: Upload quality reports uses: actions/upload-artifact@v3 with: name: python-quality-reports path: | flake8-report.xml pylint-report.xml mypy-report.xml bandit-report.json radon-report.json vulture-report.json javascript-quality: name: JavaScript Code Quality runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '18' cache: 'npm' cache-dependency-path: frontend/package-lock.json - name: Install dependencies run: | cd frontend npm install - name: Run ESLint run: | cd frontend npm run lint -- --format junit --output-file ../eslint-report.xml - name: Run Prettier formatting check run: | cd frontend npm run format:check - name: Run TypeScript type checking run: | cd frontend npm run type-check - name: Run SonarQube scan uses: sonarqube-quality-gate-action@master env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - name: Upload JavaScript quality reports uses: actions/upload-artifact@v3 with: name: javascript-quality-reports path: | eslint-report.xml test-coverage: name: Test Coverage Analysis runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_PASSWORD: postgres POSTGRES_DB: test_db options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 redis: image: redis:7-alpine options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 6379:6379 steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: python-version: 3.10 - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt pip install -r requirements-dev.txt pip install coverage[toml] coveralls - name: Run tests with coverage run: | cd backend coverage run --source=. manage.py test --verbosity=2 coverage xml coverage report --show-missing coverage html env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db REDIS_URL: redis://localhost:6379/0 SECRET_KEY: test-secret-key-for-ci - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: file: ./coverage.xml flags: unittests name: codecov-umbrella - name: Upload coverage reports uses: actions/upload-artifact@v3 with: name: coverage-reports path: | coverage.xml htmlcov/ performance-analysis: name: Performance Analysis 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.10 - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt pip install line-profiler memory-profiler - name: Run Python performance analysis run: | cd backend python -m cProfile -o profile_output.prof manage.py test --verbosity=0 python -m memory_profiler scripts/memory-profile.py > memory-profile.txt - name: Analyze performance results run: | pip install snakeviz snakeviz profile_output.prof --server - name: Upload performance reports uses: actions/upload-artifact@v3 with: name: performance-reports path: | profile_output.prof memory-profile.txt documentation-quality: name: Documentation Quality 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.10 - name: Install documentation tools run: | python -m pip install --upgrade pip pip install sphinx sphinx-rtd-theme pydoc-markdown pip install -r requirements.txt - name: Check docstring coverage run: | pip install interrogate interrogate backend/ --verbose --ignore-init-method --ignore-module --ignore-private --fail-under=80 - name: Generate documentation run: | cd docs make html - name: Check for broken links run: | pip install linkchecker linkchecker docs/_build/html/index.html - name: Upload documentation uses: actions/upload-artifact@v3 with: name: documentation-build path: docs/_build/html/ code-metrics: name: Code Metrics 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.10 - name: Install analysis tools run: | python -m pip install --upgrade pip pip install lizard radon xenon - name: Calculate code metrics run: | lizard backend/ --csv > lizard-metrics.csv radon raw backend/ --json > radon-metrics.json xenon --max-absolute A --max-modules A --max-average A backend/ > xenon-report.txt - name: Generate quality dashboard run: | python scripts/generate-quality-dashboard.py - name: Upload metrics reports uses: actions/upload-artifact@v3 with: name: code-metrics path: | lizard-metrics.csv radon-metrics.json xenon-report.txt quality-dashboard.html quality-gate: name: Quality Gate runs-on: ubuntu-latest needs: [python-quality, javascript-quality, test-coverage, documentation-quality, code-metrics] if: always() steps: - name: Download all reports uses: actions/download-artifact@v3 - name: Evaluate quality gate run: | python scripts/evaluate-quality-gate.py - name: Create quality issue if gate fails if: failure() uses: actions/github-script@v6 with: script: | github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: `🔍 Quality Gate Failed - ${{ github.sha }}`, body: `Code quality checks failed for commit ${{ github.sha }}. **Branch:** ${{ github.ref }} **Commit:** ${{ github.sha }} **Author:** ${{ github.actor }} Please review the quality reports and address the issues. 📋 **Quality Reports:** - [Python Quality](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - [JavaScript Quality](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - [Test Coverage](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - [Documentation Quality](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - [Code Metrics](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) 🎯 **Action Items:** 1. Review and fix code style issues 2. Address security vulnerabilities 3. Improve test coverage where needed 4. Update documentation 5. Refactor complex code This issue was automatically created by the CI/CD pipeline.`, labels: ['quality', 'bug', 'needs-attention'] });