From ee7c5b7933fa469e752ffb49f845d5784197c0ba Mon Sep 17 00:00:00 2001 From: root Date: Sun, 29 Mar 2026 00:20:06 +0000 Subject: [PATCH] ci: add test artifacts and coverage threshold - pytest-html for HTML test reports - coverage HTML report - 90% coverage threshold check - Upload test results and coverage as artifacts - Artifacts available in PR for review --- .gitea/workflows/pr-check.yml | 36 ++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/pr-check.yml b/.gitea/workflows/pr-check.yml index 214c8f9..d14f57f 100644 --- a/.gitea/workflows/pr-check.yml +++ b/.gitea/workflows/pr-check.yml @@ -21,7 +21,41 @@ jobs: run: uv sync --group dev - name: Run tests with coverage - run: uv run pytest tests/unit/ -v --tb=short --cov=src/kwork_api --cov-report=term-missing + run: | + uv run pytest tests/unit/ \ + -v \ + --tb=short \ + --cov=src/kwork_api \ + --cov-report=term-missing \ + --cov-report=html:coverage-html \ + --html=test-results/report.html \ + --self-contained-html + + - name: Check coverage threshold (90%) + run: | + COVERAGE=$(uv run coverage report | grep TOTAL | awk '{print $NF}' | tr -d '%') + echo "Coverage: ${COVERAGE}%" + if (( $(echo "$COVERAGE < 90" | bc -l) )); then + echo "❌ Coverage ${COVERAGE}% is below 90% threshold" + exit 1 + fi + echo "✅ Coverage ${COVERAGE}% meets 90% threshold" + + - name: Upload test results + uses: actions/upload-artifact@v3 + if: always() + with: + name: test-results + path: test-results/ + retention-days: 7 + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + if: always() + with: + name: coverage-report + path: coverage-html/ + retention-days: 7 - name: Run linting run: uv run ruff check src/kwork_api tests/ diff --git a/pyproject.toml b/pyproject.toml index 8090b28..f6b26af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ dev = [ "pytest>=8.0.0", "pytest-cov>=4.0.0", "pytest-asyncio>=0.23.0", + "pytest-html>=4.0.0", "respx>=0.20.0", "ruff>=0.3.0", ]