From a135c10dcb4e3049bac6780ef442c433bf53f45f Mon Sep 17 00:00:00 2001 From: Hubert Gruszecki Date: Sun, 1 Dec 2024 16:06:04 +0100 Subject: [PATCH] Improve CI scripts (#1372) - If server tag is present, use it. Otherise, just return sha1 - If server is not running after 2s, fail script --- .../run-standard-performance-suite.sh | 5 ++- scripts/performance/utils.sh | 36 +++++++++++++------ scripts/utils.sh | 11 ++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/scripts/performance/run-standard-performance-suite.sh b/scripts/performance/run-standard-performance-suite.sh index 0d0203d7a..0f6a3d6bb 100755 --- a/scripts/performance/run-standard-performance-suite.sh +++ b/scripts/performance/run-standard-performance-suite.sh @@ -63,8 +63,11 @@ for (( i=0; i<${#SUITES[@]} ; i+=2 )) ; do # Start iggy-server echo "Starting iggy-server..." target/release/iggy-server &> /dev/null & + IGGY_SERVER_PID=$! sleep 2 - echo + + # Check if the server is running + exit_if_process_is_not_running "$IGGY_SERVER_PID" # Start send bench echo "Running ${SEND_BENCH}" diff --git a/scripts/performance/utils.sh b/scripts/performance/utils.sh index d2124d809..8ce356356 100755 --- a/scripts/performance/utils.sh +++ b/scripts/performance/utils.sh @@ -5,28 +5,42 @@ COMMON_ARGS="--warmup-time 0" -# Function to get the current git tag or commit -function get_git_commit_or_tag() { - local dir=$1 +# Function to get the current git tag containing "server" or commit SHA1 +function get_git_iggy_server_tag_or_sha1() { + local dir="$1" if [ -d "$dir" ]; then - pushd "$dir" > /dev/null || exit 1 + pushd "$dir" > /dev/null || { + echo "Error: Failed to enter directory '$dir'." >&2 + exit 1 + } if git rev-parse --git-dir > /dev/null 2>&1; then + # Get the short commit hash local commit_hash commit_hash=$(git rev-parse --short HEAD) - local tag - tag=$(git describe --exact-match --tags HEAD 2> /dev/null) - popd > /dev/null || exit 1 + # Get all tags pointing to HEAD that contain "server" (case-insensitive) + local matching_tags + matching_tags=$(git tag --points-at HEAD | grep -i "server" || true) + + popd > /dev/null || { + echo "Error: Failed to return from directory '$dir'." >&2 + exit 1 + } - if [ -n "$tag" ]; then - echo "$tag" + if [ -n "$matching_tags" ]; then + # If multiple tags match, you can choose to return the first one + # or handle them as needed. Here, we'll return the first match. + local first_matching_tag + first_matching_tag=$(echo "$matching_tags" | head -n 1) + echo "$first_matching_tag" else + # No matching tag found; return the commit hash echo "$commit_hash" fi else - echo "Error: Not a git repository." >&2 + echo "Error: Directory '$dir' is not a git repository." >&2 popd > /dev/null || exit 1 return 1 fi @@ -62,7 +76,7 @@ function construct_bench_command() { local streams=${count} local superdir - superdir="performance_results_$(get_git_commit_or_tag .)" || { echo "Failed to get git commit or tag."; exit 1; } + superdir="performance_results_$(get_git_iggy_server_tag_or_sha1 .)" || { echo "Failed to get git commit or tag."; exit 1; } local output_directory="${superdir}/${type}_${count}${type:0:1}_${message_size}_${messages_per_batch}_${message_batches}_${protocol}" echo "$bench_command \ diff --git a/scripts/utils.sh b/scripts/utils.sh index 8b84528ef..0dbbbe87b 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -54,6 +54,17 @@ function send_signal() { fi } +# Function to exit with error if a process with the given PID is running +exit_if_process_is_not_running() { + local pid="$1" + + if kill -0 "$pid" 2>/dev/null; then + return 0 # Process is running + else + exit 1 # Process is not running + fi +} + # Exit hook for profile.sh function on_exit_profile() { # Gracefully stop the server