102 lines
2.7 KiB
Bash
102 lines
2.7 KiB
Bash
#!/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}"
|
|
overall_rc=0
|
|
|
|
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}"
|
|
overall_rc=1
|
|
fi
|
|
fi
|
|
|
|
echo "[quality] doc hygiene"
|
|
printf 'failed\n' > "${BUILD_DIR}/docs-naming.status"
|
|
if python3 "${ROOT_DIR}/scripts/doc_hygiene_check.py" \
|
|
--root "${ROOT_DIR}" \
|
|
--waivers "${ROOT_DIR}/scripts/doc_hygiene_waivers.tsv"; then
|
|
printf 'ok\n' > "${BUILD_DIR}/docs-naming.status"
|
|
else
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] structure hygiene"
|
|
if ! python3 "${ROOT_DIR}/scripts/structure_hygiene_check.py" --root "${ROOT_DIR}"; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] LOC hygiene"
|
|
if ! 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"; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] code smell"
|
|
if ! bash "${ROOT_DIR}/scripts/code_smell_check.sh"; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] ui test framework policy"
|
|
if ! python3 "${ROOT_DIR}/scripts/ui_test_framework_check.py" --root "${ROOT_DIR}"; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] go vet"
|
|
if ! go vet ./...; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] unit tests + coverage"
|
|
set +e
|
|
go test -json -coverprofile="${BUILD_DIR}/coverage.out" ./... > "${BUILD_DIR}/go-test.json"
|
|
test_rc=$?
|
|
set -e
|
|
if [ "${test_rc}" -ne 0 ]; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
echo "[quality] coverage hygiene"
|
|
if ! python3 "${ROOT_DIR}/scripts/coverage_hygiene_check.py" \
|
|
--root "${ROOT_DIR}" \
|
|
--coverprofile "${BUILD_DIR}/coverage.out" \
|
|
--min-total 95 \
|
|
--baseline "${ROOT_DIR}/scripts/coverage_hygiene_baseline.tsv" \
|
|
--summary-json "${BUILD_DIR}/coverage-summary.json"; then
|
|
overall_rc=1
|
|
fi
|
|
|
|
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 "${overall_rc}"
|