From ea1473dd58f8e29a03dcb36ac74c6393bf62f356 Mon Sep 17 00:00:00 2001 From: Jack Green Date: Tue, 5 Nov 2024 13:30:20 +0000 Subject: [PATCH] Add `xtrace` shell command tracing when running action in GitHub Debug mode (#817) We already do this in _some_ places, make it consistent everywhere. Raised from [PR feedback](https://github.com/hazelcast/hazelcast-docker/pull/816#discussion_r1827704039). --- .github/scripts/abstract-simple-smoke-test.sh | 87 +++++++++++++++++++ .github/scripts/build.functions.sh | 2 +- .github/scripts/build.functions_tests.sh | 2 +- .github/scripts/ee-build.functions.sh | 2 +- .github/scripts/ee-build.functions_tests.sh | 3 +- .github/scripts/get-tags-to-push_tests.sh | 3 +- .github/scripts/maven.functions_tests.sh | 2 +- .github/scripts/oss-build.functions.sh | 2 +- .github/scripts/oss-build.functions_tests.sh | 3 +- .github/scripts/simple-smoke-test.sh | 63 +++----------- .github/scripts/smoke-test.sh | 3 +- hazelcast-enterprise/maven.functions.sh | 2 +- hazelcast-oss/maven.functions.sh | 2 +- 13 files changed, 113 insertions(+), 63 deletions(-) create mode 100755 .github/scripts/abstract-simple-smoke-test.sh diff --git a/.github/scripts/abstract-simple-smoke-test.sh b/.github/scripts/abstract-simple-smoke-test.sh new file mode 100755 index 00000000..786467cf --- /dev/null +++ b/.github/scripts/abstract-simple-smoke-test.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail ${RUNNER_DEBUG:+-x} + +# Performs simple validation tests on an already-running Hazelcast instance +# Abstract as could be from Docker, Homebrew, local binary etc +# Because abstract, expects callers to implement required, but absent functions +function test_package() { + local expected_distribution_type=$1 + local expected_version=$2 + + test_health + test_map_read_write + + # Deliberately last step as it doesn't block-and-wait until the instance is initialized + # Otherwise would have false positives if instance still starting and logs empty + check_metadata "${expected_distribution_type}" "${expected_version}" +} + +# Search logs for entries _like_: +# Hazelcast Platform 5.5.0 (20240725) starting at [172.17.0.2]:5701 +# To validate the version and distribution is correct +function check_metadata() { + local expected_distribution_type=$1 + local expected_version=$2 + + logs=$(get_hz_logs) + + if [[ -z "${logs}" ]]; then + echoerr "Failed to read logs" + exit 1; + fi + + if grep -q "${expected_distribution_type} ${expected_version}" <<< "${logs}"; then + echo "Expected contents (${expected_distribution_type}) and version (${expected_version}) identified." + else + echoerr "Failed to find ${expected_distribution_type} ${expected_version} in logs:" + echoerr "${logs}" + exit 1; + fi +} + +function test_health() { + local attempts=0 + local max_attempts=30 + until curl --silent --fail "127.0.0.1:5701/hazelcast/health/ready"; do + if [[ ${attempts} -eq ${max_attempts} ]];then + echoerr "Hazelcast not responding" + exit 1; + fi + printf '.' + attempts=$((attempts+1)) + sleep 2 + done +} + +function test_map_read_write() { + install_clc + + local key="some-key" + local expected="some-value" + echo "Putting value '${expected}' for key '${key}'" + clc --timeout 5s map set -n some-map "${key}" "${expected}" --log.path stderr + echo "Getting value for key '${key}'" + local actual + actual=$(clc map get --format delimited -n some-map "${key}" --log.path stderr) + + if [[ "${expected}" != "${actual}" ]]; then + echoerr "Expected to read '${expected}' but got '${actual}'" + exit 1; + fi +} + +function install_clc() { + while ! curl https://hazelcast.com/clc/install.sh | bash + do + echo "Retrying clc installation..." + sleep 3 + done + export PATH=${PATH}:${HOME}/.hazelcast/bin + clc config add default cluster.name=dev cluster.address=localhost +} + +# Prints the given message to stderr +function echoerr() { + echo "ERROR - $*" 1>&2; +} diff --git a/.github/scripts/build.functions.sh b/.github/scripts/build.functions.sh index 01b7c0b0..5493b192 100644 --- a/.github/scripts/build.functions.sh +++ b/.github/scripts/build.functions.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -euo pipefail ${RUNNER_DEBUG:+-x} # Checks if we should build the OSS docker image. # Returns "yes" if we should build it or "no" if we shouldn't. diff --git a/.github/scripts/build.functions_tests.sh b/.github/scripts/build.functions_tests.sh index cac798ea..8308bdbd 100755 --- a/.github/scripts/build.functions_tests.sh +++ b/.github/scripts/build.functions_tests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eu +set -eu ${RUNNER_DEBUG:+-x} SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" diff --git a/.github/scripts/ee-build.functions.sh b/.github/scripts/ee-build.functions.sh index 946e8eb7..c3f0f841 100644 --- a/.github/scripts/ee-build.functions.sh +++ b/.github/scripts/ee-build.functions.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -euo pipefail ${RUNNER_DEBUG:+-x} # This is a simple script imitating what maven does for snapshot versions. We are not using maven because currently Docker Buildx and QEMU on Github Actions # don't work with Java on architectures ppc64le and s390x. When the problem is fixed we will revert back to using maven. diff --git a/.github/scripts/ee-build.functions_tests.sh b/.github/scripts/ee-build.functions_tests.sh index a9da9b2b..23845615 100755 --- a/.github/scripts/ee-build.functions_tests.sh +++ b/.github/scripts/ee-build.functions_tests.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -set -eu +set -eu ${RUNNER_DEBUG:+-x} + function find_script_dir() { CURRENT=$PWD diff --git a/.github/scripts/get-tags-to-push_tests.sh b/.github/scripts/get-tags-to-push_tests.sh index 31798eb4..29593094 100644 --- a/.github/scripts/get-tags-to-push_tests.sh +++ b/.github/scripts/get-tags-to-push_tests.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -set -eu +set -eu ${RUNNER_DEBUG:+-x} + function findScriptDir() { CURRENT=$PWD diff --git a/.github/scripts/maven.functions_tests.sh b/.github/scripts/maven.functions_tests.sh index 2a70b363..108d2973 100755 --- a/.github/scripts/maven.functions_tests.sh +++ b/.github/scripts/maven.functions_tests.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eu +set -eu ${RUNNER_DEBUG:+-x} function find_script_dir() { CURRENT=$PWD diff --git a/.github/scripts/oss-build.functions.sh b/.github/scripts/oss-build.functions.sh index 76a1f3c3..c831b9fc 100644 --- a/.github/scripts/oss-build.functions.sh +++ b/.github/scripts/oss-build.functions.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -euo pipefail ${RUNNER_DEBUG:+-x} function get_hz_dist_zip() { local hz_variant=$1 diff --git a/.github/scripts/oss-build.functions_tests.sh b/.github/scripts/oss-build.functions_tests.sh index 917b9a82..11b5afe1 100644 --- a/.github/scripts/oss-build.functions_tests.sh +++ b/.github/scripts/oss-build.functions_tests.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -set -eu +set -eu ${RUNNER_DEBUG:+-x} + function find_script_dir() { CURRENT=$PWD diff --git a/.github/scripts/simple-smoke-test.sh b/.github/scripts/simple-smoke-test.sh index 0f022ed5..0262855e 100755 --- a/.github/scripts/simple-smoke-test.sh +++ b/.github/scripts/simple-smoke-test.sh @@ -1,62 +1,23 @@ #!/usr/bin/env bash -set -e -set -o pipefail +set -o errexit ${RUNNER_DEBUG:+-x} -function test_docker_image() { - local image=$1 - local container_name=$2 - local expected_distribution_type=$3 +# shellcheck source=../.github/scripts/abstract-simple-smoke-test.sh +. .github/scripts/abstract-simple-smoke-test.sh - if [ "$(docker ps --all --quiet --filter name="$container_name")" ]; then - echo "Removing existing '$container_name' container" - docker container rm --force "$container_name" - fi - - echo "Checking if $image is EE" - if docker run --rm $image bash -c 'compgen -G lib/*enterprise*'; then - echo "EE contents identified" - distribution_type="ee" - else - echo "No EE contents identified - assuming OSS" - distribution_type="oss" - fi - - if [[ "$distribution_type" != "$expected_distribution_type" ]]; then - echo "Distribution was $distribution_type, not $expected_distribution_type as expected" - exit 1 - fi +function remove_container_if_exists() { + local containers + containers=$(docker ps --all --quiet --filter name="${container_name}") - echo "Starting container '$container_name' from image '$image'" - docker run -it --name "$container_name" -e HZ_LICENSEKEY -e HZ_INSTANCETRACKING_FILENAME -d -p5701:5701 "$image" - local key="some-key" - local expected="some-value" - echo "Putting value '$expected' for key '$key'" - while ! clc --timeout 5s map set -n some-map $key $expected --log.path stderr - do - echo "Retrying..." - sleep 3 - done - echo "Getting value for key '$key'" - local actual - actual=$(clc map get --format delimited -n some-map $key --log.path stderr) - echo "Stopping container $container_name}" - docker stop "$container_name" - - if [ "$expected" != "$actual" ]; then - echo "Expected to read '${expected}' but got '${actual}'" - exit 1; + if [[ -n "${containers}" ]]; then + echo "Removing existing '${container_name}' container" + docker container rm --force "${container_name}" fi } -function install_clc() { - while ! curl https://hazelcast.com/clc/install.sh | bash - do - echo "Retrying clc installation..." - sleep 3 - done - export PATH=$PATH:$HOME/.hazelcast/bin - clc config add default cluster.name=dev cluster.address=localhost +function start_container() { + echo "Starting container '${container_name}' from image '${image}'" + docker run -it --name "${container_name}" -e HZ_LICENSEKEY -e HZ_INSTANCETRACKING_FILENAME -d -p5701:5701 "${image}" } function get_hz_logs() { diff --git a/.github/scripts/smoke-test.sh b/.github/scripts/smoke-test.sh index 78d58d03..a4f7e3fd 100755 --- a/.github/scripts/smoke-test.sh +++ b/.github/scripts/smoke-test.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -e -set -o pipefail +set -e -o pipefail ${RUNNER_DEBUG:+-x} # Fill the variables before running the script WORKDIR=$1 diff --git a/hazelcast-enterprise/maven.functions.sh b/hazelcast-enterprise/maven.functions.sh index c761c932..53b6d026 100755 --- a/hazelcast-enterprise/maven.functions.sh +++ b/hazelcast-enterprise/maven.functions.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -euo pipefail ${RUNNER_DEBUG:+-x} # THIS FILE IS DUPLICATED AND MUST BE KEPT IN SYNC MANUALLY # Docker requires any included script to be in the current folder, hence we must duplicate this script for OS and EE diff --git a/hazelcast-oss/maven.functions.sh b/hazelcast-oss/maven.functions.sh index c761c932..53b6d026 100755 --- a/hazelcast-oss/maven.functions.sh +++ b/hazelcast-oss/maven.functions.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -euo pipefail ${RUNNER_DEBUG:+-x} # THIS FILE IS DUPLICATED AND MUST BE KEPT IN SYNC MANUALLY # Docker requires any included script to be in the current folder, hence we must duplicate this script for OS and EE