mishima-nexus-client-csharp/scripts/woodpecker-verify.sh

44 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Library quality gate: analyzers on, tests, coverlet >= 90% on Robotico.Nexus.Client.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "${ROOT}"
TEST_PROJ="tests/Robotico.Nexus.Client.Tests/Robotico.Nexus.Client.Tests.csproj"
COVERAGE_DIR="${ROOT}/coverage"
MIN_LINE_RATE="${COVERAGE_MIN_LINE_RATE:-0.90}"
test -f Directory.Build.props || { echo "MUST - Directory.Build.props required"; exit 1; }
test -f tests/coverlet.runsettings || { echo "MUST - tests/coverlet.runsettings required"; exit 1; }
rm -rf "${COVERAGE_DIR}"
mkdir -p "${COVERAGE_DIR}"
echo "woodpecker-verify: restore/build/test with analyzers (Library 10 bar)"
dotnet restore "${TEST_PROJ}" -p:NuGetAudit=false
dotnet build "${TEST_PROJ}" -c Release --no-restore -p:NuGetAudit=false
dotnet test "${TEST_PROJ}" -c Release --no-build --verbosity minimal -p:NuGetAudit=false \
--collect:"XPlat Code Coverage" --results-directory "${COVERAGE_DIR}" \
--settings tests/coverlet.runsettings
COV_FILE="$(find "${COVERAGE_DIR}" -name 'coverage.cobertura.xml' 2>/dev/null | head -1 || true)"
if [[ -z "${COV_FILE}" ]]; then
echo "error: no coverage.cobertura.xml under ${COVERAGE_DIR}" >&2
exit 1
fi
python3 - "${COV_FILE}" "${MIN_LINE_RATE}" <<'PY'
import sys
import xml.etree.ElementTree as ET
path, minimum = sys.argv[1], float(sys.argv[2])
root = ET.parse(path).getroot()
rate = float(root.attrib.get("line-rate", "0"))
print(f"Line coverage (Robotico.Nexus.Client): {rate:.4f} (minimum {minimum:.2f})")
if rate + 1e-9 < minimum:
sys.exit(f"Coverage below {minimum:.0%}")
PY
echo "woodpecker-verify: OK"