Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions scripts/test_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail

PROJECT_ROOT=${GITHUB_WORKSPACE:-$(pwd)}
PROJECT_ROOT=${GITHUB_WORKSPACE:-$(cd "$(dirname "$0")/.." && pwd)}
COVERAGE_ROOT="$PROJECT_ROOT/dist/coverage"
LOG_FILE="$COVERAGE_ROOT/test_coverage_log.txt"

Expand All @@ -22,16 +22,42 @@ fi

export RUSTC_BOOTSTRAP=1

COVERAGE_THRESHOLD=80

echo "πŸ“‚ Running tarpaulin for workspace" | tee -a "$LOG_FILE"
mkdir -p "$COVERAGE_ROOT/workspace"

if cargo tarpaulin --workspace --out Html --out Lcov --out Xml \
TARPAULIN_OUTPUT=$(cargo tarpaulin --packages timpani-n timpani-o --out Html --out Lcov --out Xml \
--output-dir "$COVERAGE_ROOT/workspace" \
--ignore-panics --no-fail-fast \
2>&1 | tee -a "$LOG_FILE"; then
echo "βœ… Coverage generated successfully" | tee -a "$LOG_FILE"
2>&1) || {
echo "$TARPAULIN_OUTPUT" | tee -a "$LOG_FILE"
echo "::error ::tarpaulin failed or no tests found" | tee -a "$LOG_FILE"
exit 1
}
echo "$TARPAULIN_OUTPUT" | tee -a "$LOG_FILE"

echo "βœ… Coverage generated successfully" | tee -a "$LOG_FILE"

# Parse the coverage percentage from tarpaulin output (line like "X.XX% coverage")
COVERAGE=$(echo "$TARPAULIN_OUTPUT" | grep -oP '\d+\.\d+(?=% coverage)' | tail -1)

if [ -z "$COVERAGE" ]; then
echo "::error ::Could not parse coverage percentage from tarpaulin output" | tee -a "$LOG_FILE"
exit 1
fi

echo "πŸ“Š Measured coverage: ${COVERAGE}%" | tee -a "$LOG_FILE"
echo "🎯 Required threshold: ${COVERAGE_THRESHOLD}%" | tee -a "$LOG_FILE"

# Compare using awk (bash arithmetic doesn't handle floats)
PASS=$(awk -v cov="$COVERAGE" -v threshold="$COVERAGE_THRESHOLD" 'BEGIN { print (cov >= threshold) ? "yes" : "no" }')

if [ "$PASS" = "yes" ]; then
echo "βœ… Coverage check passed: ${COVERAGE}% >= ${COVERAGE_THRESHOLD}%" | tee -a "$LOG_FILE"
else
echo "::warning ::tarpaulin failed or no tests found" | tee -a "$LOG_FILE"
echo "::error ::Coverage check FAILED: ${COVERAGE}% is below the required ${COVERAGE_THRESHOLD}% threshold" | tee -a "$LOG_FILE"
exit 1
fi

echo "βœ… All test coverage reports generated at: $COVERAGE_ROOT" | tee -a "$LOG_FILE"
Loading