FSCash/update.sh
fds2610-bot 6f377ea251 V.2.2: Unit-Tests für wichtige Funktionen, automatisch geprüft bei Update
Extrahiert die wichtigste DB-/netzwerkfreie Geschäftslogik (Monatsnavigation,
Admin-/Aktien-Rollenprüfung, Aktien-GuV-Berechnung, OpenFIGI-/Alpha-Vantage-
Antwortauswertung, Eingabevalidierung, CSV-Export, Migrations-Logik) nach
html/lib/fscash.php und deckt sie mit 31 PHPUnit-Tests ab. update.sh
installiert Composer-Abhängigkeiten bei Bedarf und führt die Tests jetzt vor
jedem Deploy aus - bei Fehlschlag wird nichts kopiert oder migriert.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-23 17:54:30 +02:00

77 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Deployt den aktuellen git-Stand dieses Projektverzeichnisses in den Webroot
# und wendet danach ausstehende Datenbank-Migrationen an.
#
# Aufruf (im Projektverzeichnis):
# ./update.sh
#
# Optional per Umgebungsvariable überschreibbar:
# WEBROOT=/anderer/pfad ./update.sh
# CONFIG_FILE=/anderer/pfad/config.php ./update.sh
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEBROOT="${WEBROOT:-/var/www/html}"
CONFIG_FILE="${CONFIG_FILE:-$WEBROOT/config.php}"
log() { echo "==> $*"; }
fail() { echo "FEHLER: $*" >&2; exit 1; }
cd "$PROJECT_DIR"
command -v php >/dev/null 2>&1 || fail "php ist nicht installiert bzw. nicht im PATH."
[ -d "$WEBROOT" ] || fail "Webroot $WEBROOT existiert nicht."
[ -w "$WEBROOT" ] || fail "Keine Schreibrechte auf $WEBROOT."
# --- 1. Sicherstellen, dass das Projektverzeichnis sauber ist ---
if ! git diff --quiet || ! git diff --cached --quiet; then
fail "Lokale Änderungen im Projektverzeichnis vorhanden - bitte erst committen oder stashen."
fi
# --- 2. Neuesten Stand holen ---
log "git pull..."
git pull --ff-only
# --- 3. PHP-Syntaxcheck als Sicherheitsnetz vor dem Kopieren ---
log "Prüfe PHP-Syntax..."
while IFS= read -r -d '' file; do
php -l "$file" >/dev/null || fail "Syntaxfehler in $file - es wird nichts kopiert."
done < <(find html -name '*.php' -print0)
# --- 4. Unit-Tests: müssen grün sein, bevor irgendetwas deployt wird ---
if [ -f tests/run.sh ]; then
if [ ! -x vendor/bin/phpunit ]; then
command -v composer >/dev/null 2>&1 || fail "composer ist nicht installiert - wird für die Tests benötigt."
log "Installiere Test-Abhängigkeiten (composer install)..."
composer install --no-interaction --no-progress
fi
log "Führe Tests aus..."
bash tests/run.sh || fail "Tests fehlgeschlagen - es wird nichts deployt. Siehe Ausgabe oben."
else
log "Noch keine Tests vorhanden - werden später ergänzt."
fi
# --- 5. Dateien kopieren, config.php bleibt unangetastet ---
log "Kopiere Dateien nach $WEBROOT..."
config_backup=""
if [ -f "$CONFIG_FILE" ]; then
config_backup="$(mktemp)"
cp "$CONFIG_FILE" "$config_backup"
fi
cp -r html/. "$WEBROOT/"
if [ -n "$config_backup" ]; then
cp "$config_backup" "$CONFIG_FILE"
rm -f "$config_backup"
fi
# --- 6. Datenbank-Migrationen ---
if [ -d migrations ] && [ -f migrations/run_migrations.php ]; then
log "Wende Datenbank-Migrationen an..."
php migrations/run_migrations.php "$CONFIG_FILE"
fi
log "Update abgeschlossen."