Implements a proper "rectifier" pattern that detects changed components and deploys them automatically when pushing to main. Changes: - Add rectify-deploy.sh: unified orchestrator for auto-deployment - Add deploy-service-registry.sh: service-registry deployment script - Update detect-changes.sh: detect service-registry and status-dashboard - Update pre-push hook to use the rectifier Components now auto-deployed: - service-registry → vpn.1984.nasty.sh - status-dashboard → 0.1984.nasty.sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
164 lines
5 KiB
Bash
Executable file
164 lines
5 KiB
Bash
Executable file
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
#
|
||
# Rectifier Deployment Script
|
||
#
|
||
# Unified auto-deploy that detects changed components and deploys them.
|
||
# Called by pre-push hook after pushing to main.
|
||
#
|
||
# Components handled:
|
||
# - status-dashboard → deploy-status-dashboard.sh
|
||
# - service-registry → deploy-service-registry.sh
|
||
# - Platform services → release-deploy.sh (full pipeline)
|
||
#
|
||
# Usage: ./rectify-deploy.sh [--dry-run]
|
||
#
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||
|
||
# Source detection library
|
||
source "$SCRIPT_DIR/lib/detect-changes.sh" 2>/dev/null || {
|
||
echo "Warning: detect-changes.sh not found, using basic detection"
|
||
}
|
||
|
||
# Inline logging
|
||
log_header() { echo -e "\n\033[1;35m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"; echo -e "\033[1;35m $1\033[0m"; echo -e "\033[1;35m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"; }
|
||
log_step() { echo -e "\n\033[1;34m▶\033[0m $1"; }
|
||
log_info() { echo -e "\033[0;36m ℹ\033[0m $1"; }
|
||
log_success() { echo -e "\033[0;32m ✓\033[0m $1"; }
|
||
log_error() { echo -e "\033[0;31m ✗\033[0m $1"; }
|
||
log_warn() { echo -e "\033[0;33m ⚠\033[0m $1"; }
|
||
|
||
DRY_RUN="${1:-}"
|
||
|
||
# =============================================================================
|
||
# DETECT CHANGES
|
||
# =============================================================================
|
||
|
||
detect_all_changes() {
|
||
log_step "Detecting changed components..."
|
||
|
||
cd "$PROJECT_ROOT"
|
||
|
||
# Get list of changed files since last push
|
||
local CHANGED_FILES
|
||
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD 2>/dev/null || git diff --name-only HEAD)
|
||
|
||
if [ -z "$CHANGED_FILES" ]; then
|
||
log_info "No changes detected"
|
||
return
|
||
fi
|
||
|
||
local COMPONENTS=""
|
||
|
||
# Status Dashboard
|
||
if echo "$CHANGED_FILES" | grep -q "features/status-dashboard/"; then
|
||
COMPONENTS="$COMPONENTS status-dashboard"
|
||
fi
|
||
|
||
# Service Registry
|
||
if echo "$CHANGED_FILES" | grep -q "infrastructure/service-registry/"; then
|
||
COMPONENTS="$COMPONENTS service-registry"
|
||
fi
|
||
|
||
# UI packages (affects both)
|
||
if echo "$CHANGED_FILES" | grep -q "@packages/@ui/"; then
|
||
if ! echo "$COMPONENTS" | grep -q "status-dashboard"; then
|
||
COMPONENTS="$COMPONENTS status-dashboard"
|
||
fi
|
||
if ! echo "$COMPONENTS" | grep -q "service-registry"; then
|
||
COMPONENTS="$COMPONENTS service-registry"
|
||
fi
|
||
fi
|
||
|
||
echo "$COMPONENTS" | tr ' ' '\n' | grep -v '^$' | sort -u | tr '\n' ' '
|
||
}
|
||
|
||
# =============================================================================
|
||
# DEPLOY COMPONENTS
|
||
# =============================================================================
|
||
|
||
deploy_component() {
|
||
local component="$1"
|
||
|
||
log_step "Deploying: $component"
|
||
|
||
if [ "$DRY_RUN" = "--dry-run" ]; then
|
||
log_info "[DRY RUN] Would deploy $component"
|
||
return 0
|
||
fi
|
||
|
||
case "$component" in
|
||
status-dashboard)
|
||
if [ -x "$SCRIPT_DIR/deploy-status-dashboard.sh" ]; then
|
||
"$SCRIPT_DIR/deploy-status-dashboard.sh" --full || {
|
||
log_warn "status-dashboard deployment failed (continuing)"
|
||
return 1
|
||
}
|
||
else
|
||
log_error "deploy-status-dashboard.sh not found"
|
||
return 1
|
||
fi
|
||
;;
|
||
service-registry)
|
||
if [ -x "$SCRIPT_DIR/deploy-service-registry.sh" ]; then
|
||
"$SCRIPT_DIR/deploy-service-registry.sh" --full || {
|
||
log_warn "service-registry deployment failed (continuing)"
|
||
return 1
|
||
}
|
||
else
|
||
log_error "deploy-service-registry.sh not found"
|
||
return 1
|
||
fi
|
||
;;
|
||
*)
|
||
log_warn "Unknown component: $component (skipping)"
|
||
;;
|
||
esac
|
||
|
||
log_success "$component deployed"
|
||
}
|
||
|
||
# =============================================================================
|
||
# MAIN
|
||
# =============================================================================
|
||
|
||
main() {
|
||
log_header "Rectifier Auto-Deploy"
|
||
|
||
cd "$PROJECT_ROOT"
|
||
|
||
# Detect what changed
|
||
local CHANGED_COMPONENTS
|
||
CHANGED_COMPONENTS=$(detect_all_changes)
|
||
|
||
if [ -z "$CHANGED_COMPONENTS" ]; then
|
||
log_info "No deployable components changed"
|
||
return 0
|
||
fi
|
||
|
||
log_info "Components to deploy: $CHANGED_COMPONENTS"
|
||
|
||
# Deploy each component
|
||
local DEPLOY_COUNT=0
|
||
local FAIL_COUNT=0
|
||
|
||
for component in $CHANGED_COMPONENTS; do
|
||
if deploy_component "$component"; then
|
||
((DEPLOY_COUNT++)) || true
|
||
else
|
||
((FAIL_COUNT++)) || true
|
||
fi
|
||
done
|
||
|
||
echo ""
|
||
log_header "Rectifier Complete"
|
||
log_info "Deployed: $DEPLOY_COUNT component(s)"
|
||
if [ "$FAIL_COUNT" -gt 0 ]; then
|
||
log_warn "Failed: $FAIL_COUNT component(s)"
|
||
fi
|
||
}
|
||
|
||
main "$@"
|