OSVauco/scripts/preflight-check.sh
2026-05-26 13:40:07 +00:00

74 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# preflight-check.sh — Verifies the local development environment for OSVauco OPAX.
set -euo pipefail
# --- Configuration & Helpers ---
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
FAIL_COUNT=0
step_info() { echo "[INFO] $1"; }
step_ok() { echo "$1"; }
step_fail() {
echo "$1"
FAIL_COUNT=$((FAIL_COUNT + 1))
}
# --- Preflight Checks ---
echo "=================================================================="
echo "=> Running OSVauco Preflight Checks"
echo "=================================================================="
# Check 1: gcloud authentication and project config
step_info "Checking GCP authentication..."
if bash "$ROOT_DIR/infrastructure/00-authcheck.sh" &>/dev/null; then
step_ok "gcloud is authenticated and project is set."
else
step_fail "gcloud authentication or project is not configured. Run 'gcloud auth login' and 'gcloud config set project <project_id>'."
fi
# Check 2: .env file existence
step_info "Checking for .env file..."
if [ -f "$ROOT_DIR/.env" ]; then
step_ok ".env file found."
# Source it for the next check
source "$ROOT_DIR/.env"
else
step_fail ".env file not found. Please copy .env.example to .env and fill in the required values."
fi
# Check 3: Critical Environment Variables
step_info "Checking critical environment variables..."
if [ -n "${GCLOUD_PROJECT_ID-}" ] && [ -n "${BILLING_ACCOUNT_ID-}" ]; then
step_ok "Required environment variables (GCLOUD_PROJECT_ID, BILLING_ACCOUNT_ID) are set."
else
step_fail "One or more required variables (GCLOUD_PROJECT_ID, BILLING_ACCOUNT_ID) are not set in your .env file."
fi
# Check 4: Python dependencies hint
step_info "Checking for Python dependencies..."
if [ -f "$ROOT_DIR/requirements.txt" ]; then
step_ok "requirements.txt found. Ensure dependencies are installed with 'pip install -r requirements.txt'."
else
step_fail "requirements.txt not found."
fi
# Check 5: Git working directory status
step_info "Checking Git status..."
if git -C "$ROOT_DIR" diff --quiet && git -C "$ROOT_DIR" diff --cached --quiet; then
step_ok "Git working directory is clean."
else
step_fail "Git working directory has uncommitted changes. Please commit or stash them."
fi
# --- Summary ---
echo "=================================================================="
if [ $FAIL_COUNT -eq 0 ]; then
echo "✅✅✅ Preflight checks passed successfully! ✅✅✅"
exit 0
else
echo "❌❌❌ Preflight checks failed with $FAIL_COUNT error(s). Please resolve them and re-run. ❌❌❌"
exit 1
fi