This commit is contained in:
@@ -98,34 +98,62 @@ jobs:
|
||||
SSH_CMD="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||
RSYNC_RSH="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||
CHANGE_PATHS=(app/controllers app/middlewares app/models app/routes app/scheduler app/services)
|
||||
CHANGED_LIST_FILE="$(mktemp)"
|
||||
DELETED_LIST_FILE="$(mktemp)"
|
||||
DIRS_LIST_FILE="$(mktemp)"
|
||||
|
||||
is_excluded_path() {
|
||||
case "$1" in
|
||||
*.DS_Store|*/.DS_Store|_MACOSX|_MACOSX/*|*/_MACOSX|*/_MACOSX/*) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
|
||||
CHANGED_FILES=$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
||||
DELETED_FILES=$(git diff --name-only --diff-filter=D "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
is_excluded_path "$file" && continue
|
||||
printf '%s\n' "$file" >> "$CHANGED_LIST_FILE"
|
||||
done < <(git diff --name-only --diff-filter=ACMRT "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
is_excluded_path "$file" && continue
|
||||
printf '%s\n' "$file" >> "$DELETED_LIST_FILE"
|
||||
done < <(git diff --name-only --diff-filter=D "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||
else
|
||||
CHANGED_FILES=$(git show --name-only --pretty="" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
||||
DELETED_FILES=""
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
is_excluded_path "$file" && continue
|
||||
[ -f "$file" ] || continue
|
||||
printf '%s\n' "$file" >> "$CHANGED_LIST_FILE"
|
||||
done < <(git show --name-only --pretty="" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||
fi
|
||||
|
||||
if [ -z "$CHANGED_FILES" ]; then
|
||||
if [ ! -s "$CHANGED_LIST_FILE" ]; then
|
||||
echo "No backend file changes detected in target folders."
|
||||
else
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
[ -f "$file" ] || continue
|
||||
remote_file="$REMOTE_APP_ROOT/$file"
|
||||
remote_dir=$(dirname "$remote_file")
|
||||
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo mkdir -p \"$remote_dir\""
|
||||
rsync -az --exclude ".DS_Store" --exclude "_MACOSX" --rsync-path="sudo rsync" -e "$RSYNC_RSH" "$file" "$REMOTE_USER@$REMOTE_HOST:$remote_file"
|
||||
echo "Deployed: $file"
|
||||
done <<< "$CHANGED_FILES"
|
||||
printf '%s\n' "$(dirname "$file")"
|
||||
done < "$CHANGED_LIST_FILE" | awk '!seen[$0]++' > "$DIRS_LIST_FILE"
|
||||
|
||||
while IFS= read -r dir; do
|
||||
[ -z "$dir" ] && continue
|
||||
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo mkdir -p \"$REMOTE_APP_ROOT/$dir\""
|
||||
done < "$DIRS_LIST_FILE"
|
||||
|
||||
rsync -az --files-from="$CHANGED_LIST_FILE" --exclude ".DS_Store" --exclude "_MACOSX" --rsync-path="sudo rsync" -e "$RSYNC_RSH" ./ "$REMOTE_USER@$REMOTE_HOST:$REMOTE_APP_ROOT/"
|
||||
echo "Deployed backend changes from CHANGE_PATHS."
|
||||
fi
|
||||
|
||||
if [ -n "$DELETED_FILES" ]; then
|
||||
if [ -s "$DELETED_LIST_FILE" ]; then
|
||||
while IFS= read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
remote_file="$REMOTE_APP_ROOT/$file"
|
||||
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo rm -f \"$remote_file\""
|
||||
echo "Deleted on remote: $file"
|
||||
done <<< "$DELETED_FILES"
|
||||
done < "$DELETED_LIST_FILE"
|
||||
fi
|
||||
|
||||
rm -f "$CHANGED_LIST_FILE" "$DELETED_LIST_FILE" "$DIRS_LIST_FILE"
|
||||
|
||||
Reference in New Issue
Block a user