This commit is contained in:
2025-12-03 19:07:56 -05:00

View File

@@ -4,11 +4,13 @@ set -euo pipefail
BAR_WIDTH=50
SLEEP_INTERVAL=0.05
CLEAR_LINE="\033[K"
LOG_FILE="/var/log/laravel_deploy.log"
GREEN="\033[32m"
RESET="\033[0m"
# Keep track of Git HEAD for summary
OLD_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "")
STEPS=(
"Pull latest code"
"Maintenance mode"
@@ -39,7 +41,7 @@ CMDS=(
rollback(){
echo -e "\n\033[31m✘ Deployment failed. Rolling back...\033[0m"
git reset --hard HEAD@{1} >> "$LOG_FILE" 2>&1 || true
git reset --hard HEAD@{1} || true
php artisan up || true
exit 1
}
@@ -85,8 +87,8 @@ run_deployment() {
step_percent_start=$(( i * 100 / total_steps ))
step_percent_end=$(( (i+1) * 100 / total_steps ))
# Run the command: stdout/stderr go to log file only
bash -c "$cmd" > >(tee -a "$LOG_FILE" >/dev/null) 2> >(tee -a "$LOG_FILE" >/dev/null) &
# Run the command: output hidden, bar stays clean
bash -c "$cmd" > /dev/null 2>&1 &
pid=$!
percent=$step_percent_start
@@ -97,7 +99,6 @@ run_deployment() {
done
wait "$pid"
# Fill bar to end of step
echo -ne "\r$(draw_bar $step_percent_end $BAR_WIDTH "$step_name")$CLEAR_LINE"
done
@@ -113,7 +114,19 @@ run_deployment() {
green_bar="${final_bar:0:start+1}${GREEN}${final_text}${RESET}${final_bar:end+1}"
echo -e "\r$green_bar$CLEAR_LINE"
#echo "Log: $LOG_FILE"
# Git summary
if [ -n "$OLD_HEAD" ]; then
NEW_HEAD=$(git rev-parse HEAD)
if [ "$OLD_HEAD" != "$NEW_HEAD" ]; then
echo -e "Git changes since last deploy:"
git diff --shortstat "$OLD_HEAD" "$NEW_HEAD"
else
echo -e "No Git changes were applied."
fi
else
echo -e "Git repository initialized."
fi
}
run_deployment