Enhance deployment script to conditionally symlink data directories based on git tracking status, improving error handling for uncommitted changes. Implement cleanup of untracked files while preserving essential directories, ensuring a smoother deployment process.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 42s

This commit is contained in:
Torsten Schulz (local)
2026-01-07 18:08:07 +01:00
parent 946e5fadb0
commit a8423f9c39

View File

@@ -55,7 +55,13 @@ has_tracked_files_under() {
} }
echo "0. Ensuring persistent data directories (recommended)..." echo "0. Ensuring persistent data directories (recommended)..."
ensure_symlink_dir "server/data" "$DATA_ROOT/server-data" # IMPORTANT: Only symlink server/data if it's not tracked by git.
if has_tracked_files_under "server/data"; then
echo " Skipping symlink for server/data (tracked files detected in git)."
echo " Recommendation: remove server/data/** from git history and keep them only as production data."
else
ensure_symlink_dir "server/data" "$DATA_ROOT/server-data"
fi
# IMPORTANT: Only symlink public/data if it's not tracked by git. # IMPORTANT: Only symlink public/data if it's not tracked by git.
# Otherwise git will error with "path is beyond a symbolic link". # Otherwise git will error with "path is beyond a symbolic link".
@@ -104,13 +110,18 @@ if [ -n "$(git status --porcelain | grep '^UU\|^AA\|^DD')" ]; then
git reset --hard HEAD git reset --hard HEAD
fi fi
# Ensure a clean working tree (we avoid git stash because it breaks with symlinked data paths) # Ensure git operations can run even if we have untracked local artifacts (e.g. backups/)
if [ -n "$(git status --porcelain)" ]; then # We avoid `git stash` (breaks with symlinked tracked paths). Instead, hard-reset and clean safely.
echo "ERROR: Working tree is not clean. Please commit/revert changes before deployment." echo " Resetting working tree to HEAD (production data will be restored from backup)..."
echo "Hint: If this is caused by tracked production data files, remove them from git tracking." git reset --hard HEAD
git status --porcelain
exit 1 echo " Cleaning untracked files (excluding data dirs/backups/.env)..."
fi git clean -fd \
-e server/data \
-e public/data \
-e public/uploads \
-e backups \
-e .env || true
# Pull latest changes # Pull latest changes
echo " Pulling latest changes..." echo " Pulling latest changes..."