Enhance deployment script to force reset local changes and backup modified files

This commit is contained in:
Mohmmed Elfateh Sabry
2025-08-11 14:53:17 +03:00
parent 0bc47b65c1
commit 798e461e4e

View File

@@ -43,10 +43,16 @@ jobs:
"export REMOTE_DIR='${{ secrets.REMOTE_DIR }}'; bash -se" <<'EOF' "export REMOTE_DIR='${{ secrets.REMOTE_DIR }}'; bash -se" <<'EOF'
set -euo pipefail set -euo pipefail
cd "$REMOTE_DIR" cd "$REMOTE_DIR"
# Reset any local changes if this is a git repository # Force reset any local changes regardless of git status
if [ -d ".git" ]; then if [ -d ".git" ]; then
git reset --hard HEAD echo "Git repository detected, resetting changes..."
git clean -fd git reset --hard HEAD 2>/dev/null || true
git clean -fd 2>/dev/null || true
git checkout main 2>/dev/null || git checkout master 2>/dev/null || true
else
echo "No git repository found, creating backup of modified files..."
# Backup any existing files that might conflict
[ -f "docker-compose.yml" ] && cp docker-compose.yml docker-compose.yml.backup.$(date +%s) || true
fi fi
EOF EOF
@@ -56,6 +62,7 @@ jobs:
-e "ssh -p ${{ secrets.SSH_PORT }}" \ -e "ssh -p ${{ secrets.SSH_PORT }}" \
--exclude ".git" \ --exclude ".git" \
--exclude ".github" \ --exclude ".github" \
--exclude ".env" \
./ "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${REMOTE_DIR}/" ./ "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${REMOTE_DIR}/"
- name: Write .env on VPS (from GitHub Secrets) - name: Write .env on VPS (from GitHub Secrets)