Skip to content

Commit 6c55ebc

Browse files
authored
Refactor Python version and badge update script
Updated Python version extraction and badge update logic in README.md.
1 parent b3355b0 commit 6c55ebc

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

.github/workflows/tag_and_publish.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ jobs:
2525
python -m pip install -e . --group dev --no-cache-dir
2626
- name: Get Python version and Update README.md
2727
run: |
28-
python_version=$(grep "requires-python" pyproject.toml | grep -o ">=[^\"]*")
29-
python_badge=$(grep '^\!\[Python\]' README.md | sed -n 's/.*\(python-[^)]*\).*/\1/p')
30-
new_python_badge="python-$python_version-blue?logo=python"
31-
sed -i "s/$python_badge/$new_python_badge/g" README.md
28+
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."
33+
exit 0
34+
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
3240
- name: Get interrogate values and Update README.md
3341
run: |
3442
interrogate_val=$(interrogate . | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}')

0 commit comments

Comments
 (0)