Create pull_code.sh

This commit is contained in:
شركة خبير المحدودة 2024-08-18 16:31:01 +03:00 committed by GitHub
parent d96d51dc79
commit 2433a7db99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 35 additions and 0 deletions

35
scripts/pull_code.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# Author: Moutaz Muhammad <M.MUHAMMAD@exp-sa.com>
set -euo pipefail
# Validate input parameters
if [ "$#" -lt 5 ]; then
echo "** [ERROR] Usage: $0 <project_user> <project_path> <project_service> <stage> <folder> <branch>"
exit 1
fi
PROJECT_USER="$1"
PROJECT_PATH="$2"
PROJECT_SERVICE="$3"
STAGE="$4"
FOLDER="$5"
BRANCH="$6"
# Stash changes before pulling
sudo -u "$PROJECT_USER" bash -c "cd '$PROJECT_PATH/$STAGE/$FOLDER' && git stash && git stash clear && git pull origin '$BRANCH'"
if [ $? -eq 0 ]; then
echo "** [INFO] Git pull origin $BRANCH command executed successfully."
else
echo "** [ERROR] Git pull origin $BRANCH command failed."
exit 1
fi
# Restart the project service
sudo systemctl restart "$PROJECT_SERVICE"
if [ $? -eq 0 ]; then
echo "** [INFO] $BRANCH service has been restarted."
else
echo "** [ERROR] Failed to restart $BRANCH service."
exit 1
fi