#!/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"