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
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 42s
This commit is contained in:
@@ -55,7 +55,13 @@ has_tracked_files_under() {
|
||||
}
|
||||
|
||||
echo "0. Ensuring persistent data directories (recommended)..."
|
||||
# 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.
|
||||
# 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
|
||||
fi
|
||||
|
||||
# Ensure a clean working tree (we avoid git stash because it breaks with symlinked data paths)
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "ERROR: Working tree is not clean. Please commit/revert changes before deployment."
|
||||
echo "Hint: If this is caused by tracked production data files, remove them from git tracking."
|
||||
git status --porcelain
|
||||
exit 1
|
||||
fi
|
||||
# Ensure git operations can run even if we have untracked local artifacts (e.g. backups/)
|
||||
# We avoid `git stash` (breaks with symlinked tracked paths). Instead, hard-reset and clean safely.
|
||||
echo " Resetting working tree to HEAD (production data will be restored from backup)..."
|
||||
git reset --hard HEAD
|
||||
|
||||
echo " Cleaning untracked files (excluding data dirs/backups/.env)..."
|
||||
git clean -fd \
|
||||
-e server/data \
|
||||
-e public/data \
|
||||
-e public/uploads \
|
||||
-e backups \
|
||||
-e .env || true
|
||||
|
||||
# Pull latest changes
|
||||
echo " Pulling latest changes..."
|
||||
|
||||
Reference in New Issue
Block a user