Skip to content

build(deps-dev): update ruff requirement from ^0.3.0 to ^0.14.1 #62

build(deps-dev): update ruff requirement from ^0.3.0 to ^0.14.1

build(deps-dev): update ruff requirement from ^0.3.0 to ^0.14.1 #62

name: Docstring Coverage
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
docstring-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Check docstring coverage
run: |
python scripts/check_docstring_coverage.py --min-coverage 80
- name: Generate docstring coverage badge
run: |
python -c "
import re
import subprocess
import json
# Run the docstring coverage script and capture output
result = subprocess.run(
['python', 'scripts/check_docstring_coverage.py', '--dir', 'src'],
capture_output=True,
text=True
)
# Extract the overall coverage percentage
match = re.search(r'Overall docstring coverage: (\d+\.\d+)%', result.stdout)
if match:
coverage = float(match.group(1))
# Determine badge color
color = 'red'
if coverage >= 90:
color = 'brightgreen'
elif coverage >= 80:
color = 'green'
elif coverage >= 70:
color = 'yellowgreen'
elif coverage >= 60:
color = 'yellow'
elif coverage >= 50:
color = 'orange'
# Create badge URL
badge_url = f'https://img.shields.io/badge/docstring%20coverage-{coverage:.1f}%25-{color}'
# Update README.md
with open('README.md', 'r') as f:
readme = f.read()
# Look for existing docstring coverage badge
docstring_badge_pattern = r'!\[Docstring Coverage\]\(https://img\.shields\.io/badge/docstring%20coverage-[\d\.]+%25-[a-z]+\)'
if re.search(docstring_badge_pattern, readme):
# Replace existing badge
readme = re.sub(docstring_badge_pattern, f'![Docstring Coverage]({badge_url})', readme)
else:
# Look for badge section to add to
badge_section = re.search(r'(!\[[^\]]+\]\([^\)]+\)[ \t]*)+', readme)
if badge_section:
# Add to existing badges
end_pos = badge_section.end()
readme = readme[:end_pos] + f' ![Docstring Coverage]({badge_url})' + readme[end_pos:]
else:
# Add after first line
first_line_end = readme.find('\\n')
if first_line_end != -1:
readme = readme[:first_line_end+1] + f'\\n![Docstring Coverage]({badge_url})\\n' + readme[first_line_end+1:]
else:
readme = readme + f'\\n\\n![Docstring Coverage]({badge_url})\\n'
with open('README.md', 'w') as f:
f.write(readme)
print(f'Updated README.md with docstring coverage badge: {coverage:.1f}%')
else:
print('Could not extract docstring coverage percentage')
"
- name: Commit updated README with docstring coverage badge
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
git diff --quiet && git diff --staged --quiet || (
git commit -m "docs: update docstring coverage badge [skip ci]"
git push
)
permissions:
contents: write