feat: migrate test infrastructure to pygit2 for in-process git ops #307
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
| # .github/workflows/ci.yml | |
| name: treemapper CI | |
| 'on': | |
| pull_request: | |
| branches: ['**'] | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| # ============================================================================ | |
| # Pre-commit checks (fast feedback) | |
| # ============================================================================ | |
| pre-commit: | |
| name: Pre-commit hooks | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Cache pre-commit | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.cache/pre-commit | |
| key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pre-commit | |
| pip install -e ".[dev]" | |
| - name: Run pre-commit | |
| run: pre-commit run --all-files | |
| # ============================================================================ | |
| # Linting and Type Checking | |
| # ============================================================================ | |
| lint-type-check: | |
| name: Lint & Type Check | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v6 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.10' | |
| cache: 'pip' | |
| cache-dependency-path: 'pyproject.toml' | |
| - name: Install Linters and Type Checker | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install .[dev] | |
| - name: Run Linters and Formatters Check | |
| run: | | |
| ruff check src tests | |
| black --check src tests | |
| - name: Run Type Checker (Mypy) | |
| run: | | |
| mypy src | |
| # ============================================================================ | |
| # Cross-platform Testing | |
| # ============================================================================ | |
| test: | |
| needs: [pre-commit, lint-type-check] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: ['3.10', '3.11', '3.12', '3.13'] | |
| runs-on: ${{ matrix.os }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v6 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| cache-dependency-path: 'pyproject.toml' | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev,full]" | |
| - name: Run Tests with Coverage | |
| shell: bash | |
| run: | | |
| pytest -v --cov=src/treemapper --cov-report=xml \ | |
| --cov-report=term-missing --cov-branch --junitxml=test-results.xml | |
| - name: Coverage report with threshold | |
| run: | | |
| coverage report --fail-under=80 | |
| - name: Upload coverage reports to Codecov | |
| if: runner.os == 'Linux' && matrix.python-version == '3.12' | |
| uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.xml | |
| flags: integration | |
| fail_ci_if_error: false | |
| verbose: true | |
| - name: Upload coverage for SonarCloud | |
| uses: actions/upload-artifact@v7 | |
| if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' | |
| with: | |
| name: coverage-report | |
| path: | | |
| coverage.xml | |
| test-results.xml | |
| retention-days: 1 | |
| # ============================================================================ | |
| # Mutation Testing (test effectiveness validation) | |
| # Evidence: Mutation score correlates with real fault detection | |
| # ============================================================================ | |
| mutation-testing: | |
| name: Mutation Testing | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev]" | |
| - name: Run mutation testing | |
| run: | | |
| mutmut run || true | |
| mutmut results || true | |
| # ============================================================================ | |
| # Complexity & Maintainability Metrics | |
| # Evidence: Cyclomatic complexity correlates with defect density | |
| # ============================================================================ | |
| complexity-checks: | |
| name: Complexity & Maintainability Analysis | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev]" | |
| - name: Check cyclomatic complexity | |
| run: | | |
| echo "=== Cyclomatic Complexity Report ===" | |
| radon cc src/treemapper/ --min B --show-complexity --total-average | |
| - name: Check maintainability index | |
| run: | | |
| echo "=== Maintainability Index Report ===" | |
| radon mi src/treemapper/ --min B --show | |
| - name: Fail on high complexity | |
| run: | | |
| radon cc src/treemapper/ --min C --total-average || \ | |
| (echo "High complexity detected" && exit 1) | |
| # ============================================================================ | |
| # Architecture & Import Contracts | |
| # Evidence: Coupling/architecture violations correlate with defect density | |
| # ============================================================================ | |
| architecture-checks: | |
| name: Architecture & Import Contracts | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev]" | |
| - name: Check import contracts | |
| run: lint-imports |