From 4fddc5259a26a9c292d0d89b665e6e9f61994c35 Mon Sep 17 00:00:00 2001 From: Moreno Ambrosin Date: Tue, 26 Sep 2023 00:45:48 -0700 Subject: [PATCH] Run kokoro jobs only against the latest tink-go release PiperOrigin-RevId: 568449452 Change-Id: I55aa996d3c71689ba6f3b45ff92bcc674e05e92c --- WORKSPACE | 4 -- kokoro/gcp_ubuntu/bazel/run_tests.sh | 67 ++++------------------- kokoro/gcp_ubuntu/gomod/run_tests.sh | 70 ++++++------------------ kokoro/macos_external/bazel/run_tests.sh | 34 +----------- kokoro/macos_external/gomod/run_tests.sh | 44 ++------------- 5 files changed, 39 insertions(+), 180 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index bb0cefb..79e5b1a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -82,8 +82,6 @@ http_archive( ], ) -# Placeholder for tink-go http_archive or local_repository. - load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") # Tink Go Google Cloud KMS Deps. @@ -95,8 +93,6 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") protobuf_deps() -# Placeholder for tink-go dependencies. - # gazelle:repository_macro deps.bzl%tink_go_gcpkms_dependencies tink_go_gcpkms_dependencies() diff --git a/kokoro/gcp_ubuntu/bazel/run_tests.sh b/kokoro/gcp_ubuntu/bazel/run_tests.sh index 524d67d..63b71c2 100644 --- a/kokoro/gcp_ubuntu/bazel/run_tests.sh +++ b/kokoro/gcp_ubuntu/bazel/run_tests.sh @@ -14,74 +14,37 @@ # limitations under the License. ################################################################################ -# By default when run locally this script runs the command below directly on the -# host. The CONTAINER_IMAGE variable can be set to run on a custom container -# image for local testing. E.g.: +# Builds and tests tink-go-gcpkms using Bazel. # -# CONTAINER_IMAGE="gcr.io/tink-test-infrastructure/linux-tink-go-base:latest" \ -# sh ./kokoro/gcp_ubuntu/bazel/run_tests.sh +# The behavior of this script can be modified using the following optional env +# variables: # -# The user may specify TINK_BASE_DIR as the folder where to look for -# tink-go-gcpkms and its dependencies. That is: -# ${TINK_BASE_DIR}/tink_go -# ${TINK_BASE_DIR}/tink_go_gcpkms -# NOTE: tink_go is fetched from GitHub if not found. +# - CONTAINER_IMAGE (unset by default): By default when run locally this script +# executes tests directly on the host. The CONTAINER_IMAGE variable can be set +# to execute tests in a custom container image for local testing. E.g.: +# +# CONTAINER_IMAGE="us-docker.pkg.dev/tink-test-infrastructure/tink-ci-images/linux-tink-go-base:latest" \ +# sh ./kokoro/gcp_ubuntu/bazel/run_tests.sh set -euo pipefail RUN_COMMAND_ARGS=() if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then - TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" - source \ - "${TINK_BASE_DIR}/tink_go_gcpkms/kokoro/testutils/go_test_container_images.sh" + readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" + cd "${TINK_BASE_DIR}/tink_go_gcpkms" + source "./kokoro/testutils/go_test_container_images.sh" CONTAINER_IMAGE="${TINK_GO_BASE_IMAGE}" RUN_COMMAND_ARGS+=( -k "${TINK_GCR_SERVICE_KEY}" ) fi -: "${TINK_BASE_DIR:=$(cd .. && pwd)}" -readonly TINK_BASE_DIR readonly CONTAINER_IMAGE -# If running from the tink_go_gcpkms folder this has no effect. -cd "${TINK_BASE_DIR}/tink_go_gcpkms" - if [[ -n "${CONTAINER_IMAGE:-}" ]]; then RUN_COMMAND_ARGS+=( -c "${CONTAINER_IMAGE}" ) fi -# Check for dependencies in TINK_BASE_DIR. Any that aren't present will be -# downloaded. -readonly GITHUB_ORG="https://github.com/tink-crypto" -./kokoro/testutils/fetch_git_repo_if_not_present.sh "${TINK_BASE_DIR}" \ - "${GITHUB_ORG}/tink-go" - # TODO(b/238389921): Run check_go_generated_files_up_to_date.sh after a # refactoring that takes into account extensions to tink-go. ./kokoro/testutils/copy_credentials.sh "testdata" "gcp" -cp WORKSPACE WORKSPACE.bak - -# Replace com_github_tink_crypto_tink_go_v2 with a local one. -mapfile -d '' TINK_GO_LOCAL_REPO <<'EOF' -local_repository(\ - name = "com_github_tink_crypto_tink_go_v2",\ - path = "../tink_go",\ -)\ -EOF -readonly TINK_GO_LOCAL_REPO - -mapfile -d '' TINK_GO_DEPENDENCIES <<'EOF' -load("@com_github_tink_crypto_tink_go_v2//:deps.bzl", tink_go_dependencies="go_dependencies")\ -\ -tink_go_dependencies()\ -EOF -readonly TINK_GO_DEPENDENCIES - -sed -i \ - "s~# Placeholder for tink-go http_archive or local_repository.~${TINK_GO_LOCAL_REPO}~" \ - WORKSPACE -sed -i \ - "s~# Placeholder for tink-go dependencies.~${TINK_GO_DEPENDENCIES}~"\ - WORKSPACE - MANUAL_TARGETS=() # Run manual tests that rely on test data only available via Bazel. if [[ -n "${KOKORO_ROOT:-}" ]]; then @@ -89,12 +52,6 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then fi readonly MANUAL_TARGETS -trap cleanup EXIT - -cleanup() { - mv WORKSPACE.bak WORKSPACE -} - ./kokoro/testutils/run_command.sh "${RUN_COMMAND_ARGS[@]}" \ ./kokoro/testutils/run_bazel_tests.sh \ -t --test_arg=--test.v . "${MANUAL_TARGETS[@]}" diff --git a/kokoro/gcp_ubuntu/gomod/run_tests.sh b/kokoro/gcp_ubuntu/gomod/run_tests.sh index 55953c6..90d890a 100644 --- a/kokoro/gcp_ubuntu/gomod/run_tests.sh +++ b/kokoro/gcp_ubuntu/gomod/run_tests.sh @@ -14,71 +14,37 @@ # limitations under the License. ################################################################################ -# By default when run locally this script runs the command below directly on the -# host. The CONTAINER_IMAGE variable can be set to run on a custom container -# image for local testing. E.g.: +# Builds and tests tink-go-gcpkms using Go tooling. # -# CONTAINER_IMAGE="gcr.io/tink-test-infrastructure/linux-tink-go-base:latest" \ -# sh ./kokoro/gcp_ubuntu/gomod/run_tests.sh +# The behavior of this script can be modified using the following optional env +# variables: # -# The user may specify TINK_BASE_DIR as the folder where to look for -# tink-go-gcpkms and its dependencies. That is: -# ${TINK_BASE_DIR}/tink_go -# ${TINK_BASE_DIR}/tink_go_gcpkms -# NOTE: tink_go is fetched from GitHub if not found. +# - CONTAINER_IMAGE (unset by default): By default when run locally this script +# executes tests directly on the host. The CONTAINER_IMAGE variable can be set +# to execute tests in a custom container image for local testing. E.g.: +# +# CONTAINER_IMAGE="us-docker.pkg.dev/tink-test-infrastructure/tink-ci-images/linux-tink-go-base:latest" \ +# sh ./kokoro/gcp_ubuntu/gomod/run_tests.sh set -eEuo pipefail RUN_COMMAND_ARGS=() -if [[ -n "${KOKORO_ROOT:-}" ]]; then - TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" - source \ - "${TINK_BASE_DIR}/tink_go_gcpkms/kokoro/testutils/go_test_container_images.sh" +if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then + readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" + cd "${TINK_BASE_DIR}/tink_go_gcpkms" + source "./kokoro/testutils/go_test_container_images.sh" CONTAINER_IMAGE="${TINK_GO_BASE_IMAGE}" RUN_COMMAND_ARGS+=( -k "${TINK_GCR_SERVICE_KEY}" ) fi -: "${TINK_BASE_DIR:=$(cd .. && pwd)}" -readonly TINK_BASE_DIR readonly CONTAINER_IMAGE -# If running from the tink_go_gcpkms folder this has no effect. -cd "${TINK_BASE_DIR}/tink_go_gcpkms" - if [[ -n "${CONTAINER_IMAGE:-}" ]]; then RUN_COMMAND_ARGS+=( -c "${CONTAINER_IMAGE}" ) fi -# Check for dependencies in TINK_BASE_DIR. Any that aren't present will be -# downloaded. -readonly GITHUB_ORG="https://github.com/tink-crypto" -./kokoro/testutils/fetch_git_repo_if_not_present.sh "${TINK_BASE_DIR}" \ - "${GITHUB_ORG}/tink-go" - -./kokoro/testutils/copy_credentials.sh "testdata" "gcp" - -readonly TINK_GO_MODULE_URL="github.com/tink-crypto/tink-go/v2" -readonly TINK_GO_GCPKMS_MODULE_URL="github.com/tink-crypto/tink-go-gcpkms" -readonly TINK_VERSION="$(cat version.bzl | grep ^TINK | cut -f 2 -d \")" - -cp go.mod go.mod.bak - -cat < _do_run_test.sh -set -euo pipefail - -# Modify go.mod locally to use the version of tink-go in ../tink_go. -go mod edit "-replace=${TINK_GO_MODULE_URL}=../tink_go" -go mod tidy -go list -m all | grep tink-go -./kokoro/testutils/run_go_mod_tests.sh "${TINK_GO_GCPKMS_MODULE_URL}" . \ - "${TINK_VERSION}" "main" -EOF -chmod +x _do_run_test.sh - -# Run cleanup on EXIT. -trap cleanup EXIT +readonly MODULE_URL="github.com/tink-crypto/tink-go-gcpkms" +readonly MODULE_VERSION="$(cat version.bzl | grep ^TINK | cut -f 2 -d \")" -cleanup() { - mv go.mod.bak go.mod - rm -rf _do_run_test.sh -} +./kokoro/testutils/run_command.sh "${RUN_COMMAND_ARGS[@]}" \ + ./kokoro/testutils/run_go_mod_tests.sh "${MODULE_URL}" . \ + "${MODULE_VERSION}" "main" -./kokoro/testutils/run_command.sh "${RUN_COMMAND_ARGS[@]}" ./_do_run_test.sh diff --git a/kokoro/macos_external/bazel/run_tests.sh b/kokoro/macos_external/bazel/run_tests.sh index 46ce670..398ad29 100644 --- a/kokoro/macos_external/bazel/run_tests.sh +++ b/kokoro/macos_external/bazel/run_tests.sh @@ -14,47 +14,21 @@ # limitations under the License. ################################################################################ -# The user may specify TINK_BASE_DIR as the folder where to look for -# tink-go-gcpkms dependencies. - set -euo pipefail if [[ -n "${KOKORO_ROOT:-}" ]]; then - TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" + readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" cd "${TINK_BASE_DIR}/tink_go_gcpkms" fi -: "${TINK_BASE_DIR:=$(cd .. && pwd)}" - -# Check for dependencies in TINK_BASE_DIR. Any that aren't present will be -# downloaded. -readonly GITHUB_ORG="https://github.com/tink-crypto" -./kokoro/testutils/fetch_git_repo_if_not_present.sh "${TINK_BASE_DIR}" \ - "${GITHUB_ORG}/tink-go" - # Sourcing required to update callers environment. source ./kokoro/testutils/install_go.sh - echo "Using go binary from $(which go): $(go version)" # TODO(b/238389921): Run check_go_generated_files_up_to_date.sh after a # refactoring that takes into account extensions to tink-go. - ./kokoro/testutils/copy_credentials.sh "testdata" "gcp" -# Replace com_github_tink_crypto_tink_go_v2 with a local one. -grep -r "com_github_tink_crypto_tink_go_v2" -l --include="*.bazel" . \ - | xargs sed -i '.bak' \ - "s~com_github_tink_crypto_tink_go_v2~com_github_tink_crypto_tink_go_local~g" - -sed -i '.bak' \ - 's~workspace(name = "tink_go_gcpkms")~workspace(name = "tink_go_gcpkms")\ -\ -local_repository(\ - name = "com_github_tink_crypto_tink_go_local",\ - path = "'"${TINK_BASE_DIR}"'/tink_go",\ -)~' WORKSPACE - MANUAL_TARGETS=() # Run manual tests that rely on test data only available via Bazel. if [[ -n "${KOKORO_ROOT:-}" ]]; then @@ -62,7 +36,5 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then fi readonly MANUAL_TARGETS -./kokoro/testutils/run_bazel_tests.sh \ - -t --test_arg=--test.v . "${MANUAL_TARGETS[@]}" - -mv WORKSPACE.bak WORKSPACE +./kokoro/testutils/run_bazel_tests.sh -t --test_arg=--test.v . \ + "${MANUAL_TARGETS[@]}" diff --git a/kokoro/macos_external/gomod/run_tests.sh b/kokoro/macos_external/gomod/run_tests.sh index b0c0e91..7b6d479 100644 --- a/kokoro/macos_external/gomod/run_tests.sh +++ b/kokoro/macos_external/gomod/run_tests.sh @@ -14,51 +14,19 @@ # limitations under the License. ################################################################################ -# The user may specify TINK_BASE_DIR as the folder where to look for -# tink-go-gcpkms dependencies. - set -euo pipefail -TINK_GO_GCPKMS_PROJECT_PATH="$(pwd)" if [[ -n "${KOKORO_ROOT:-}" ]]; then - TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" - TINK_GO_GCPKMS_PROJECT_PATH="${TINK_BASE_DIR}/tink_go_gcpkms" - cd "${TINK_GO_GCPKMS_PROJECT_PATH}" + readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" + cd "${TINK_BASE_DIR}/tink_go_gcpkms" fi -readonly TINK_GO_GCPKMS_PROJECT_PATH - -: "${TINK_BASE_DIR:=$(cd .. && pwd)}" -# Check for dependencies in TINK_BASE_DIR. Any that aren't present will be -# downloaded. -readonly GITHUB_ORG="https://github.com/tink-crypto" -./kokoro/testutils/fetch_git_repo_if_not_present.sh "${TINK_BASE_DIR}" \ - "${GITHUB_ORG}/tink-go" - -./kokoro/testutils/copy_credentials.sh "testdata" "gcp" # Sourcing required to update callers environment. source ./kokoro/testutils/install_go.sh - echo "Using go binary from $(which go): $(go version)" -readonly TINK_GO_MODULE_URL="github.com/tink-crypto/tink-go/v2" -readonly TINK_GO_GCPKMS_MODULE_URL="github.com/tink-crypto/tink-go-gcpkms" -readonly TINK_VERSION="$(cat ${TINK_GO_GCPKMS_PROJECT_PATH}/version.bzl \ - | grep ^TINK \ - | cut -f 2 -d \")" - - -cp go.mod go.mod.bak - -# Modify go.mod locally to use the version of tink-go in TINK_BASE_DIR/tink_go. -go mod edit "-replace=${TINK_GO_MODULE_URL}=${TINK_BASE_DIR}/tink_go" -go mod tidy -go list -m all | grep tink-go - -./kokoro/testutils/run_go_mod_tests.sh \ - "${TINK_GO_GCPKMS_MODULE_URL}" \ - "${TINK_GO_GCPKMS_PROJECT_PATH}" \ - "${TINK_VERSION}" \ - "main" +readonly MODULE_URL="github.com/tink-crypto/tink-go-gcpkms" +readonly MODULE_VERSION="$(cat version.bzl | grep ^TINK | cut -f 2 -d \")" -mv go.mod.bak go.mod +./kokoro/testutils/run_go_mod_tests.sh "${MODULE_URL}" "$(pwd)" \ + "${MODULE_VERSION}" "main"