🐛 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"
fi
# Create different badge URLs based on type
# Create different badge URLs and markdown format based on type
if [ "$BADGE_TYPE" = "bdd" ]; then
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"
elif [ "$BADGE_TYPE" = "unit" ]; then
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"
else
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"
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
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}%"
@@ -68,24 +77,25 @@ fi
if [ "$BADGE_TYPE" = "bdd" ] || [ "$BADGE_TYPE" = "unit" ]; then
# 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
$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
# Add new badge line after the main coverage badge
# Use a more reliable approach with temporary file for cross-platform compatibility
TEMP_FILE=$(mktemp)
awk -v new_badge="${BADGE_URL}" '
/coverage-.*-.*?style=flat-square/ {
print $0
print new_badge
next
}
{print}
' README.md > "$TEMP_FILE"
awk -v new_badge="${BADGE_MARKDOWN}" '{
if ($0 ~ /\[!\[Coverage\].*img.shields.io.*coverage/) {
print $0
print new_badge
} else {
print $0
}
}' README.md > "$TEMP_FILE"
mv "$TEMP_FILE" README.md
fi
else
# 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
# Set up git
@@ -138,4 +148,4 @@ if git commit -m "🤖 chore: update coverage badge to ${COVERAGE}% [skip ci]";
done
else
echo "No coverage change to commit"
fi
fi