From 5e26dac62706749b8f1802c0b17b6f4bd16a485e Mon Sep 17 00:00:00 2001 From: codex Date: Thu, 25 Jun 2026 08:22:57 +0000 Subject: [PATCH] ci: add coverage badge updates --- .gitea/workflows/update-badges.yml | 20 ++++++++++++++++++-- README.md | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/update-badges.yml b/.gitea/workflows/update-badges.yml index 091d844..8ef744b 100644 --- a/.gitea/workflows/update-badges.yml +++ b/.gitea/workflows/update-badges.yml @@ -7,7 +7,11 @@ on: paths: - '**.py' - '.pylintrc' + - '.coveragerc' + - '.gitea/workflows/update-badges.yml' - 'pyrightconfig.json' + - 'requirements-dev.txt' + - 'tests/**' workflow_dispatch: jobs: @@ -37,6 +41,14 @@ jobs: echo "score=$SCORE" >> $GITHUB_OUTPUT echo "Pylint score: $SCORE" + - name: Run unit tests and extract coverage + id: coverage + run: | + python -m coverage run -m unittest discover -t . -s tests/unit -v + TOTAL=$(python -m coverage report --format=total) + echo "total=$TOTAL" >> $GITHUB_OUTPUT + echo "Coverage total: $TOTAL" + - name: Run pyright and check errors id: pyright run: | @@ -49,9 +61,13 @@ jobs: run: | PYLINT_SCORE="${{ steps.pylint.outputs.score }}" PYRIGHT_ERRORS="${{ steps.pyright.outputs.errors }}" + COVERAGE_TOTAL="${{ steps.coverage.outputs.total }}" PYLINT_SCORE_ENCODED=$(echo "$PYLINT_SCORE" | sed 's|/|%2F|g') + if [ -n "$COVERAGE_TOTAL" ]; then + sed -i "s|/badge/coverage-[^)]*|/badge/coverage-${COVERAGE_TOTAL}%25-brightgreen|" README.md + fi if [ -n "$PYLINT_SCORE_ENCODED" ]; then sed -i "s|/badge/pylint-[^)]*|/badge/pylint-${PYLINT_SCORE_ENCODED}-brightgreen|" README.md fi @@ -60,7 +76,7 @@ jobs: fi echo "Updated badges:" - grep -E "pylint|pyright" README.md | head -2 + grep -E "coverage|pylint|pyright" README.md | head -3 - name: Commit and push badge updates run: | @@ -73,7 +89,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'"- Coverage: ${{ steps.coverage.outputs.total }}"$'\n'"- Pylint: ${{ steps.pylint.outputs.score }}"$'\n'"- Pyright: ${{ steps.pyright.outputs.errors }} errors"$'\n\n'"[skip ci]" git commit -m "$MSG" git push fi diff --git a/README.md b/README.md index 63dcafe..72336a4 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ # bot-bottle [![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) +[![coverage](https://img.shields.io/badge/coverage-0%25-brightgreen)](https://coverage.readthedocs.io/) [![pylint](https://img.shields.io/badge/pylint-9.93%2F10-brightgreen)](https://github.com/PyCQA/pylint) [![pyright](https://img.shields.io/badge/pyright-0%20errors-brightgreen)](https://github.com/microsoft/pyright)