From 1ee107ec1ddc2997a7af1df1bacacd4d2887e5da Mon Sep 17 00:00:00 2001 From: joshjms Date: Sat, 3 May 2025 14:17:18 +0800 Subject: [PATCH 1/4] Add test-release-tests Makefile target This is a cherrypick of 64cd6b643b76d13e2bd2ce3c993058654dc8f441 PR: #19815 Signed-off-by: joshjms --- Makefile | 4 ++++ test | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Makefile b/Makefile index 0ee624fce82..7e4cfa818e1 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,10 @@ test-e2e: test-e2e-release: PASSES="build release e2e" ./test $(GO_TEST_FLAGS) +.PHONY: test-release +test-release: + PASSES="release_tests" VERSION="3.4.99" CI=$$CI ./scripts/test.sh $(GO_TEST_FLAGS) + docker-test: $(info GO_VERSION: $(GO_VERSION)) $(info ETCD_VERSION: $(ETCD_VERSION)) diff --git a/test b/test index 6186a6d483a..94ead0b3c49 100755 --- a/test +++ b/test @@ -398,6 +398,31 @@ function release_pass { mv /tmp/etcd ./bin/etcd-last-release } +function release_tests_pass { + VERSION=$(go list -m go.etcd.io/etcd/api/v3 2>/dev/null | awk '{split(substr($2,2), a, "."); print a[1]"."a[2]".99"}') + + if [ -n "${CI:-}" ]; then + git config user.email "prow@etcd.io" + git config user.name "Prow" + + gpg --batch --gen-key < Date: Sat, 3 May 2025 14:21:54 +0800 Subject: [PATCH 2/4] fix: test-release checks Address reviews in etcd-io#19815 This is a cherrypick of c940bf55bf901914b27c79ac18a5e15086bdc9ad PR: #19848 Signed-off-by: joshjms --- Makefile | 2 +- test | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7e4cfa818e1..ba1ae72b711 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ test-e2e-release: .PHONY: test-release test-release: - PASSES="release_tests" VERSION="3.4.99" CI=$$CI ./scripts/test.sh $(GO_TEST_FLAGS) + PASSES="release_tests" VERSION="3.4.99" ./test $(GO_TEST_FLAGS) docker-test: $(info GO_VERSION: $(GO_VERSION)) diff --git a/test b/test index 94ead0b3c49..e651742f673 100755 --- a/test +++ b/test @@ -399,7 +399,10 @@ function release_pass { } function release_tests_pass { - VERSION=$(go list -m go.etcd.io/etcd/api/v3 2>/dev/null | awk '{split(substr($2,2), a, "."); print a[1]"."a[2]".99"}') + if [ -z "${VERSION:-}" ]; then + VERSION=$(go list -m go.etcd.io/etcd/api/v3 2>/dev/null | \ + awk '{split(substr($2,2), a, "."); print a[1]"."a[2]".99"}') + fi if [ -n "${CI:-}" ]; then git config user.email "prow@etcd.io" @@ -419,8 +422,8 @@ EOF git remote add origin https://github.com/etcd-io/etcd.git fi - DRY_RUN=true run "./scripts/release.sh" --no-upload --no-docker-push --no-gh-release --in-place "${VERSION}" - VERSION="${VERSION}" run "./scripts/test_images.sh" + DRY_RUN=true "./scripts/release.sh" --no-upload --no-docker-push --no-gh-release --in-place "${VERSION}" + VERSION="${VERSION}" "./scripts/test_images.sh" } function shellcheck_pass { From e8f5ea34a64b680e687b93f83b5db96f703353b4 Mon Sep 17 00:00:00 2001 From: joshjms Date: Sat, 3 May 2025 15:23:12 +0800 Subject: [PATCH 3/4] Change IMAGE variable to TEST_IMAGE Partial backport of #19305 Refactor scripts/test_images.sh * Rename the input "IMAGE" to "TEST_IMAGE" to avoid clashing with the environment variable from the Prow infrastructure. Co-authored-by: ivanvc Signed-off-by: joshjms --- scripts/test_images.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/test_images.sh b/scripts/test_images.sh index 7183645613f..983e78403d9 100755 --- a/scripts/test_images.sh +++ b/scripts/test_images.sh @@ -8,14 +8,14 @@ source ./scripts/test_lib.sh function startContainer { # run docker in the background - docker run -d --rm --name "${RUN_NAME}" "${IMAGE}" + docker run -d --rm --name "${RUN_NAME}" "${TEST_IMAGE}" # wait for etcd daemon to bootstrap sleep 5 } function runVersionCheck { - Out=$(docker run --rm "${IMAGE}" "${@}") + Out=$(docker run --rm "${TEST_IMAGE}" "${@}") foundVersion=$(echo "$Out" | head -1 | rev | cut -d" " -f 1 | rev ) if [[ "${foundVersion}" != "${VERSION}" ]]; then echo "error: Invalid Version. Got $foundVersion, expected $VERSION. Error: $Out" @@ -50,15 +50,15 @@ else echo "Terminating test, VERSION not supplied" exit 1 fi -IMAGE=${IMAGE:-"${REPOSITARY}:${TAG}"} +TEST_IMAGE=${TEST_IMAGE:-"${REPOSITARY}:${TAG}"} # ETCD related values RUN_NAME="test_etcd" KEY="foo" VALUE="bar" -if [[ "$(docker images -q "${IMAGE}" 2> /dev/null)" == "" ]]; then - echo "${IMAGE} not present locally" +if [[ "$(docker images -q "${TEST_IMAGE}" 2> /dev/null)" == "" ]]; then + echo "${TEST_IMAGE} not present locally" exit 1 fi From 013d5b4fea1977fb3b39d463eea7e6ad5746c919 Mon Sep 17 00:00:00 2001 From: Madhav Jivrajani Date: Thu, 25 Apr 2024 14:12:51 +0530 Subject: [PATCH 4/4] scripts: default to using .go-version's version for tests and builds Additionally, provide ability to opt-out of the .go-version and use a custom one via env vars: FORCE_HOST_GO and GO_VERSION. Co-authored-by: Madhav Jivrajani Signed-off-by: joshjms --- scripts/test_lib.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/test_lib.sh b/scripts/test_lib.sh index 4f57415f4bc..646b82420d8 100644 --- a/scripts/test_lib.sh +++ b/scripts/test_lib.sh @@ -52,3 +52,27 @@ function log_info { >&2 echo "$@" >&2 echo -n -e "${COLOR_NONE}" } + +# The version present in the .go-verion is the default version that test and build scripts will use. +# However, it is possible to control the version that should be used with the help of env vars: +# - FORCE_HOST_GO: if set to a non-empty value, use the version of go installed in system's $PATH. +# - GO_VERSION: desired version of go to be used, might differ from what is present in .go-version. +# If empty, the value defaults to the version in .go-version. +function determine_go_version { + # Borrowing from how Kubernetes does this: + # https://github.com/kubernetes/kubernetes/blob/17854f0e0a153b06f9d0db096e2cd8ab2fa89c11/hack/lib/golang.sh#L510-L520 + # + # default GO_VERSION to content of .go-version + GO_VERSION="${GO_VERSION:-"$(cat "./.go-version")"}" + if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then + # no-op, just respect GOTOOLCHAIN + : + elif [ -n "${FORCE_HOST_GO:-}" ]; then + export GOTOOLCHAIN='local' + else + GOTOOLCHAIN="go${GO_VERSION}" + export GOTOOLCHAIN + fi +} + +determine_go_version