From 50f5b3aa7fcd7424fe72357b4d8d0340162d60f6 Mon Sep 17 00:00:00 2001 From: didericis Date: Thu, 25 Jun 2026 15:13:44 -0400 Subject: [PATCH] ci(badges): add coverage percentage to quality badges The update-badges workflow only refreshed pylint and pyright. Add a coverage step that runs the unit suite under coverage.py, extracts the TOTAL percentage, and updates a new coverage badge in the README. Also trigger the workflow on .coveragerc changes. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01NkwFXLFff9PYPy4wgVBJp9 --- .gitea/workflows/update-badges.yml | 17 +++++++++++++++-- README.md | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/update-badges.yml b/.gitea/workflows/update-badges.yml index 091d844..7db0341 100644 --- a/.gitea/workflows/update-badges.yml +++ b/.gitea/workflows/update-badges.yml @@ -8,6 +8,7 @@ on: - '**.py' - '.pylintrc' - 'pyrightconfig.json' + - '.coveragerc' workflow_dispatch: jobs: @@ -45,10 +46,19 @@ jobs: echo "errors=$ERRORS" >> $GITHUB_OUTPUT echo "Pyright errors: $ERRORS" + - name: Run coverage and extract percentage + id: coverage + run: | + python -m coverage run -m unittest discover -t . -s tests/unit > /dev/null 2>&1 || true + PERCENT=$(python -m coverage report 2>/dev/null | grep '^TOTAL' | grep -oP '\d+(?=%)' | tail -1) + echo "percent=$PERCENT" >> $GITHUB_OUTPUT + echo "Coverage: $PERCENT%" + - name: Update badges in README run: | PYLINT_SCORE="${{ steps.pylint.outputs.score }}" PYRIGHT_ERRORS="${{ steps.pyright.outputs.errors }}" + COVERAGE_PERCENT="${{ steps.coverage.outputs.percent }}" PYLINT_SCORE_ENCODED=$(echo "$PYLINT_SCORE" | sed 's|/|%2F|g') @@ -58,9 +68,12 @@ jobs: if [ -n "$PYRIGHT_ERRORS" ]; then sed -i "s|/badge/pyright-[^)]*|/badge/pyright-${PYRIGHT_ERRORS}%20errors-brightgreen|" README.md fi + if [ -n "$COVERAGE_PERCENT" ]; then + sed -i "s|/badge/coverage-[^)]*|/badge/coverage-${COVERAGE_PERCENT}%25-brightgreen|" README.md + fi echo "Updated badges:" - grep -E "pylint|pyright" README.md | head -2 + grep -E "pylint|pyright|coverage" README.md | head -3 - name: Commit and push badge updates run: | @@ -73,7 +86,7 @@ jobs: else echo "Badge changes detected, committing..." git add README.md - MSG="chore: update quality badges"$'\n\n'"- Pylint: ${{ steps.pylint.outputs.score }}"$'\n'"- Pyright: ${{ steps.pyright.outputs.errors }} errors"$'\n\n'"[skip ci]" + MSG="chore: update quality badges"$'\n\n'"- Pylint: ${{ steps.pylint.outputs.score }}"$'\n'"- Pyright: ${{ steps.pyright.outputs.errors }} errors"$'\n'"- Coverage: ${{ steps.coverage.outputs.percent }}%"$'\n\n'"[skip ci]" git commit -m "$MSG" git push fi diff --git a/README.md b/README.md index 70539ac..199fc53 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![test](https://gitea.dideric.is/didericis/bot-bottle/actions/workflows/test.yml/badge.svg?branch=main)](https://gitea.dideric.is/didericis/bot-bottle/actions?workflow=test.yml) [![pylint](https://img.shields.io/badge/pylint-9.93%2F10-brightgreen)](https://github.com/PyCQA/pylint) [![pyright](https://img.shields.io/badge/pyright-1%20errors-brightgreen)](https://github.com/microsoft/pyright) +[![coverage](https://img.shields.io/badge/coverage-unknown-lightgrey)](https://coverage.readthedocs.io/) **Problem:** Developer wants to run a coding agent without supervision, but they don't want a prompt injected or misbehaving agent wrecking their environment or exfiltrating sensitive data.