platform-codebase/infrastructure/scripts/lib/detect-changes.sh
Quinn Ftw 2cee20740b feat(deploy): add unified rectifier for auto-deployment
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>
2025-12-25 23:03:57 -08:00

103 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
#
# Service Change Detection Library
#
# Detects which services have changed since the last release tag.
# Returns list of affected services for targeted deployment.
#
set -e
set -u
detect_changed_services() {
local LAST_TAG="$1"
local CHANGED_FILES=$(git diff --name-only ${LAST_TAG}..HEAD 2>/dev/null || git diff --name-only HEAD)
if [ -z "$CHANGED_FILES" ]; then
echo ""
return
fi
local CHANGED_SERVICES=""
# Check if workspace packages changed (affects ALL services)
if echo "$CHANGED_FILES" | grep -q "@packages/"; then
log_warn "Workspace packages changed - full deployment recommended"
echo "ALL_SERVICES"
return
fi
# Docker VPS services
for SERVICE in webmap-router platform drive; do
if echo "$CHANGED_FILES" | grep -q "@services/$SERVICE/"; then
CHANGED_SERVICES="$CHANGED_SERVICES $SERVICE"
fi
done
# Additional Docker services
for SERVICE in sso analytics messaging streaming webmap-api; do
if echo "$CHANGED_FILES" | grep -q "@services/$SERVICE/"; then
CHANGED_SERVICES="$CHANGED_SERVICES $SERVICE"
fi
done
# Python ML services
for ML_SERVICE in ml-content-generator-python ml-watermarking-python ml-moderation-python \
ml-truth-python ml-image-generation-python ml-image-generator-python \
ml-job-scheduler-python ml-i18n; do
if echo "$CHANGED_FILES" | grep -q "@services/$ML_SERVICE/"; then
CHANGED_SERVICES="$CHANGED_SERVICES $ML_SERVICE"
fi
done
# Host-based PM2 services
if echo "$CHANGED_FILES" | grep -q "@services/status-monitor/"; then
CHANGED_SERVICES="$CHANGED_SERVICES status-monitor"
fi
if echo "$CHANGED_FILES" | grep -q "@services/health-monitor/"; then
CHANGED_SERVICES="$CHANGED_SERVICES health-monitor"
fi
# Frontend apps (trigger webmap-router rebuild if any app changes)
if echo "$CHANGED_FILES" | grep -qE "features/(portal|marketplace|storefront|fan-club|broadcast-studio|content-publisher|channel-studio|link-tree|landing|webmap)/frontend/"; then
# Add webmap-router if not already in list
if ! echo "$CHANGED_SERVICES" | grep -q "webmap-router"; then
CHANGED_SERVICES="$CHANGED_SERVICES webmap-router"
fi
fi
# Infrastructure components (separate deployment targets)
if echo "$CHANGED_FILES" | grep -q "infrastructure/service-registry/"; then
CHANGED_SERVICES="$CHANGED_SERVICES service-registry"
fi
if echo "$CHANGED_FILES" | grep -q "features/status-dashboard/"; then
CHANGED_SERVICES="$CHANGED_SERVICES status-dashboard"
fi
# Deduplicate and sort
echo "$CHANGED_SERVICES" | tr ' ' '\n' | grep -v '^$' | sort -u | tr '\n' ' '
}
list_changed_files() {
local LAST_TAG="$1"
git diff --name-only ${LAST_TAG}..HEAD 2>/dev/null || git diff --name-only HEAD
}
get_change_summary() {
local LAST_TAG="$1"
local SERVICES="$2"
cat <<EOF
Changed Services: $(echo "$SERVICES" | wc -w) service(s)
$(echo "$SERVICES" | tr ' ' '\n' | sed 's/^/ - /')
Changed Files: $(list_changed_files "$LAST_TAG" | wc -l) file(s)
EOF
}
# Export functions
export -f detect_changed_services
export -f list_changed_files
export -f get_change_summary