From 31bce64a701334a281f596446b88a32caf7f611c Mon Sep 17 00:00:00 2001 From: D Tripp <38776199+thedtripp@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:44:14 +0000 Subject: [PATCH] etcd 3.5: Install shellcheck if not installed. Include conditional logic to install shellcheck with correct architecture. This is based on commit 4f23883 and pull request #14872. Signed-off-by: D Tripp <38776199+thedtripp@users.noreply.github.com> --- Makefile | 1 + test.sh | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 928f9ac092e..80f34252472 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ clean: rm -rf ./release rm -rf ./coverage/*.err ./coverage/*.out rm -rf ./tests/e2e/default.proxy + rm -rf ./bin/shellcheck* find ./ -name "127.0.0.1:*" -o -name "localhost:*" -o -name "*.log" -o -name "agent-*" -o -name "*.coverprofile" -o -name "testname-proxy-*" | $(XARGS) docker-clean: diff --git a/test.sh b/test.sh index e14bb424959..09d9feb79c5 100755 --- a/test.sh +++ b/test.sh @@ -50,6 +50,7 @@ source ./build.sh PASSES=${PASSES:-"fmt bom dep build unit"} PKG=${PKG:-} +SHELLCHECK_VERSION=${SHELLCHECK_VERSION:-"v0.10.0"} if [ -z "${GOARCH:-}" ]; then GOARCH=$(go env GOARCH); @@ -393,9 +394,29 @@ function fmt_pass { } function shellcheck_pass { - if tool_exists "shellcheck" "https://github.com/koalaman/shellcheck#installing"; then - generic_checker run shellcheck -fgcc build test scripts/*.sh ./*.sh + SHELLCHECK=shellcheck + + if ! tool_exists "shellcheck" "https://github.com/koalaman/shellcheck#installing"; then + log_callout "Installing shellcheck $SHELLCHECK_VERSION" + + if [ "$GOARCH" == "amd64" ]; then + URL="https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" + elif [[ "$GOARCH" == "arm" || "$GOARCH" == "arm64" ]]; then + URL="https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.aarch64.tar.xz" + else + echo "Unsupported architecture: $GOARCH" + exit 1 + fi + + wget -qO- "$URL" | tar -xJv -C /tmp/ --strip-components=1 + mkdir -p ./bin + mv /tmp/shellcheck ./bin/ + SHELLCHECK=./bin/shellcheck fi + + echo "Running shellcheck with $SHELLCHECK" + generic_checker run ${SHELLCHECK} -fgcc build test scripts/*.sh ./*.sh + } function shellws_pass {