DEVX-41: Fix badge generation: REPO_ROOT, auto-detect package, error feedback #65

Merged
emil merged 0 commits from DEVX-41-fix-badge-generation into master 2026-06-24 20:33:13 +00:00
Owner

Summary

Fixes badge generation that was showing "unknown" for coverage, tests, quality, and version badges across all three repos.

Root Cause

generate_badges.py used REPO_ROOT = Path(__file__).resolve().parents[4] to find the repo root. When devx is installed as a pip package in CI (which is how grm and infra consume it), __file__ resolves to site-packages/devx/tools/generate_badges.py, so REPO_ROOT pointed to site-packages/ instead of the actual repo being tested. This meant:

  • pytest ran against site-packages/tests/ (doesn't exist) → no coverage, no test count
  • __init__.py lookup found site-packages/devx/__init__.py → version showed "vunknown" (wrong package)
  • ruff/pyright/bandit ran against site-packages/src/ → quality badge failed

Changes

generate_badges.py — complete rewrite of repo root resolution and metric collection:

  • resolve_repo_root() — uses GITHUB_WORKSPACE env var or os.getcwd() (same pattern as molecule_ci_guard.py fix)
  • detect_package_name() — auto-detects the Python package from src/ directory structure (works for devx, gitea_runner_manager, oblachno_infra)
  • detect_coverage_target() — parses --cov= from pyproject.toml addopts, falls back to src/<package>
  • read_version() — takes repo_root parameter, auto-detects package
  • collect_coverage_and_tests() — emits warnings with stderr excerpt on failure (so CI logs explain WHY it's "unknown")
  • collect_quality() — skips tools that are not installed (counts as pass, logs warning)
  • collect_doc_coverage() — same warning pattern
  • generate_badges() — takes optional repo_root parameter, logs repo root and package name

push_badges.py — same _repo_root() fix for update_readme_with_badge_sha()

Tests — 100% coverage on both modules, new tests for:

  • resolve_repo_root() / _repo_root() (GITHUB_WORKSPACE, cwd fallback, invalid workspace)
  • detect_package_name() (with/without src, non-dir entries, alphabetical)
  • detect_coverage_target() (pyproject parse, fallback, no package)
  • collect_coverage_and_tests() (success, failure, no target)
  • collect_quality() (all pass, lint fail, tool not installed)
  • read_version() (success, no version, no package, init missing)

Reusability

This module now works correctly across all three repos (devx, grm, infra) without per-repo configuration. It auto-detects:

  • Repo root from GITHUB_WORKSPACE (set by Gitea Actions checkout)
  • Package name from src/ directory structure
  • Coverage target from pyproject.toml addopts
  • Version from <package>/__init__.py

Closes DEVX-41

## Summary Fixes badge generation that was showing "unknown" for coverage, tests, quality, and version badges across all three repos. ### Root Cause `generate_badges.py` used `REPO_ROOT = Path(__file__).resolve().parents[4]` to find the repo root. When devx is installed as a pip package in CI (which is how grm and infra consume it), `__file__` resolves to `site-packages/devx/tools/generate_badges.py`, so `REPO_ROOT` pointed to `site-packages/` instead of the actual repo being tested. This meant: - pytest ran against `site-packages/tests/` (doesn't exist) → no coverage, no test count - `__init__.py` lookup found `site-packages/devx/__init__.py` → version showed "vunknown" (wrong package) - ruff/pyright/bandit ran against `site-packages/src/` → quality badge failed ### Changes **`generate_badges.py`** — complete rewrite of repo root resolution and metric collection: - `resolve_repo_root()` — uses `GITHUB_WORKSPACE` env var or `os.getcwd()` (same pattern as `molecule_ci_guard.py` fix) - `detect_package_name()` — auto-detects the Python package from `src/` directory structure (works for `devx`, `gitea_runner_manager`, `oblachno_infra`) - `detect_coverage_target()` — parses `--cov=` from `pyproject.toml` addopts, falls back to `src/<package>` - `read_version()` — takes `repo_root` parameter, auto-detects package - `collect_coverage_and_tests()` — emits warnings with stderr excerpt on failure (so CI logs explain WHY it's "unknown") - `collect_quality()` — skips tools that are not installed (counts as pass, logs warning) - `collect_doc_coverage()` — same warning pattern - `generate_badges()` — takes optional `repo_root` parameter, logs repo root and package name **`push_badges.py`** — same `_repo_root()` fix for `update_readme_with_badge_sha()` **Tests** — 100% coverage on both modules, new tests for: - `resolve_repo_root()` / `_repo_root()` (GITHUB_WORKSPACE, cwd fallback, invalid workspace) - `detect_package_name()` (with/without src, non-dir entries, alphabetical) - `detect_coverage_target()` (pyproject parse, fallback, no package) - `collect_coverage_and_tests()` (success, failure, no target) - `collect_quality()` (all pass, lint fail, tool not installed) - `read_version()` (success, no version, no package, init missing) ### Reusability This module now works correctly across all three repos (`devx`, `grm`, `infra`) without per-repo configuration. It auto-detects: - Repo root from `GITHUB_WORKSPACE` (set by Gitea Actions checkout) - Package name from `src/` directory structure - Coverage target from `pyproject.toml` addopts - Version from `<package>/__init__.py` Closes DEVX-41
emil reviewed 2026-06-24 20:32:25 +00:00
emil left a comment
Author
Owner

Automated PR Review

  • Architecture compliance: OK
  • Best practices: OK
  • Security: OK
  • i18n: OK
  • Resource management: OK
  • Documentation: WARNING — source files changed but no docs updated
  • Tests: OK
  • Commit conventions: OK

No issues found by automated checks.


Auto-merge: If all CI checks pass, this PR will be merged automatically.

## Automated PR Review - Architecture compliance: OK - Best practices: OK - Security: OK - i18n: OK - Resource management: OK - Documentation: WARNING — source files changed but no docs updated - Tests: OK - Commit conventions: OK No issues found by automated checks. --- **Auto-merge:** If all CI checks pass, this PR will be merged automatically.
emil merged commit 95adf86895 into master 2026-06-24 20:33:13 +00:00
emil deleted branch DEVX-41-fix-badge-generation 2026-06-24 20:33:14 +00:00
Sign in to join this conversation.