fix(ci): resolve mypy type errors in client model and content service #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Quality Assurance | |
| on: | |
| pull_request: | |
| branches: [main, develop] | |
| push: | |
| branches: [main, develop] | |
| jobs: | |
| # Stage 1: Linting - If this fails, tests won't run | |
| lint: | |
| name: Code Quality (Linting & Formatting) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: 1.7.1 | |
| virtualenvs-create: true | |
| virtualenvs-in-project: true | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: .venv | |
| key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | |
| - name: Install dependencies | |
| run: poetry install --no-interaction --no-root | |
| - name: Run Black (formatting check) | |
| run: | | |
| poetry run black --check app tests | |
| if [ $? -ne 0 ]; then | |
| echo "❌ FAILED: Code is not formatted with Black" | |
| echo "Run: poetry run black app tests" | |
| exit 1 | |
| fi | |
| - name: Run Ruff (linting) | |
| run: | | |
| poetry run ruff check app tests | |
| if [ $? -ne 0 ]; then | |
| echo "❌ FAILED: Ruff found linting errors" | |
| echo "Run: poetry run ruff check app tests --fix" | |
| exit 1 | |
| fi | |
| - name: Run MyPy (type checking) | |
| run: | | |
| poetry run mypy app | |
| if [ $? -ne 0 ]; then | |
| echo "❌ FAILED: MyPy found type errors" | |
| exit 1 | |
| fi | |
| - name: ✅ Linting Passed | |
| run: echo "All linting checks passed!" | |
| # Stage 2: Tests - Only runs if linting passes | |
| test: | |
| name: Unit & Integration Tests | |
| runs-on: ubuntu-latest | |
| needs: lint # This ensures tests only run after linting passes | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: 1.7.1 | |
| virtualenvs-create: true | |
| virtualenvs-in-project: true | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: .venv | |
| key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | |
| - name: Install dependencies | |
| run: poetry install --no-interaction | |
| - name: Run tests with coverage | |
| run: | | |
| poetry run pytest -v --cov=app --cov-report=xml --cov-report=term-missing | |
| if [ $? -ne 0 ]; then | |
| echo "❌ FAILED: Tests did not pass" | |
| exit 1 | |
| fi | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| fail_ci_if_error: false | |
| - name: Check coverage threshold | |
| run: | | |
| COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') | |
| echo "Coverage: $COVERAGE%" | |
| if (( $(echo "$COVERAGE < 80" | bc -l) )); then | |
| echo "❌ FAILED: Coverage is below 80% ($COVERAGE%)" | |
| exit 1 | |
| fi | |
| echo "✅ Coverage meets threshold: $COVERAGE%" | |
| - name: ✅ Tests Passed | |
| run: echo "All tests passed with adequate coverage!" | |
| # Optional: Security scanning | |
| security: | |
| name: Security Scan | |
| runs-on: ubuntu-latest | |
| needs: [lint, test] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run Bandit (security linter) | |
| uses: tj-actions/bandit@v5.1 | |
| with: | |
| targets: | | |
| app/ | |
| options: "-r -ll -s B104" |