firehose/clean_build.sh
2026-07-06 16:56:54 +01:00

124 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Clean Build Script for Firehose Monorepo
# This script performs a full clean rebuild of the Phoenix application
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="${SCRIPT_DIR}/app"
echo "🔧 Starting clean build..."
# Function to check if PostgreSQL is running
check_postgres() {
if command -v pg_isready >/dev/null 2>&1; then
if pg_isready -q 2>/dev/null; then
echo "✅ PostgreSQL is running"
return 0
fi
fi
# Check common locations
if curl -s http://localhost:5432 >/dev/null 2>&1; then
echo "✅ PostgreSQL is running (port 5432)"
return 0
fi
echo "⚠️ PostgreSQL is not running. Skipping tests."
return 1
}
# Function to set SSL certificates if needed
set_ssl_certs() {
# Check for Homebrew CA certs
if [ -f "/opt/homebrew/etc/ca-certificates/cert.pem" ]; then
export SSL_CACERTFILE="/opt/homebrew/etc/ca-certificates/cert.pem"
export SSL_CACERT="/opt/homebrew/etc/ca-certificates/cert.pem"
echo "✅ SSL certificates set (Homebrew)"
elif [ -f "/usr/local/etc/ca-certificates/cert.pem" ]; then
export SSL_CACERTFILE="/usr/local/etc/ca-certificates/cert.pem"
export SSL_CACERT="/usr/local/etc/ca-certificates/cert.pem"
echo "✅ SSL certificates set (/usr/local)"
fi
}
# Step 1: Clean build artifacts
echo "🧹 Cleaning build artifacts..."
cd "$APP_DIR"
# Remove all build artifacts
rm -rf _build
rm -rf deps/*.exs # Remove compiled deps
rm -rf priv/static
if [ -d "config" ] && [ -f "config/config.exs" ]; then
# Don't remove the config files themselves, just generated ones
rm -f config/runtime.exs
fi
echo "✅ Cleaned build artifacts"
# Step 2: Set up environment
set_ssl_certs
# Check if Hex is installed
if ! command -v mix >/dev/null 2>&1; then
echo "❌ Mix not found in PATH. Please install Elixir first."
exit 1
fi
# Install Hex if not present
if ! mix hex version >/dev/null 2>&1; then
echo "📦 Installing Hex..."
mix local.hex --force
fi
# Step 3: Get dependencies
echo "📥 Fetching dependencies..."
mise exec -- mix deps.get
echo "✅ Dependencies fetched"
# Step 4: Compile dependencies
echo "🔨 Compiling dependencies..."
mise exec -- mix deps.compile
echo "✅ Dependencies compiled"
# Step 5: Compile the project
echo "🏗️ Compiling project..."
mise exec -- mix compile --warnings-as-errors
echo "✅ Project compiled successfully"
# Step 6: Run tests (if PostgreSQL is available)
if check_postgres; then
echo "🧪 Running tests..."
mise exec -- mix test
if [ $? -eq 0 ]; then
echo "✅ All tests passed"
else
echo "❌ Some tests failed"
exit 1
fi
else
echo "⚠️ Skipping tests (PostgreSQL not available)"
fi
# Step 7: Format code (optional but recommended)
echo "✨ Formatting code..."
mise exec -- mix format
echo "✅ Code formatted"
echo ""
echo "🎉 Clean build completed successfully!"
echo ""
echo "To start the development server:"
echo " cd $APP_DIR"
echo " mise exec -- mix phx.server"
echo ""
echo "Or to run in release mode:"
echo " mise exec -- mix release"
echo " ./_build/dev/rel/firehose/bin/firehose console"