d89d389bef
Surface the metric ADR 0004 says matters — the critical security/logic core, currently 95% — as a README badge, distinct from the informational global `coverage` badge. - scripts/critical-modules.txt: single source of truth for the core module list. scripts/coverage.sh now reads it (instead of a hardcoded string) and update-badges.yml reads the same file, so the badge and the `critical` report cannot drift. - update-badges.yml: a `core coverage` step reuses the unit-coverage data (every core module is unit-tested, so unit-only is accurate for it) and sed-updates the new badge, like the existing ones. - README: `core coverage 95%` badge linking to ADR 0004 so a reader can find out what "core" means. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NkwFXLFff9PYPy4wgVBJp9
108 lines
4.2 KiB
YAML
108 lines
4.2 KiB
YAML
name: Update Quality Badges
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- '**.py'
|
|
- '.pylintrc'
|
|
- 'pyrightconfig.json'
|
|
- '.coveragerc'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
update-badges:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.12'
|
|
|
|
- name: Install dev dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements-dev.txt
|
|
|
|
- name: Run pylint and extract score
|
|
id: pylint
|
|
run: |
|
|
PYLINT_OUTPUT=$(python -m pylint bot_bottle/ 2>&1) || true
|
|
SCORE=$(echo "$PYLINT_OUTPUT" | grep -oP '(?<=rated at )\d+\.\d+/10' | head -1)
|
|
echo "score=$SCORE" >> $GITHUB_OUTPUT
|
|
echo "Pylint score: $SCORE"
|
|
|
|
- name: Run pyright and check errors
|
|
id: pyright
|
|
run: |
|
|
PYRIGHT_OUTPUT=$(python -m pyright 2>&1) || true
|
|
ERRORS=$(echo "$PYRIGHT_OUTPUT" | grep -oP '\d+(?= error)' | head -1)
|
|
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: Extract core (critical-module) coverage percentage
|
|
id: core_coverage
|
|
run: |
|
|
# Reuses the .coverage data from the previous step. The core list is
|
|
# the single source of truth in scripts/critical-modules.txt; every
|
|
# core module is unit-tested, so the unit-only run is accurate for it.
|
|
INCLUDE=$(grep -vE '^[[:space:]]*(#|$)' scripts/critical-modules.txt | paste -sd, -)
|
|
PERCENT=$(python -m coverage report --include="$INCLUDE" 2>/dev/null | grep '^TOTAL' | grep -oP '\d+(?=%)' | tail -1)
|
|
echo "percent=$PERCENT" >> $GITHUB_OUTPUT
|
|
echo "Core 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 }}"
|
|
CORE_COVERAGE_PERCENT="${{ steps.core_coverage.outputs.percent }}"
|
|
|
|
PYLINT_SCORE_ENCODED=$(echo "$PYLINT_SCORE" | sed 's|/|%2F|g')
|
|
|
|
if [ -n "$PYLINT_SCORE_ENCODED" ]; then
|
|
sed -i "s|/badge/pylint-[^)]*|/badge/pylint-${PYLINT_SCORE_ENCODED}-brightgreen|" README.md
|
|
fi
|
|
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
|
|
if [ -n "$CORE_COVERAGE_PERCENT" ]; then
|
|
sed -i "s|/badge/core%20coverage-[^)]*|/badge/core%20coverage-${CORE_COVERAGE_PERCENT}%25-brightgreen|" README.md
|
|
fi
|
|
|
|
echo "Updated badges:"
|
|
grep -E "pylint|pyright|coverage" README.md | head -4
|
|
|
|
- name: Commit and push badge updates
|
|
run: |
|
|
git config --local user.email "action@gitea.local"
|
|
git config --local user.name "Quality Badge Bot"
|
|
|
|
# Check if there are changes
|
|
if git diff --quiet README.md; then
|
|
echo "No badge changes needed"
|
|
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'"- Coverage: ${{ steps.coverage.outputs.percent }}%"$'\n'"- Core coverage: ${{ steps.core_coverage.outputs.percent }}%"$'\n\n'"[skip ci]"
|
|
git commit -m "$MSG"
|
|
git push
|
|
fi
|