📊 feat: add separate BDD and unit test coverage badges to distinguish test coverage types
This commit is contained in:
@@ -183,9 +183,9 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Run BDD tests with strict validation
|
||||
- name: Run BDD tests with strict validation and coverage
|
||||
run: |
|
||||
echo "Running BDD tests with strict validation..."
|
||||
echo "Running BDD tests with strict validation and coverage..."
|
||||
# Use the run-bdd-tests.sh script which fails on undefined/pending steps
|
||||
# In CI environment, PostgreSQL is already running as a service
|
||||
export DLC_DATABASE_HOST=postgres
|
||||
@@ -195,6 +195,15 @@ jobs:
|
||||
export DLC_DATABASE_NAME=dance_lessons_coach_bdd_test
|
||||
export DLC_DATABASE_SSL_MODE=disable
|
||||
./scripts/run-bdd-tests.sh
|
||||
|
||||
# Extract BDD coverage percentage
|
||||
BDD_COVERAGE=$(grep "coverage:" <<< "$test_output" | grep -oP '\d+\.\d+' | head -1)
|
||||
echo "BDD Coverage: ${BDD_COVERAGE}%"
|
||||
|
||||
# Update BDD coverage badge
|
||||
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
|
||||
export GITHUB_REF_NAME="${{ github.ref_name }}"
|
||||
./scripts/ci-update-coverage-badge.sh "$BDD_COVERAGE" "bdd"
|
||||
|
||||
- name: Run unit tests with coverage
|
||||
run: |
|
||||
@@ -202,14 +211,14 @@ jobs:
|
||||
# Run unit tests excluding BDD tests (already run above)
|
||||
go test ./pkg/... ./cmd/... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt
|
||||
|
||||
# Extract coverage percentage
|
||||
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||
echo "Coverage: ${COVERAGE}%"
|
||||
# Extract unit test coverage percentage
|
||||
UNIT_COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||
echo "Unit Coverage: ${UNIT_COVERAGE}%"
|
||||
|
||||
# Update coverage badge using script
|
||||
# Update unit test coverage badge
|
||||
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
|
||||
export GITHUB_REF_NAME="${{ github.ref_name }}"
|
||||
./scripts/ci-update-coverage-badge.sh "$COVERAGE"
|
||||
./scripts/ci-update-coverage-badge.sh "$UNIT_COVERAGE" "unit"
|
||||
|
||||
- name: Run go fmt
|
||||
run: go fmt ./...
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
# CI script to update coverage badge in README.md
|
||||
# Usage: scripts/ci-update-coverage-badge.sh <coverage_percentage>
|
||||
# Usage: scripts/ci-update-coverage-badge.sh <coverage_percentage> [badge_type]
|
||||
# badge_type can be "bdd", "unit", or empty for combined coverage
|
||||
|
||||
set -e
|
||||
|
||||
@@ -10,6 +11,7 @@ if [ -z "$1" ]; then
|
||||
fi
|
||||
|
||||
COVERAGE=$1
|
||||
BADGE_TYPE=${2:-"combined"}
|
||||
|
||||
# Determine badge color
|
||||
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
|
||||
@@ -20,16 +22,37 @@ else
|
||||
COLOR="red"
|
||||
fi
|
||||
|
||||
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square"
|
||||
# Create different badge URLs based on type
|
||||
if [ "$BADGE_TYPE" = "bdd" ]; then
|
||||
BADGE_URL="https://img.shields.io/badge/BDD_Coverage-${COVERAGE}%-${COLOR}?style=flat-square"
|
||||
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"
|
||||
SEARCH_PATTERN="Unit_Coverage-.*-.*?style=flat-square"
|
||||
else
|
||||
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square"
|
||||
SEARCH_PATTERN="coverage-.*-.*?style=flat-square"
|
||||
fi
|
||||
|
||||
# Only update if coverage has actually changed
|
||||
if 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}%"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Update README
|
||||
sed -i "s|https://img.shields.io/badge/coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md
|
||||
# Update README - handle both old and new badge formats
|
||||
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 -i "s|https://img.shields.io/badge/${BADGE_TYPE}_Coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md
|
||||
else
|
||||
# Add new badge line after the main coverage badge
|
||||
sed -i "/coverage-.*-.*?style=flat-square/a\\n${BADGE_URL}" README.md
|
||||
fi
|
||||
else
|
||||
# For combined coverage, use the original logic
|
||||
sed -i "s|https://img.shields.io/badge/coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md
|
||||
fi
|
||||
|
||||
# Set up git
|
||||
git config --global user.name "CI Bot"
|
||||
|
||||
Reference in New Issue
Block a user