🐛 fix: proper markdown format for coverage badges
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 10s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m8s

This commit is contained in:
2026-04-08 16:59:58 +02:00
parent 41e7183603
commit 51e98a0185

View File

@@ -35,18 +35,27 @@ else
COLOR="red" COLOR="red"
fi fi
# Create different badge URLs based on type # Create different badge URLs and markdown format based on type
if [ "$BADGE_TYPE" = "bdd" ]; then if [ "$BADGE_TYPE" = "bdd" ]; then
BADGE_URL="https://img.shields.io/badge/BDD_Coverage-${COVERAGE}%-${COLOR}?style=flat-square" BADGE_URL="https://img.shields.io/badge/BDD_Coverage-${COVERAGE}%-${COLOR}?style=flat-square"
BADGE_MARKDOWN="[![BDD Coverage](${BADGE_URL})](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)"
SEARCH_PATTERN="BDD_Coverage-.*-.*?style=flat-square" SEARCH_PATTERN="BDD_Coverage-.*-.*?style=flat-square"
elif [ "$BADGE_TYPE" = "unit" ]; then elif [ "$BADGE_TYPE" = "unit" ]; then
BADGE_URL="https://img.shields.io/badge/Unit_Coverage-${COVERAGE}%-${COLOR}?style=flat-square" BADGE_URL="https://img.shields.io/badge/Unit_Coverage-${COVERAGE}%-${COLOR}?style=flat-square"
BADGE_MARKDOWN="[![Unit Coverage](${BADGE_URL})](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)"
SEARCH_PATTERN="Unit_Coverage-.*-.*?style=flat-square" SEARCH_PATTERN="Unit_Coverage-.*-.*?style=flat-square"
else else
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square" BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square"
BADGE_MARKDOWN="[![Coverage](${BADGE_URL})](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)"
SEARCH_PATTERN="coverage-.*-.*?style=flat-square" SEARCH_PATTERN="coverage-.*-.*?style=flat-square"
fi fi
# Clean up any malformed badge lines from previous runs
# Remove lines starting with "nhttps://" or "https://" that aren't proper markdown
sed -i.bak '/^nhttps:\/\/.*img.shields.io.*Coverage/d' README.md 2>/dev/null || true
sed -i.bak '/^https:\/\/.*img.shields.io.*Coverage/d' README.md 2>/dev/null || true
rm -f README.md.bak
# Only update if coverage has actually changed # Only update if coverage has actually changed
if grep -q "${BADGE_TYPE}_Coverage-${COVERAGE}%" README.md || grep -q "coverage-${COVERAGE}%" README.md; then if grep -q "${BADGE_TYPE}_Coverage-${COVERAGE}%" README.md || grep -q "coverage-${COVERAGE}%" README.md; then
echo "Coverage badge already up to date at ${COVERAGE}%" echo "Coverage badge already up to date at ${COVERAGE}%"
@@ -68,24 +77,25 @@ fi
if [ "$BADGE_TYPE" = "bdd" ] || [ "$BADGE_TYPE" = "unit" ]; then if [ "$BADGE_TYPE" = "bdd" ] || [ "$BADGE_TYPE" = "unit" ]; then
# For BDD/Unit badges, add them if they don't exist, or update if they do # For BDD/Unit badges, add them if they don't exist, or update if they do
if grep -q "${BADGE_TYPE}_Coverage" README.md; then if grep -q "${BADGE_TYPE}_Coverage" README.md; then
$SED_CMD "s|https://img.shields.io/badge/${BADGE_TYPE}_Coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md # Update existing badge with proper markdown format
$SED_CMD "s|^\[!\[${BADGE_TYPE} Coverage\].*|"${BADGE_MARKDOWN}"|" README.md
else else
# Add new badge line after the main coverage badge # Add new badge line after the main coverage badge
# Use a more reliable approach with temporary file for cross-platform compatibility # Use a more reliable approach with temporary file for cross-platform compatibility
TEMP_FILE=$(mktemp) TEMP_FILE=$(mktemp)
awk -v new_badge="${BADGE_URL}" ' awk -v new_badge="${BADGE_MARKDOWN}" '{
/coverage-.*-.*?style=flat-square/ { if ($0 ~ /\[!\[Coverage\].*img.shields.io.*coverage/) {
print $0 print $0
print new_badge print new_badge
next } else {
} print $0
{print} }
' README.md > "$TEMP_FILE" }' README.md > "$TEMP_FILE"
mv "$TEMP_FILE" README.md mv "$TEMP_FILE" README.md
fi fi
else else
# For combined coverage, use the original logic # For combined coverage, use the original logic
$SED_CMD "s|https://img.shields.io/badge/coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md $SED_CMD "s|^\[!\[Coverage\].*|"${BADGE_MARKDOWN}"|" README.md
fi fi
# Set up git # Set up git