mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 12:41:46 +00:00
feat: Enhance clean, optimize, analyze, and status commands, and update security audit documentation.
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Build Universal Binary for analyze-go
|
||||
# Supports both Apple Silicon and Intel Macs
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# Check if Go is installed
|
||||
if ! command -v go > /dev/null 2>&1; then
|
||||
echo "Error: Go not installed"
|
||||
echo "Install: brew install go"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building analyze-go for multiple architectures..."
|
||||
|
||||
# Get version info
|
||||
VERSION=$(git describe --tags --always --dirty 2> /dev/null || echo "dev")
|
||||
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
LDFLAGS="-s -w -X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME"
|
||||
|
||||
echo " Version: $VERSION"
|
||||
echo " Build time: $BUILD_TIME"
|
||||
echo ""
|
||||
|
||||
# Build for arm64 (Apple Silicon)
|
||||
echo " → Building for arm64..."
|
||||
GOARCH=arm64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-arm64 ./cmd/analyze
|
||||
|
||||
# Build for amd64 (Intel)
|
||||
echo " → Building for amd64..."
|
||||
GOARCH=amd64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-amd64 ./cmd/analyze
|
||||
|
||||
# Create Universal Binary
|
||||
echo " → Creating Universal Binary..."
|
||||
lipo -create bin/analyze-go-arm64 bin/analyze-go-amd64 -output bin/analyze-go
|
||||
|
||||
# Clean up temporary files
|
||||
rm bin/analyze-go-arm64 bin/analyze-go-amd64
|
||||
|
||||
# Verify
|
||||
echo ""
|
||||
echo "✓ Build complete!"
|
||||
echo ""
|
||||
file bin/analyze-go
|
||||
size_bytes=$(/usr/bin/stat -f%z bin/analyze-go 2> /dev/null || echo 0)
|
||||
size_mb=$((size_bytes / 1024 / 1024))
|
||||
printf "Size: %d MB (%d bytes)\n" "$size_mb" "$size_bytes"
|
||||
echo ""
|
||||
echo "Binary supports: arm64 (Apple Silicon) + x86_64 (Intel)"
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Build Universal Binary for status-go
|
||||
# Supports both Apple Silicon and Intel Macs
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if ! command -v go > /dev/null 2>&1; then
|
||||
echo "Error: Go not installed"
|
||||
echo "Install: brew install go"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building status-go for multiple architectures..."
|
||||
|
||||
VERSION=$(git describe --tags --always --dirty 2> /dev/null || echo "dev")
|
||||
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
LDFLAGS="-s -w -X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME"
|
||||
|
||||
echo " Version: $VERSION"
|
||||
echo " Build time: $BUILD_TIME"
|
||||
echo ""
|
||||
|
||||
echo " → Building for arm64..."
|
||||
GOARCH=arm64 go build -ldflags="$LDFLAGS" -trimpath -o bin/status-go-arm64 ./cmd/status
|
||||
|
||||
echo " → Building for amd64..."
|
||||
GOARCH=amd64 go build -ldflags="$LDFLAGS" -trimpath -o bin/status-go-amd64 ./cmd/status
|
||||
|
||||
echo " → Creating Universal Binary..."
|
||||
lipo -create bin/status-go-arm64 bin/status-go-amd64 -output bin/status-go
|
||||
|
||||
rm bin/status-go-arm64 bin/status-go-amd64
|
||||
|
||||
echo ""
|
||||
echo "✓ Build complete!"
|
||||
echo ""
|
||||
file bin/status-go
|
||||
size_bytes=$(/usr/bin/stat -f%z bin/status-go 2> /dev/null || echo 0)
|
||||
size_mb=$((size_bytes / 1024 / 1024))
|
||||
printf "Size: %d MB (%d bytes)\n" "$size_mb" "$size_bytes"
|
||||
echo ""
|
||||
echo "Binary supports: arm64 (Apple Silicon) + x86_64 (Intel)"
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Pre-commit hook to ensure bin/analyze-go and bin/status-go are universal binaries
|
||||
|
||||
set -e
|
||||
|
||||
# ANSI color codes
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if binaries are being added or modified (ignore deletions)
|
||||
binaries=()
|
||||
while read -r status path; do
|
||||
case "$status" in
|
||||
A|M)
|
||||
if [[ "$path" == "bin/analyze-go" || "$path" == "bin/status-go" ]]; then
|
||||
binaries+=("$path")
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done < <(git diff --cached --name-status)
|
||||
|
||||
# If no binaries are being committed, exit early
|
||||
if [[ ${#binaries[@]} -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Checking compiled binaries...${NC}"
|
||||
|
||||
# Verify each binary is a universal binary
|
||||
all_valid=true
|
||||
for binary in "${binaries[@]}"; do
|
||||
if [[ ! -f "$binary" ]]; then
|
||||
echo -e "${RED}✗ $binary not found${NC}"
|
||||
all_valid=false
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if it's a universal binary
|
||||
if file "$binary" | grep -q "Mach-O universal binary"; then
|
||||
# Verify it contains both x86_64 and arm64
|
||||
if lipo -info "$binary" 2>/dev/null | grep -q "x86_64 arm64"; then
|
||||
echo -e "${GREEN}✓ $binary is a universal binary (x86_64 + arm64)${NC}"
|
||||
elif lipo -info "$binary" 2>/dev/null | grep -q "arm64 x86_64"; then
|
||||
echo -e "${GREEN}✓ $binary is a universal binary (x86_64 + arm64)${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ $binary is missing required architectures${NC}"
|
||||
lipo -info "$binary"
|
||||
all_valid=false
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}✗ $binary is not a universal binary${NC}"
|
||||
file "$binary"
|
||||
all_valid=false
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$all_valid" == "false" ]]; then
|
||||
echo ""
|
||||
echo -e "${RED}Commit rejected: binaries must be universal (x86_64 + arm64)${NC}"
|
||||
echo ""
|
||||
echo "To create universal binaries, run:"
|
||||
echo " ./scripts/build-analyze.sh"
|
||||
echo " ./scripts/build-status.sh"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}All binaries verified!${NC}"
|
||||
exit 0
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Install git hooks for Mole development
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
HOOKS_DIR="$REPO_ROOT/.git/hooks"
|
||||
|
||||
if [[ ! -d "$REPO_ROOT/.git" ]]; then
|
||||
echo "Error: Not in a git repository"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installing git hooks..."
|
||||
|
||||
# Install pre-commit hook
|
||||
if [[ -f "$SCRIPT_DIR/hooks/pre-commit" ]]; then
|
||||
cp "$SCRIPT_DIR/hooks/pre-commit" "$HOOKS_DIR/pre-commit"
|
||||
chmod +x "$HOOKS_DIR/pre-commit"
|
||||
echo "✓ Installed pre-commit hook (validates universal binaries)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Git hooks installed successfully!"
|
||||
echo ""
|
||||
echo "The pre-commit hook will ensure that bin/analyze-go and bin/status-go"
|
||||
echo "are universal binaries (x86_64 + arm64) before allowing commits."
|
||||
Reference in New Issue
Block a user