- Implemented a new script `local-patch-report.sh` to generate a local patch report. - The report computes patch coverage based on changes from the current branch against `origin/main`. - Integrated backend and frontend coverage inputs, producing both Markdown and JSON output artifacts. - Updated existing frontend coverage script to validate the presence of LCOV coverage file. - Added tests for coverage computation and parsing of unified diffs for changed lines. - Enhanced error handling and validation for coverage inputs and baseline references.
53 lines
1.6 KiB
Bash
Executable File
53 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
BASELINE="${CHARON_PATCH_BASELINE:-origin/main...HEAD}"
|
|
BACKEND_COVERAGE_FILE="$ROOT_DIR/backend/coverage.txt"
|
|
FRONTEND_COVERAGE_FILE="$ROOT_DIR/frontend/coverage/lcov.info"
|
|
JSON_OUT="$ROOT_DIR/test-results/local-patch-report.json"
|
|
MD_OUT="$ROOT_DIR/test-results/local-patch-report.md"
|
|
|
|
if ! command -v git >/dev/null 2>&1; then
|
|
echo "Error: git is required to generate local patch report." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v go >/dev/null 2>&1; then
|
|
echo "Error: go is required to generate local patch report." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$BACKEND_COVERAGE_FILE" ]]; then
|
|
echo "Error: backend coverage input missing at $BACKEND_COVERAGE_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$FRONTEND_COVERAGE_FILE" ]]; then
|
|
echo "Error: frontend coverage input missing at $FRONTEND_COVERAGE_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
BASE_REF="$BASELINE"
|
|
if [[ "$BASELINE" == *"..."* ]]; then
|
|
BASE_REF="${BASELINE%%...*}"
|
|
fi
|
|
|
|
if [[ -n "$BASE_REF" ]] && ! git -C "$ROOT_DIR" rev-parse --verify --quiet "${BASE_REF}^{commit}" >/dev/null; then
|
|
echo "Error: baseline base ref '$BASE_REF' is not available locally. Set CHARON_PATCH_BASELINE to a valid range and retry." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$ROOT_DIR/test-results"
|
|
|
|
(
|
|
cd "$ROOT_DIR/backend"
|
|
go run ./cmd/localpatchreport \
|
|
--repo-root "$ROOT_DIR" \
|
|
--baseline "$BASELINE" \
|
|
--backend-coverage "$BACKEND_COVERAGE_FILE" \
|
|
--frontend-coverage "$FRONTEND_COVERAGE_FILE" \
|
|
--json-out "$JSON_OUT" \
|
|
--md-out "$MD_OUT"
|
|
)
|