soteria/scripts/check.sh

81 lines
2.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_DIR="${ROOT_DIR}/build"
mkdir -p "${BUILD_DIR}"
cd "${ROOT_DIR}"
echo "[quality] gofmt"
mapfile -t go_files < <(find cmd internal -type f -name '*.go' ! -name '*_test.go' ! -path '*/ui-dist/*' | sort)
if ((${#go_files[@]})); then
gofmt_diff="$(gofmt -l "${go_files[@]}")"
if [[ -n "${gofmt_diff}" ]]; then
echo "gofmt check failed. Run: gofmt -w <files>"
echo "${gofmt_diff}"
exit 1
fi
fi
echo "[quality] structure hygiene"
python3 "${ROOT_DIR}/scripts/structure_hygiene_check.py" --root "${ROOT_DIR}"
echo "[quality] doc hygiene"
python3 "${ROOT_DIR}/scripts/doc_hygiene_check.py" \
--root "${ROOT_DIR}" \
--waivers "${ROOT_DIR}/scripts/doc_hygiene_waivers.tsv"
echo "[quality] LOC hygiene"
python3 "${ROOT_DIR}/scripts/loc_hygiene_check.py" \
--root "${ROOT_DIR}" \
--max-lines 500 \
--waivers "${ROOT_DIR}/scripts/loc_hygiene_waivers.tsv" \
--summary-json "${BUILD_DIR}/loc-summary.json"
echo "[quality] code smell"
bash "${ROOT_DIR}/scripts/code_smell_check.sh"
echo "[quality] ui test framework policy"
python3 "${ROOT_DIR}/scripts/ui_test_framework_check.py" --root "${ROOT_DIR}"
echo "[quality] go vet"
go vet ./...
echo "[quality] unit tests + coverage"
set +e
go test -json -coverprofile="${BUILD_DIR}/coverage.out" ./... > "${BUILD_DIR}/go-test.json"
test_rc=$?
set -e
echo "[quality] coverage hygiene"
python3 "${ROOT_DIR}/scripts/coverage_hygiene_check.py" \
--root "${ROOT_DIR}" \
--coverprofile "${BUILD_DIR}/coverage.out" \
--min-total 39.5 \
--baseline "${ROOT_DIR}/scripts/coverage_hygiene_baseline.tsv" \
--summary-json "${BUILD_DIR}/coverage-summary.json"
python3 - <<'PY'
import json
from pathlib import Path
build = Path("build")
loc_path = build / "loc-summary.json"
cov_path = build / "coverage-summary.json"
summary = {"coverage_percent": 0.0, "source_lines_over_500": 0}
if loc_path.exists():
try:
summary["source_lines_over_500"] = int(json.loads(loc_path.read_text()).get("over_500", 0))
except Exception:
pass
if cov_path.exists():
try:
summary["coverage_percent"] = float(json.loads(cov_path.read_text()).get("total_percent", 0.0))
except Exception:
pass
(build / "quality-summary.json").write_text(json.dumps(summary, indent=2), encoding="utf-8")
PY
exit "${test_rc}"