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>
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
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 master2026-06-24 20:33:13 +00:00
emil
deleted branch DEVX-41-fix-badge-generation2026-06-24 20:33:14 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Fixes badge generation that was showing "unknown" for coverage, tests, quality, and version badges across all three repos.
Root Cause
generate_badges.pyusedREPO_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 tosite-packages/devx/tools/generate_badges.py, soREPO_ROOTpointed tosite-packages/instead of the actual repo being tested. This meant:site-packages/tests/(doesn't exist) → no coverage, no test count__init__.pylookup foundsite-packages/devx/__init__.py→ version showed "vunknown" (wrong package)site-packages/src/→ quality badge failedChanges
generate_badges.py— complete rewrite of repo root resolution and metric collection:resolve_repo_root()— usesGITHUB_WORKSPACEenv var oros.getcwd()(same pattern asmolecule_ci_guard.pyfix)detect_package_name()— auto-detects the Python package fromsrc/directory structure (works fordevx,gitea_runner_manager,oblachno_infra)detect_coverage_target()— parses--cov=frompyproject.tomladdopts, falls back tosrc/<package>read_version()— takesrepo_rootparameter, auto-detects packagecollect_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 patterngenerate_badges()— takes optionalrepo_rootparameter, logs repo root and package namepush_badges.py— same_repo_root()fix forupdate_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:GITHUB_WORKSPACE(set by Gitea Actions checkout)src/directory structurepyproject.tomladdopts<package>/__init__.pyCloses DEVX-41
Automated PR Review
No issues found by automated checks.
Auto-merge: If all CI checks pass, this PR will be merged automatically.