|
| 1 | +# =============================================================== |
| 2 | +# 🧪🦀 PyTest With Rust Build - Quality Gate |
| 3 | +# =============================================================== |
| 4 | +# |
| 5 | +# - builds/install Rust-backed components required by the Python suite |
| 6 | +# - runs the full pytest suite with Rust enabled |
| 7 | +# - measures branch + line coverage (fails < 90% main, < 35% doctest) |
| 8 | +# - posts changed-line coverage for PRs |
| 9 | +# --------------------------------------------------------------- |
| 10 | + |
| 11 | +name: Tests & Coverage (Rust) |
| 12 | + |
| 13 | +on: |
| 14 | + push: |
| 15 | + branches: ["main"] |
| 16 | + paths: |
| 17 | + - "crates/**" |
| 18 | + - "Cargo.toml" |
| 19 | + - "Cargo.lock" |
| 20 | + - "rust-toolchain.toml" |
| 21 | + - "deny.toml" |
| 22 | + - "tests/e2e_rust/**" |
| 23 | + - ".github/workflows/pytest-rust.yml" |
| 24 | + pull_request: |
| 25 | + types: [opened, synchronize, ready_for_review] |
| 26 | + branches: ["main"] |
| 27 | + paths: |
| 28 | + - "crates/**" |
| 29 | + - "Cargo.toml" |
| 30 | + - "Cargo.lock" |
| 31 | + - "rust-toolchain.toml" |
| 32 | + - "deny.toml" |
| 33 | + - "tests/e2e_rust/**" |
| 34 | + - ".github/workflows/pytest-rust.yml" |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +permissions: |
| 41 | + contents: read |
| 42 | + |
| 43 | +jobs: |
| 44 | + test: |
| 45 | + if: github.event_name != 'pull_request' || !github.event.pull_request.draft |
| 46 | + name: pytest-rust |
| 47 | + runs-on: ubuntu-latest |
| 48 | + timeout-minutes: 40 |
| 49 | + services: |
| 50 | + redis: |
| 51 | + image: redis:7-bookworm |
| 52 | + ports: |
| 53 | + - 6379:6379 |
| 54 | + options: >- |
| 55 | + --health-cmd "redis-cli ping" |
| 56 | + --health-interval 5s |
| 57 | + --health-timeout 3s |
| 58 | + --health-retries 20 |
| 59 | +
|
| 60 | + env: |
| 61 | + PYTHONUNBUFFERED: "1" |
| 62 | + PIP_DISABLE_PIP_VERSION_CHECK: "1" |
| 63 | + REQUIRE_RUST: "1" |
| 64 | + AUTH_ENCRYPTION_SECRET: ci-rust-auth-encryption-secret-1234567890 # pragma: allowlist secret |
| 65 | + REDIS_URL: redis://127.0.0.1:6379/0 |
| 66 | + MCP_RUST_REDIS_URL: redis://127.0.0.1:6379/0 |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: ⬇️ Checkout code |
| 70 | + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 |
| 71 | + with: |
| 72 | + persist-credentials: false |
| 73 | + fetch-depth: 0 |
| 74 | + |
| 75 | + - name: 🐍 Setup Python 3.12 |
| 76 | + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 77 | + with: |
| 78 | + python-version: "3.12" |
| 79 | + cache: pip |
| 80 | + |
| 81 | + - name: ⚡ Install uv |
| 82 | + uses: astral-sh/setup-uv@d0d8abe699bfb85fec6de9f7adb5ae17292296ff # v6 |
| 83 | + with: |
| 84 | + version: "0.10.11" |
| 85 | + python-version: "3.12" |
| 86 | + |
| 87 | + - name: 🦀 Install Rust stable |
| 88 | + run: | |
| 89 | + rustup toolchain install stable |
| 90 | + rustup default stable |
| 91 | +
|
| 92 | + - name: 📦 Cache Cargo dependencies |
| 93 | + uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 |
| 94 | + with: |
| 95 | + path: | |
| 96 | + ~/.cargo/registry |
| 97 | + ~/.cargo/git |
| 98 | + target |
| 99 | + key: ${{ runner.os }}-cargo-pytest-rust-${{ hashFiles('**/Cargo.lock', 'Cargo.toml') }} |
| 100 | + restore-keys: | |
| 101 | + ${{ runner.os }}-cargo-pytest-rust- |
| 102 | +
|
| 103 | + - name: 🔨 Build Rust extensions |
| 104 | + run: make rust-install && make rust-verify-stubs |
| 105 | + |
| 106 | + - name: 🧪 Run pytest |
| 107 | + run: | |
| 108 | + uv run --extra plugins pytest -n 0 \ |
| 109 | + --durations=5 \ |
| 110 | + --ignore=tests/fuzz \ |
| 111 | + --ignore=tests/e2e/test_entra_id_integration.py \ |
| 112 | + --cov=mcpgateway \ |
| 113 | + --cov-report=xml \ |
| 114 | + --cov-report=html \ |
| 115 | + --cov-report=term \ |
| 116 | + --cov-branch \ |
| 117 | + --cov-fail-under=95 |
| 118 | +
|
| 119 | + - name: 📈 Diff-cover (changed lines) |
| 120 | + if: github.event_name == 'pull_request' |
| 121 | + run: | |
| 122 | + uv run diff-cover coverage.xml \ |
| 123 | + --compare-branch=origin/${{ github.base_ref }} \ |
| 124 | + --fail-under=93 |
| 125 | +
|
| 126 | + - name: 📊 Doctest coverage with threshold |
| 127 | + run: | |
| 128 | + uv run --extra plugins pytest -n 0 \ |
| 129 | + --doctest-modules mcpgateway/ \ |
| 130 | + --cov=mcpgateway \ |
| 131 | + --cov-report=term \ |
| 132 | + --cov-report=json:doctest-coverage.json \ |
| 133 | + --cov-fail-under=30 \ |
| 134 | + --tb=short |
0 commit comments