Skip to content

Commit a5cd765

Browse files
committed
build: fail if not high coverage
1 parent b116c90 commit a5cd765

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

flake.nix

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
src = self;
6464
nativeBuildInputs =
6565
(self.packages.${pkgs.stdenv.hostPlatform.system}.smart-piano.nativeBuildInputs or [ ])
66-
++ [ pkgs.lcov ];
66+
++ [
67+
pkgs.lcov
68+
pkgs.jq
69+
];
6770
buildInputs = (self.packages.${pkgs.stdenv.hostPlatform.system}.smart-piano.buildInputs or [ ]);
6871
configurePhase = ''
6972
cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -GNinja -S . -B build
@@ -73,12 +76,24 @@
7376
'';
7477
checkPhase = ''
7578
cmake --build build --target coverage -j1 # Multithread breaks tests
79+
# Text report for the CI comment
7680
llvm-cov report build/src/main -instr-profile=build/coverage.profdata -ignore-filename-regex='test/.*' > build/coverage.txt
7781
cat build/coverage.txt
78-
echo "Verifying functions coverage is > 90%"
79-
grep TOTAL build/coverage.txt | awk '{ if ($7 + 0 > 90) exit 0; else { print "Function coverage is " $7 "% (< 90%)"; exit 1 } }'
80-
echo "Verifying line coverage is > 90%"
81-
grep TOTAL build/coverage.txt | awk '{ if ($10 + 0 > 90) exit 0; else { print "Line coverage is " $10 "% (< 90%)"; exit 1 } }'
82+
83+
# JSON export for threshold verification
84+
llvm-cov export build/src/main -instr-profile=build/coverage.profdata -ignore-filename-regex='test/.*' --summary-only > build/coverage.json
85+
86+
# Extract totals
87+
FUNCTIONS=$(jq '.data[0].totals.functions.percent' build/coverage.json)
88+
LINES=$(jq '.data[0].totals.lines.percent' build/coverage.json)
89+
90+
echo "#### Coverage thresholds check ####"
91+
echo "Function coverage: $FUNCTIONS% (Required: 90%)"
92+
echo "Line coverage: $LINES% (Required: 80%)"
93+
94+
# Check thresholds (using jq for float comparison)
95+
jq -e '.data[0].totals.functions.percent >= 90' build/coverage.json > /dev/null || (echo "FAILED: Function coverage is below 90%" && exit 1)
96+
jq -e '.data[0].totals.lines.percent >= 80' build/coverage.json > /dev/null || (echo "FAILED: Line coverage is below 80%" && exit 1)
8297
'';
8398
installPhase = ''
8499
mkdir -p $out

0 commit comments

Comments
 (0)