Skip to content

Commit 962b017

Browse files
committed
Add pytest workflow and update makefile for coverage
Signed-off-by: Mihai Criveti <[email protected]>
1 parent bf596cc commit 962b017

File tree

1 file changed

+62
-61
lines changed

1 file changed

+62
-61
lines changed

.github/workflows/pytest.yml

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
# 🧪 PyTest & Coverage – Quality Gate
33
# ===============================================================
44
#
5-
# This workflow
65
# • runs the full test-suite across three Python versions
76
# • measures branch + line coverage (fails < 40 %)
87
# • uploads the XML/HTML coverage reports as build artifacts
9-
# • generates / commits an SVG badge (main branch only)
10-
# • posts a concise coverage table to the job summary
11-
# • executes on every push/PR to *main* and weekly
8+
#(optionally) generates / commits an SVG badge — kept disabled
9+
# • posts a concise per-file coverage table to the job summary
10+
# • executes on every push / PR to *main* ➕ a weekly cron
1211
# ---------------------------------------------------------------
1312

1413
name: Tests & Coverage
@@ -22,19 +21,19 @@ on:
2221
# - cron: '42 3 * * 1' # Monday 03:42 UTC
2322

2423
permissions:
25-
contents: write # needed to commit the badge
24+
contents: write # needed *only* if the badge-commit step is enabled
2625
checks: write
2726
actions: read
2827

2928
jobs:
3029
test:
31-
name: pytest (${{ matrix.python }})
30+
name: pytest (py${{ matrix.python }})
3231
runs-on: ubuntu-latest
3332

3433
strategy:
3534
fail-fast: false
3635
matrix:
37-
python: ["3.10", "3.11", "3.12"]
36+
python: ["3.11", "3.12"]
3837

3938
env:
4039
PYTHONUNBUFFERED: "1"
@@ -56,19 +55,19 @@ jobs:
5655
uses: actions/setup-python@v5
5756
with:
5857
python-version: ${{ matrix.python }}
59-
cache: "pip"
58+
cache: pip
6059

6160
# -----------------------------------------------------------
62-
# 2️⃣ Install dependencies
61+
# 2️⃣ Install project + dev/test dependencies
6362
# -----------------------------------------------------------
64-
- name: 📦 Install requirements
63+
- name: 📦 Install dependencies
6564
run: |
6665
python -m pip install --upgrade pip
67-
if [ -f requirements-dev.txt ]; then
68-
pip install -r requirements-dev.txt
69-
else
70-
pip install pytest pytest-cov pytest-asyncio coverage[toml]
71-
fi
66+
# Install mcpgateway with its dev extras (defined in pyproject.toml)
67+
# This is the same as: make install-dev
68+
pip install '.[dev]'
69+
# Ensure core testing tools are present (no-ops if already satisfied)
70+
pip install pytest pytest-cov pytest-asyncio coverage[toml]
7271
7372
# -----------------------------------------------------------
7473
# 3️⃣ Run the tests with coverage
@@ -85,58 +84,60 @@ jobs:
8584
8685
# -----------------------------------------------------------
8786
# 4️⃣ Upload coverage artifacts (XML + HTML)
87+
# ––– keep disabled unless you need them –––
8888
# -----------------------------------------------------------
89+
# - name: 📤 Upload coverage.xml
90+
# uses: actions/upload-artifact@v4
91+
# with:
92+
# name: coverage-xml-${{ matrix.python }}
93+
# path: coverage.xml
94+
#
95+
# - name: 📤 Upload HTML coverage
96+
# uses: actions/upload-artifact@v4
97+
# with:
98+
# name: htmlcov-${{ matrix.python }}
99+
# path: htmlcov/
89100

