-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev
More file actions
executable file
·266 lines (230 loc) · 6.58 KB
/
Copy pathdev
File metadata and controls
executable file
·266 lines (230 loc) · 6.58 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
BOLD=$'\033[1m'
ACCENT=$'\033[38;2;251;191;36m'
MUTED=$'\033[38;2;90;100;128m'
SUCCESS=$'\033[38;2;0;229;204m'
ERROR=$'\033[38;2;230;57;70m'
NC=$'\033[0m'
commands=(
"pr:🚀:Pre-PR checks (check + e2e + bench)"
"doctor:🩺:Setup dev environment"
"test:🧪:Run unit tests"
"test verbose:🧪:Run unit tests (verbose)"
"test race:🧪:Run unit tests with race detector"
"coverage:📊:Run tests with coverage report"
"lint:🔍:Run golangci-lint"
"lint corpus:🔍:Lint benchmark corpus"
"lint docs:🔍:Check documentation links"
"fmt:✨:Format code"
"vet:🔬:Run go vet"
"check:✅:Run all checks (fmt + vet + lint + test)"
"build:📦:Build CLI binary"
"bench:🏋:Run corpus benchmark"
"bench full:🏋:Run full benchmark suite"
"baseline:📏:Create quality baseline"
"baseline check:📏:Check against baseline"
"baseline update:📏:Update baseline (--accept)"
"calibrate:🎯:Calibrate threshold recommendations"
"runtime:⏱️:Check runtime baseline"
"tune:🎛️:Tune combined weights"
"e2e:🐳:Run E2E tests (Docker)"
)
show_help() {
echo ""
echo " ${BOLD}${ACCENT}semantic${NC} ${MUTED}— development tool${NC}"
echo ""
for entry in "${commands[@]}"; do
IFS=: read -r cmd icon desc <<< "$entry"
printf " ${ACCENT}%-22s${NC} %s %s\n" "./dev $cmd" "$icon" "$desc"
done
echo ""
}
run_pr() {
echo " ${ACCENT}${BOLD}🚀 Pre-PR checks${NC}"
echo ""
echo " ${MUTED}1/4 All checks (fmt + vet + lint + test)${NC}"
run_check
echo ""
echo " ${MUTED}2/4 E2E tests${NC}"
if [[ -f tests/e2e/run.sh ]]; then
go build -o /tmp/semantic ./cmd/semantic
PATH="/tmp:$PATH" bash tests/e2e/run.sh
echo " ${SUCCESS}✓${NC} E2E passed"
else
echo " ${MUTED}Skipped (no e2e/run.sh)${NC}"
fi
echo ""
echo " ${MUTED}3/4 Lint corpus${NC}"
run_lint_corpus
echo ""
echo " ${MUTED}4/4 Corpus benchmark${NC}"
run_bench > /dev/null 2>&1
echo " ${SUCCESS}✓${NC} Benchmark complete"
echo ""
echo " ${SUCCESS}${BOLD}🚀 Ready for PR${NC}"
}
run_test() {
echo " ${ACCENT}${BOLD}🧪 Running tests${NC}"
go test ./... -count=1
echo " ${SUCCESS}✓${NC} Tests passed"
}
run_test_verbose() {
echo " ${ACCENT}${BOLD}🧪 Running tests (verbose)${NC}"
go test ./... -count=1 -v
}
run_test_race() {
echo " ${ACCENT}${BOLD}🧪 Running tests with race detector${NC}"
go test ./... -count=1 -race
echo " ${SUCCESS}✓${NC} Tests passed (race)"
}
run_coverage() {
echo " ${ACCENT}${BOLD}📊 Running tests with coverage${NC}"
go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out | tail -1
echo ""
echo " ${MUTED}HTML report: go tool cover -html=coverage.out${NC}"
}
run_lint() {
echo " ${ACCENT}${BOLD}🔍 Running linter${NC}"
golangci-lint run
echo " ${SUCCESS}✓${NC} Lint clean"
}
run_fmt() {
echo " ${ACCENT}${BOLD}✨ Formatting code${NC}"
gofmt -w .
echo " ${SUCCESS}✓${NC} Formatted"
}
run_vet() {
echo " ${ACCENT}${BOLD}🔬 Running go vet${NC}"
go vet ./...
echo " ${SUCCESS}✓${NC} Vet clean"
}
run_check() {
echo " ${ACCENT}${BOLD}✅ Running all checks${NC}"
echo ""
echo " ${MUTED}1/4 Format check${NC}"
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo " ${ERROR}✗${NC} Unformatted files:"
echo "$unformatted"
echo ""
printf " Fix formatting now? (Y/n) "
read -r answer
if [ "$answer" != "n" ] && [ "$answer" != "N" ]; then
gofmt -w .
echo " ${SUCCESS}✓${NC} Format (fixed)"
else
echo " ${MUTED}Run: gofmt -w .${NC}"
exit 1
fi
else
echo " ${SUCCESS}✓${NC} Format"
fi
echo " ${MUTED}2/4 Vet${NC}"
go vet ./...
echo " ${SUCCESS}✓${NC} Vet"
echo " ${MUTED}3/4 Lint${NC}"
golangci-lint run
echo " ${SUCCESS}✓${NC} Lint"
echo " ${MUTED}4/4 Tests${NC}"
go test ./... -count=1 -race
echo " ${SUCCESS}✓${NC} Tests"
echo ""
echo " ${SUCCESS}${BOLD}All checks passed${NC}"
}
run_build() {
echo " ${ACCENT}${BOLD}📦 Building CLI${NC}"
go build -o semantic ./cmd/semantic
echo " ${SUCCESS}✓${NC} Built: ./semantic"
}
run_bench() {
echo " ${ACCENT}${BOLD}🏋 Running corpus benchmark${NC}"
go run ./cmd/semantic-bench check "$@"
}
run_bench_full() {
echo " ${ACCENT}${BOLD}🏋 Running full benchmark suite${NC}"
go run ./cmd/semantic-bench run -suite=all "$@"
}
run_lint_corpus() {
echo " ${ACCENT}${BOLD}🔍 Linting benchmark corpus${NC}"
go run ./cmd/semantic-bench lint "$@"
}
run_lint_docs() {
echo " ${ACCENT}${BOLD}🔍 Checking documentation links${NC}"
bash scripts/check-docs-links.sh
}
run_baseline() {
echo " ${ACCENT}${BOLD}📏 Creating quality baseline${NC}"
go run ./cmd/semantic-bench baseline create "$@"
}
run_baseline_check() {
echo " ${ACCENT}${BOLD}📏 Checking against baseline${NC}"
go run ./cmd/semantic-bench check "$@"
}
run_baseline_update() {
echo " ${ACCENT}${BOLD}📏 Updating baseline${NC}"
go run ./cmd/semantic-bench baseline update --accept "$@"
}
run_calibrate() {
echo " ${ACCENT}${BOLD}🎯 Calibrating thresholds${NC}"
go run ./cmd/semantic-bench calibrate -verbose "$@"
}
run_runtime() {
echo " ${ACCENT}${BOLD}⏱️ Checking runtime baseline${NC}"
go run ./cmd/semantic-bench runtime "$@"
}
run_tune() {
echo " ${ACCENT}${BOLD}🎛️ Tuning combined weights${NC}"
go run ./cmd/semantic-bench tune -verbose "$@"
}
run_e2e() {
echo " ${ACCENT}${BOLD}🐳 Running E2E tests${NC}"
if [ ! -f tests/e2e/docker-compose.yml ]; then
echo " ${ERROR}✗${NC} E2E not yet set up (Phase 4)"
exit 1
fi
bash scripts/e2e.sh
}
case "${1:-help}" in
pr) run_pr ;;
doctor) exec bash scripts/doctor.sh ;;
test)
case "${2:-}" in
verbose) run_test_verbose ;;
race) run_test_race ;;
*) run_test ;;
esac
;;
coverage) run_coverage ;;
lint)
case "${2:-}" in
corpus) run_lint_corpus ;;
docs) run_lint_docs ;;
*) run_lint ;;
esac
;;
fmt) run_fmt ;;
vet) run_vet ;;
check) run_check ;;
build) run_build ;;
bench|benchmark)
case "${2:-}" in
full) run_bench_full ;;
*) shift; run_bench "$@" ;;
esac
;;
baseline)
case "${2:-}" in
check) shift 2; run_baseline_check "$@" ;;
update) shift 2; run_baseline_update "$@" ;;
*) shift; run_baseline "$@" ;;
esac
;;
calibrate) shift; run_calibrate "$@" ;;
runtime) shift; run_runtime "$@" ;;
tune) shift; run_tune "$@" ;;
e2e) run_e2e ;;
help|*) show_help ;;
esac