Grade OS code quality from static checks
main-release-gate / verify-and-release (push) Failing after 2m7s
main-release-gate / verify-and-release (push) Failing after 2m7s
This commit is contained in:
@@ -33,7 +33,9 @@ jobs:
|
||||
- name: CI cleanup containment checks
|
||||
run: python3 ci/test-cleanup-generated.py
|
||||
- name: Quality
|
||||
run: cargo clippy --all-targets --locked -- -D warnings
|
||||
run: |
|
||||
cargo clippy --all-targets --locked -- -D warnings
|
||||
printf '{"format":true,"clippy_warnings_denied":true}\n' > quality-current.json
|
||||
- name: Build
|
||||
run: cargo build --release --locked
|
||||
- name: Unit and workflow tests
|
||||
@@ -67,7 +69,7 @@ jobs:
|
||||
run: |
|
||||
python3 ci/metrics.py --tests-output tests-current.txt \
|
||||
--tests-coverage coverage/tests.json --bench-output bench-current.txt \
|
||||
--bench-coverage coverage/bench.json
|
||||
--bench-coverage coverage/bench.json --quality-gate quality-current.json
|
||||
- uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
|
||||
with:
|
||||
name: alkane-os-metrics
|
||||
|
||||
@@ -10,7 +10,7 @@ import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DIRECTORIES = ("target", "coverage", "dist", "bench-site")
|
||||
FILES = ("tests-current.txt", "bench-current.txt")
|
||||
FILES = ("tests-current.txt", "bench-current.txt", "quality-current.json")
|
||||
|
||||
|
||||
def cleanup() -> None:
|
||||
|
||||
+11
-14
@@ -20,6 +20,13 @@ def bench_results(path):
|
||||
return {name: float(ns) for name, ns in re.findall(r"BENCH (\w+) ([0-9.]+) ns/op", text)}
|
||||
|
||||
|
||||
def quality_grade(path):
|
||||
checks = json.loads(pathlib.Path(path).read_text())
|
||||
if checks != {"format": True, "clippy_warnings_denied": True}:
|
||||
raise ValueError("format and strict Clippy must pass before publishing quality")
|
||||
return "A"
|
||||
|
||||
|
||||
def compact(number):
|
||||
value = float(number)
|
||||
units = ("", "K", "M", "G")
|
||||
@@ -34,19 +41,6 @@ def compact(number):
|
||||
return number + units[index]
|
||||
|
||||
|
||||
def quality_grade(line_coverage):
|
||||
# Main CI reaches this publisher only after warnings-denied Clippy passes.
|
||||
if line_coverage >= 90:
|
||||
return "A"
|
||||
if line_coverage >= 80:
|
||||
return "B"
|
||||
if line_coverage >= 70:
|
||||
return "C"
|
||||
if line_coverage >= 60:
|
||||
return "D"
|
||||
return "F"
|
||||
|
||||
|
||||
def svg(label, value, color):
|
||||
label, value = html.escape(label), html.escape(value)
|
||||
lw, vw = 12 + 7 * len(label), 12 + 7 * len(value)
|
||||
@@ -65,6 +59,7 @@ def main():
|
||||
parser.add_argument("--tests-coverage", required=True)
|
||||
parser.add_argument("--bench-output", required=True)
|
||||
parser.add_argument("--bench-coverage", required=True)
|
||||
parser.add_argument("--quality-gate", required=True)
|
||||
parser.add_argument("--bench-baseline", default="badges/bench-baseline.json")
|
||||
args = parser.parse_args()
|
||||
test_output = pathlib.Path(args.tests_output).read_text()
|
||||
@@ -90,7 +85,9 @@ def main():
|
||||
"bench_ns_per_op": current, "bench_improvement_pct": delta,
|
||||
"bench_host": benchmark_host(),
|
||||
"lines_of_code": loc, "dependencies": dependencies,
|
||||
"code_quality": quality_grade(line_coverage), "license": "MIT"}
|
||||
"code_quality": quality_grade(args.quality_gate),
|
||||
"quality_scope": "main CI passed cargo fmt and warnings-denied Clippy on all targets",
|
||||
"license": "MIT"}
|
||||
pathlib.Path("badges").mkdir(exist_ok=True)
|
||||
pathlib.Path("badges/metrics.json").write_text(json.dumps(metrics, indent=2) + "\n")
|
||||
badges = {
|
||||
|
||||
+9
-6
@@ -3,6 +3,7 @@
|
||||
"""Regression checks for measured benchmark and quality badges."""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
@@ -12,12 +13,14 @@ from metrics import bench_results, compact, quality_grade
|
||||
|
||||
|
||||
class MetricTests(unittest.TestCase):
|
||||
def test_quality_grade_depends_on_measured_coverage(self):
|
||||
self.assertEqual(quality_grade(92), "A")
|
||||
self.assertEqual(quality_grade(88), "B")
|
||||
self.assertEqual(quality_grade(72), "C")
|
||||
self.assertEqual(quality_grade(65), "D")
|
||||
self.assertEqual(quality_grade(40), "F")
|
||||
def test_quality_requires_both_static_checks(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "quality.json"
|
||||
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": True}))
|
||||
self.assertEqual(quality_grade(path), "A")
|
||||
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": False}))
|
||||
with self.assertRaises(ValueError):
|
||||
quality_grade(path)
|
||||
|
||||
def test_benchmark_parser_and_short_si_badge(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
|
||||
Reference in New Issue
Block a user