From 798e461e4e5ddac308cbc17e5cea71b2b2d58c88 Mon Sep 17 00:00:00 2001 From: Mohmmed Elfateh Sabry <59346303+elfateh4@users.noreply.github.com> Date: Mon, 11 Aug 2025 14:53:17 +0300 Subject: [PATCH] Enhance deployment script to force reset local changes and backup modified files --- .github/workflows/deploy.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 02e7ba7..a91e4ae 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,10 +43,16 @@ jobs: "export REMOTE_DIR='${{ secrets.REMOTE_DIR }}'; bash -se" <<'EOF' set -euo pipefail 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 - git reset --hard HEAD - git clean -fd + echo "Git repository detected, resetting changes..." + 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 EOF @@ -56,6 +62,7 @@ jobs: -e "ssh -p ${{ secrets.SSH_PORT }}" \ --exclude ".git" \ --exclude ".github" \ + --exclude ".env" \ ./ "${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${REMOTE_DIR}/" - name: Write .env on VPS (from GitHub Secrets)