Repository navigation
Expand file tree
/
Copy pathcheck-directory-size.sh
More file actions
executable file
·73 lines (65 loc) · 2.65 KB
/
Copy pathcheck-directory-size.sh
File metadata and controls
executable file
·73 lines (65 loc) · 2.65 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
#!/usr/bin/env bash
# check-directory-size.sh - God-Folder-Watcher für CI (#809).
#
# Zählt die FLACH (maxdepth 1) in einem Verzeichnis liegenden Quell-Dateien
# (*.ts / *.tsx, inkl. Tests) und warnt, wenn ein Verzeichnis zu viele
# enthält. Analog zum Filesize-Watcher (God-Files) verhindert dieser Check,
# dass God-Folders zurückkehren, nachdem sie nach Concern gruppiert wurden.
#
# Zwei Stufen:
# WARN_THRESHOLD (default 15) - Warnung, kein Fail (Standard-Lauf).
# --gate - exit 1, wenn ein NICHT in .dirsize-baseline gelistetes
# Verzeichnis über WARN_THRESHOLD liegt (Ratchet:
# bestehende, noch nicht migrierte God-Folders werden
# toleriert, dürfen aber nicht NEU entstehen).
#
# Nur versionierte Quellen unter frontend/src (git ls-files). Generierte /
# gitignorierte Bäume entfallen damit automatisch.
#
# Exit-Codes:
# 0 = sauber, oder nur Warnungen, oder nur tolerierte Baseline-Verzeichnisse
# 1 = (nur mit --gate) ein neues Verzeichnis über dem Schwellwert
set -euo pipefail
WARN_THRESHOLD="${WARN_THRESHOLD:-15}"
ROOT_DIR="${ROOT_DIR:-frontend/src}"
BASELINE_FILE=".dirsize-baseline"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$REPO_ROOT"
GATE=0
[[ "${1:-}" == "--gate" ]] && GATE=1
# Tolerated (not-yet-migrated) directories, one path per line, '#' comments ok.
declare -A BASELINE=()
if [[ -f "$BASELINE_FILE" ]]; then
while IFS= read -r line; do
line="${line%%#*}"; line="$(echo -n "$line" | xargs || true)"
[[ -n "$line" ]] && BASELINE["$line"]=1
done < "$BASELINE_FILE"
fi
# Count flat (maxdepth 1) tracked *.ts/*.tsx per directory. Co-located test
# files (*.test.ts/x) are excluded: the guard is about grouping SOURCE files
# by concern, and tests live next to their subject by convention.
declare -A COUNT=()
while IFS= read -r f; do
[[ "$f" == */* ]] || continue
case "$f" in *.test.ts|*.test.tsx) continue;; esac
dir="${f%/*}"
COUNT["$dir"]=$(( ${COUNT["$dir"]:-0} + 1 ))
done < <(git ls-files "$ROOT_DIR" | grep -E '\.tsx?$' || true)
status=0
warned=0
for dir in $(printf '%s\n' "${!COUNT[@]}" | sort); do
n="${COUNT[$dir]}"
(( n > WARN_THRESHOLD )) || continue
if [[ -n "${BASELINE[$dir]:-}" ]]; then
echo "BASELINE (tolerated): $dir has $n files (max $WARN_THRESHOLD)"
continue
fi
echo "WARNING: $dir has $n files (max $WARN_THRESHOLD) — group by concern"
warned=1
(( GATE == 1 )) && status=1
done
if (( warned == 0 )); then
echo "check-directory-size: OK — no un-baselined directory over $WARN_THRESHOLD flat files."
fi
exit $status