Skip to content

Commit addbd79

Browse files
authored
Update README.md with interrogate badge values
1 parent dcee14c commit addbd79

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

.github/workflows/tag_and_publish.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install -e . --group dev --no-cache-dir
26-
- name: Get Python version and Update README.md
26+
- name: Get interrogate values and Update README.md
2727
run: |
2828
set -euo pipefail
29-
python_version=$(grep -E '^\s*requires-python\s*=' pyproject.toml | grep -oE '>=([^"]+)' | head -n1)
30-
python_badge=$(grep -E '^\!\[Python\]' README.md | sed -n 's/.*\(python-[^)]*\).*/\1/p' | head -n1 || true)
31-
if [[ -z "${python_badge}" ]]; then
32-
echo "Python badge not found in README.md (expected a line starting with '![Python]' containing 'python-...'). Skipping."
29+
if ! interrogate_out="$(interrogate . 2>/dev/null)"; then
30+
echo "interrogate failed under this Python version; skipping interrogate badge update."
31+
exit 0
32+
fi
33+
interrogate_val="$(printf "%s" "$interrogate_out" | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}' || true)"
34+
if [[ -z "${interrogate_val:-}" ]]; then
35+
echo "Could not parse interrogate output; skipping interrogate badge update."
36+
exit 0
37+
fi
38+
interrogate_badge=$(grep '^\!\[Interrogate\]' README.md | sed -n 's/.*\(interrogate-[^)]*\).*/\1/p' || true)
39+
if [[ -z "${interrogate_badge:-}" ]]; then
40+
echo "Interrogate badge not found in README.md; skipping."
3341
exit 0
3442
fi
35-
new_python_badge="python-${python_version}-blue?logo=python"
36-
# Escape for sed replacement (handles '/', '&', etc.)
37-
esc_old=$(printf '%s' "$python_badge" | sed 's/[\/&]/\\&/g')
38-
esc_new=$(printf '%s' "$new_python_badge" | sed 's/[\/&]/\\&/g')
39-
sed -i "s/${esc_old}/${esc_new}/g" README.md
43+
if (( $(echo "$interrogate_val >= 90.00" | bc -l) )); then
44+
new_interrogate_badge="interrogate-$interrogate_val%25-brightgreen"
45+
elif (( $(echo "$interrogate_val < 80.00" | bc -l) )); then
46+
new_interrogate_badge="interrogate-$interrogate_val%25-red"
47+
else
48+
new_interrogate_badge="interrogate-$interrogate_val%25-yellow"
49+
fi
50+
sed -i "s/$interrogate_badge/$new_interrogate_badge/g" README.md
4051
- name: Get interrogate values and Update README.md
4152
run: |
4253
interrogate_val=$(interrogate . | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}')

0 commit comments

Comments
 (0)