-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathlocal-checks
More file actions
executable file
·107 lines (95 loc) · 3.43 KB
/
Copy pathlocal-checks
File metadata and controls
executable file
·107 lines (95 loc) · 3.43 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
#!/usr/bin/env bash
# local-checks — comprehensive local check suite mirroring CI.
# Usage: ./scripts/local-checks [quick|full]
# quick (default): fmt + clippy + lib tests
# full: fmt + clippy + all tests + WASM build + audit + cargo-deny
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
BOLD='\033[1m'
MODE="${1:-quick}"
ERRORS=0
pass() { echo -e " ${GREEN}✓${NC} $1"; }
fail() { echo -e " ${RED}✗${NC} $1"; ERRORS=$((ERRORS + 1)); }
warn() { echo -e " ${YELLOW}!${NC} $1"; }
header(){ echo -e "\n${BOLD}── $1 ──${NC}"; }
echo -e "${BOLD}Local Check Suite${NC} (mode: ${MODE})"
echo "=============================="
# ── 1. Format ──────────────────────────────────────────────────────────────
header "cargo fmt"
if cargo fmt --all -- --check 2>/dev/null; then
pass "Formatting OK"
else
warn "Auto-formatting..."
cargo fmt --all
pass "Formatting fixed"
fi
# ── 2. Clippy ──────────────────────────────────────────────────────────────
header "cargo clippy"
if cargo clippy --all -- -D warnings 2>/dev/null; then
pass "Clippy OK"
else
fail "Clippy failed"
fi
# ── 3. Tests ───────────────────────────────────────────────────────────────
header "cargo test"
if [ "$MODE" = "full" ]; then
if cargo test --all --verbose 2>/dev/null; then
pass "All tests OK"
else
fail "Tests failed"
fi
else
if cargo test --lib 2>/dev/null; then
pass "Lib tests OK"
else
fail "Lib tests failed"
fi
fi
# ── 4. WASM build (full mode only) ────────────────────────────────────────
if [ "$MODE" = "full" ]; then
header "WASM build"
if cargo build --release --target wasm32v1-none 2>/dev/null; then
pass "WASM build OK"
# Report sizes
echo " WASM artifact sizes:"
for wasm in target/wasm32v1-none/release/*.wasm; do
[ -f "$wasm" ] || continue
name=$(basename "$wasm" .wasm)
bytes=$(stat -c%s "$wasm" 2>/dev/null || stat -f%z "$wasm" 2>/dev/null)
printf " %-40s %s bytes\n" "$name" "$bytes"
done
else
fail "WASM build failed"
fi
header "cargo audit"
if command -v cargo-audit &>/dev/null; then
if cargo audit 2>/dev/null; then
pass "Audit OK"
else
fail "Audit found advisories"
fi
else
warn "cargo-audit not installed (cargo install cargo-audit --locked)"
fi
header "cargo deny"
if command -v cargo-deny &>/dev/null; then
if cargo deny check 2>/dev/null; then
pass "cargo-deny OK (licences, sources, bans)"
else
fail "cargo-deny found a licence/source/bans violation"
fi
else
warn "cargo-deny not installed (cargo install cargo-deny --locked)"
fi
fi
# ── Summary ────────────────────────────────────────────────────────────────
echo ""
if [ "$ERRORS" -gt 0 ]; then
echo -e "${RED}${ERRORS} check(s) failed.${NC}"
exit 1
else
echo -e "${GREEN}All checks passed.${NC}"
fi