Section 13/221 menit
13. Monitoring & Regression Prevention
13. Monitoring & Regression Prevention
Script Deteksi Regresi Build Time
swift
#!/bin/bash
# scripts/check-build-time-regression.sh
# Jalankan di CI sebagai pre-merge check
SCHEME="${1:-MyApp}"
THRESHOLD_SECONDS="${2:-300}" # Alert jika > 5 menit
CSV_FILE="build-times.csv"
echo "Building $SCHEME..."
START=$(date +%s)
xcodebuild build \
-scheme "$SCHEME" \
-destination 'platform=iOS Simulator,name=iPhone 16' \
-configuration Debug \
CODE_SIGNING_ALLOWED=NO \
> /dev/null 2>&1
END=$(date +%s)
ELAPSED=$((END - START))
# Simpan hasil
echo "$(date +%Y-%m-%d %H:%M),${SCHEME},${ELAPSED},${GITHUB_SHA:-local}" >> "$CSV_FILE"
echo "Build time: ${ELAPSED}s (threshold: ${THRESHOLD_SECONDS}s)"
# Hitung rata-rata 5 build terakhir
if [ -f "$CSV_FILE" ]; then
RECENT_AVG=$(tail -5 "$CSV_FILE" | awk -F',' '{sum += $3; count++} END {print sum/count}')
echo "Recent average (5 builds): ${RECENT_AVG}s"
# Regresi jika lebih dari 20% di atas rata-rata
REGRESSION_LIMIT=$(echo "$RECENT_AVG * 1.20" | bc)
if (( $(echo "$ELAPSED > $REGRESSION_LIMIT" | bc -l) )); then
echo "⚠️ BUILD TIME REGRESSION DETECTED!"
echo "Current: ${ELAPSED}s, Limit: ${REGRESSION_LIMIT}s"
exit 1
fi
fi
if [ "$ELAPSED" -gt "$THRESHOLD_SECONDS" ]; then
echo "⚠️ Build time exceeds threshold!"
exit 1
fi
echo "✓ Build time OK"
Makefile untuk Standardisasi
swift
# Makefile — perintah build yang konsisten di semua mesin
.PHONY: build test clean measure setup
SCHEME = MyApp
WORKSPACE = MyApp.xcworkspace
DESTINATION = platform=iOS Simulator,name=iPhone 16