-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathpre-push-coverage
More file actions
executable file
·87 lines (75 loc) · 2.92 KB
/
pre-push-coverage
File metadata and controls
executable file
·87 lines (75 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
#
# Pre-push hook: checks that a fresh coverage report exists
# when pushing coprocessor changes. Non-blocking (always exits 0).
#
# Preserve Git LFS functionality
command -v git-lfs >/dev/null 2>&1 && git lfs pre-push "$@"
# Get the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
REPORT_FILE="$REPO_ROOT/coprocessor/fhevm-engine/coverage-report.txt"
COPROCESSOR_DIR="coprocessor/fhevm-engine/"
# Fetch latest remote to ensure accurate comparison
git fetch origin main --quiet 2>/dev/null || true
# Get changed files on this branch vs origin/main, filtered to actual crate directories only
# (ignores root-level config: Makefile, scripts/, Cargo.toml, etc.)
CRATE_CHANGES=$(git diff --name-only "origin/main"...HEAD -- "$COPROCESSOR_DIR" 2>/dev/null | \
while read -r f; do
rel=$(echo "$f" | sed "s|^$COPROCESSOR_DIR||")
crate_name=$(echo "$rel" | cut -d/ -f1)
if [ -f "$REPO_ROOT/$COPROCESSOR_DIR$crate_name/Cargo.toml" ]; then
echo "$crate_name"
fi
done | sort -u)
if [ -z "$CRATE_CHANGES" ]; then
exit 0
fi
# Check if coverage report exists
if [ ! -f "$REPORT_FILE" ]; then
echo ""
echo "WARNING: No coverage report found for coprocessor."
echo " Run 'make coverage-changed' in coprocessor/fhevm-engine/ to generate it."
echo ""
exit 0
fi
# Check report freshness via embedded commit hash
REPORT_COMMIT=$(grep "^# commit:" "$REPORT_FILE" 2>/dev/null | awk '{print $3}')
if [ -z "$REPORT_COMMIT" ]; then
echo ""
echo "WARNING: Coverage report has no commit metadata (regenerate with latest tooling)."
echo " Run 'make coverage-changed' in coprocessor/fhevm-engine/ to regenerate."
echo ""
exit 0
fi
# Get the latest crate-related commit on this branch
LATEST_CRATE_COMMIT=""
for crate in $CRATE_CHANGES; do
c=$(git log -1 --format=%H "origin/main"..HEAD -- "$COPROCESSOR_DIR$crate/" 2>/dev/null)
if [ -n "$c" ]; then
if [ -z "$LATEST_CRATE_COMMIT" ] || [ "$(git log -1 --format=%ct "$c")" -gt "$(git log -1 --format=%ct "$LATEST_CRATE_COMMIT")" ]; then
LATEST_CRATE_COMMIT="$c"
fi
fi
done
if [ -z "$LATEST_CRATE_COMMIT" ]; then
exit 0
fi
# Check if the report was generated at or after the latest crate commit
if ! git merge-base --is-ancestor "$LATEST_CRATE_COMMIT" "$REPORT_COMMIT" 2>/dev/null; then
echo ""
echo "WARNING: Coverage report is stale (generated before latest coprocessor commit)."
echo " Run 'make coverage-changed' in coprocessor/fhevm-engine/ to regenerate."
echo ""
exit 0
fi
# Report is fresh — print summary
TOTAL_LINE=$(grep "^TOTAL" "$REPORT_FILE" 2>/dev/null)
if [ -n "$TOTAL_LINE" ]; then
REGION_PCT=$(echo "$TOTAL_LINE" | awk '{print $4}')
FUNC_PCT=$(echo "$TOTAL_LINE" | awk '{print $7}')
LINE_PCT=$(echo "$TOTAL_LINE" | awk '{print $10}')
echo ""
echo "Coverage: Lines: $LINE_PCT | Functions: $FUNC_PCT | Regions: $REGION_PCT"
echo ""
fi
exit 0