Skip to content

Refactor _auto_bar_width and add _auto_bar_width_columnar #312

Refactor _auto_bar_width and add _auto_bar_width_columnar

Refactor _auto_bar_width and add _auto_bar_width_columnar #312

Workflow file for this run

name: Coverage
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Run tests with coverage
run: |
python -m pytest --cov=balance --cov-report=xml --cov-report=html --cov-report=term-missing
- name: Upload coverage reports to artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/
- name: Upload coverage XML
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-xml
path: coverage.xml
- name: Display coverage percentage
run: |
coverage report --precision=2
- name: Update coverage badge
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
GIST_TOKEN: ${{ secrets.GIST_TOKEN_COVERAGE }}
run: |
COVERAGE=$(coverage report --precision=2 | grep TOTAL | awk '{print $NF}' | sed 's/%//')
echo "Coverage: $COVERAGE%"
# Determine badge color based on coverage (finer gradient)
if (( $(echo "$COVERAGE == 100" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 97" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COVERAGE >= 95" | bc -l) )); then
COLOR="yellowgreen"
elif (( $(echo "$COVERAGE >= 90" | bc -l) )); then
COLOR="yellow"
elif (( $(echo "$COVERAGE >= 80" | bc -l) )); then
COLOR="orange"
else
COLOR="red"
fi
# Create badge JSON content as a string (escape quotes for nested JSON)
BADGE_CONTENT="{\\\"schemaVersion\\\": 1, \\\"label\\\": \\\"coverage\\\", \\\"message\\\": \\\"${COVERAGE}%\\\", \\\"color\\\": \\\"${COLOR}\\\"}"
# Update the Gist (content must be a JSON-escaped string)
curl -s -X PATCH \
-H "Authorization: token $GIST_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/gists/89d05034d314ebda47c1e16607e1ee22 \
-d "{\"files\": {\"coverage-balance.json\": {\"content\": \"$BADGE_CONTENT\"}}}" | head -20
echo ""
echo "Badge updated successfully!"