From 1e1d6bcdeecbfecd0da5d1c87d3939ce5f10e70a Mon Sep 17 00:00:00 2001 From: server Date: Wed, 29 Oct 2025 13:50:58 +0000 Subject: [PATCH] make deploy.sh executable --- deploy.sh | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) mode change 100644 => 100755 deploy.sh diff --git a/deploy.sh b/deploy.sh old mode 100644 new mode 100755 index 1b8d9bb..b678af7 --- a/deploy.sh +++ b/deploy.sh @@ -1,24 +1,45 @@ #!/bin/bash +set -euo pipefail -APP_DIR="/home/ubuntu/AyposWeb" +cd /home/ubuntu/Bgreen/AyposWeb -# Navigate to your app directory -cd "$APP_DIR" || { echo "Failed to cd to $APP_DIR"; exit 1; } +echo "Fetching latest changes from origin/main..." +git fetch origin main -# Pull latest changes from Gitea -echo "Pulling latest code..." -git pull origin main || { echo "Git pull failed"; exit 1; } +CHANGED_FILES=$(git diff --name-only HEAD origin/main || true) -# Build your app (change this to your build command) -# For example, npm build: -echo "Installing dependencies..." -npm install || { echo "npm install failed"; exit 1; } +if [ -z "$CHANGED_FILES" ]; then + echo "No file changes detected." +else + echo "Changed files:" + echo "$CHANGED_FILES" +fi -echo "Building app..." -npm run build || { echo "npm build failed"; exit 1; } +git reset --hard origin/main -# Restart your app (change this to your app's restart command) -# For example, systemctl restart myapp.service: -systemctl reload nginx || { echo "Failed to reload nginx"; exit 1; } +FRONTEND_CHANGED=false -echo "Deployment complete" +if echo "$CHANGED_FILES" | grep -qv "README\.md$"; then + FRONTEND_CHANGED=true +fi + +if [ "$FRONTEND_CHANGED" = true ]; then + echo "Frontend changes detected." + + if echo "$CHANGED_FILES" | grep -qE "^(package\.json|package-lock\.json)$"; then + echo "Package files changed. Running npm install and build..." + npm install + npm run build + else + echo "Only code changes detected. Running build..." + npm run build + fi + + cd .. + echo "Rebuilding frontend container..." + docker compose up -d --build aypos-frontend +else + echo "No frontend changes." +fi + +echo "Deployment complete."