90-
# - name: 📤 Upload coverage.xml
91-
# uses: actions/upload-artifact@v4
92-
# with:
93-
# name: coverage-xml-${{ matrix.python }}
94-
# path: coverage.xml
95-
#
96-
# - name: 📤 Upload HTML coverage
97-
# uses: actions/upload-artifact@v4
98-
# with:
99-
# name: htmlcov-${{ matrix.python }}
100-
# path: htmlcov/
101-
102-
# -----------------------------------------------------------
103-
# 5️⃣ Generate + commit badge (once, on main / highest ver)
104-
# -----------------------------------------------------------
105-
# - name: 📊 Create coverage badge
106-
# if: matrix.python == '3.11' && github.ref == 'refs/heads/main'
107-
# id: make_badge
108-
# uses: tj-actions/coverage-badge@v2
109-
# with:
110-
# coverage-file: coverage.xml # input
111-
# output: .github/badges/coverage.svg # output file
112-
# env:
113-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
# -----------------------------------------------------------
102+
# 5️⃣ Generate + commit badge (main branch, highest Python)
103+
# ––– intentionally commented-out –––
104+
# -----------------------------------------------------------
105+
# - name: 📊 Create coverage badge
106+
# if: matrix.python == '3.11' && github.ref == 'refs/heads/main'
107+
# id: make_badge
108+
# uses: tj-actions/coverage-badge@v2
109+
# with:
110+
# coverage-file: coverage.xml # input
111+
# output: .github/badges/coverage.svg # output file
112+
# env:
113+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
#
115+
# - name: 🚀 Commit badge
116+
# if: steps.make_badge.outputs.badge-updated == 'true'
117+
# uses: stefanzweifel/git-auto-commit-action@v5
118+
# with:
119+
# commit_message: "docs(badge): update coverage badge"
120+
# file_pattern: ".github/badges/coverage.svg"
114121

115-
# - name: 🚀 Commit badge
116-
# if: steps.make_badge.outputs.badge-updated == 'true'
117-
# uses: stefanzweifel/git-auto-commit-action@v5
118-
# with:
119-
# commit_message: "docs(badge): update coverage badge"
120-
# file_pattern: ".github/badges/coverage.svg"
122+
# -----------------------------------------------------------
123+
# 6️⃣ Publish coverage table to the job summary
124+
# -----------------------------------------------------------
121125

122-
# -----------------------------------------------------------
123-
# 6️⃣ Publish coverage table to the job summary
124-
# -----------------------------------------------------------
125126
# - name: 📝 Coverage summary
126127
# if: always()
127128
# run: |
128-
# echo "### Coverage – Python ${{ matrix.python }}" >> $GITHUB_STEP_SUMMARY
129-
# # table header
130-
# echo "| File | Stmts | Miss | Branch | BrMiss | Cover |" >> $GITHUB_STEP_SUMMARY
131-
# echo "|------|------:|-----:|-------:|-------:|------:|" >> $GITHUB_STEP_SUMMARY
132-
# # append trimmed coverage report
129+
# echo "### Coverage – Python ${{ matrix.python }}" >> "$GITHUB_STEP_SUMMARY"
130+
# echo "| File | Stmts | Miss | Branch | BrMiss | Cover |" >> "$GITHUB_STEP_SUMMARY"
131+
# echo "|------|------:|-----:|-------:|-------:|------:|" >> "$GITHUB_STEP_SUMMARY"
133132
# coverage json -q -o cov.json
134133
# python - <<'PY'
135-
# import json, os, pathlib, sys
136-
# d = json.load(open("cov.json"))
137-
# for f in d["files"].values():
138-
# rel = pathlib.Path(f["filename"]).relative_to(pathlib.Path().resolve())
139-
# print(f"| {rel} | {f['summary']['num_statements']} | {f['summary']['missing_lines']} | "
140-
# f"{f['summary']['num_branches']} | {f['summary']['missing_branches']} | "
141-
# f"{f['summary']['percent_covered']:.1f}% |")
142-
# PY >> $GITHUB_STEP_SUMMARY
134+
# import json, pathlib, sys, os
135+
# data = json.load(open("cov.json"))
136+
# root = pathlib.Path().resolve()
137+
# for f in data["files"].values():
138+
# rel = pathlib.Path(f["filename"]).resolve().relative_to(root)
139+
# s = f["summary"]
140+
# print(f"| {rel} | {s['num_statements']} | {s['missing_lines']} | "
141+
# f"{s['num_branches']} | {s['missing_branches']} | "
142+
# f"{s['percent_covered']:.1f}% |")
143+
# PY >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)