Skip to content

Commit

Permalink
Run kokoro jobs only against the latest tink-go release
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 568449452
Change-Id: I55aa996d3c71689ba6f3b45ff92bcc674e05e92c
  • Loading branch information
morambro authored and copybara-github committed Sep 26, 2023
1 parent 577582e commit 4fddc52
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 180 deletions.
4 changes: 0 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()

Expand Down
67 changes: 12 additions & 55 deletions kokoro/gcp_ubuntu/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,87 +14,44 @@
# 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
MANUAL_TARGETS+=( "//integration/gcpkms:gcpkms_test" )
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[@]}"
70 changes: 18 additions & 52 deletions kokoro/gcp_ubuntu/gomod/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > _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
34 changes: 3 additions & 31 deletions kokoro/macos_external/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,27 @@
# 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
MANUAL_TARGETS+=( "//integration/gcpkms:gcpkms_test" )
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[@]}"
44 changes: 6 additions & 38 deletions kokoro/macos_external/gomod/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 4fddc52

Please sign in to comment.