Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50fb036

Browse files
author
Takashi Matsuo
committed
address review comments
1 parent 45dd53c commit 50fb036

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
6868
export DATALABELING_ENDPOINT="test-datalabeling.sandbox.googleapis.com:443"
6969

7070
# Run Cloud SQL proxy (background process exit when script does)
71-
wget --quiet https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 \
72-
-O ${HOME}/cloud_sql_proxy && chmod +x ${HOME}/cloud_sql_proxy
73-
${HOME}/cloud_sql_proxy -instances="${MYSQL_INSTANCE}"=tcp:3306 &>> \
74-
${HOME}/cloud_sql_proxy.log &
75-
${HOME}/cloud_sql_proxy -instances="${POSTGRES_INSTANCE}"=tcp:5432 &>> \
71+
sudo wget --quiet https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 \
72+
-O /bin/cloud_sql_proxy && sudo chmod +x /bin/cloud_sql_proxy
73+
cloud_sql_proxy -instances="${MYSQL_INSTANCE}"=tcp:3306 &>> \
7674
${HOME}/cloud_sql_proxy.log &
75+
cloud_sql_proxy -instances="${POSTGRES_INSTANCE}"=tcp:5432 &>> \
76+
${HOME}/cloud_sql_proxy-postgres.log &
7777
echo -e "\nCloud SQL proxy started."
7878

7979
echo -e "\n******************** TESTING PROJECTS ********************"
@@ -102,25 +102,36 @@ for file in **/requirements.txt; do
102102

103103
# First we look up the environment variable `RUN_TESTS_DIRS`. If
104104
# the value is set, we'll iterate through the colon separated
105-
# directory list.
105+
# directory list. If the target directory is not under any
106+
# directory in the list, we skip this directory.
107+
# This environment variables are primarily for
108+
# `scripts/run_tests_local.sh`.
109+
#
110+
# The value must be a colon separated list of relative paths from
111+
# the project root.
112+
#
113+
# Example:
114+
# cdn:appengine/flexible
115+
# run tests for `cdn` and `appengine/flexible` directories.
116+
# logging/cloud-client
117+
# only run tests for `logging/cloud-client` directory.
118+
#
106119
if [[ -n "${RUN_TESTS_DIRS:-}" ]]; then
107-
IFS=":"
108-
read -ra run_tests_dirs <<< "${RUN_TESTS_DIRS}"
109120
match=0
110-
for d in "${run_tests_dirs[@]}"; do
121+
for d in $(echo "${RUN_TESTS_DIRS}" | tr ":" "\n"); do
111122
# If the current dir starts with one of the
112123
# RUN_TESTS_DIRS, we should run the tests.
113124
if [[ "${file}" = "${d}"* ]]; then
114125
match=1
115126
break
116127
fi
117128
done
118-
IFS=" "
119129
if [[ $match -eq 0 ]]; then
120130
continue
121131
fi
132+
fi
122133
# If $DIFF_FROM is set, use it to check for changes in this directory.
123-
elif [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
134+
if [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
124135
git diff --quiet "$DIFF_FROM" .
125136
CHANGED=$?
126137
if [[ "$CHANGED" -eq 0 ]]; then

.kokoro/trampoline_v2.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@
3232
# Then run the script.
3333
# .kokoro/trampoline_v2.sh
3434
#
35-
# You can optionally change these environment variables:
36-
#
35+
# These environment variables are required:
3736
# TRAMPOLINE_IMAGE: The docker image to use.
3837
# TRAMPOLINE_DOCKERFILE: The location of the Dockerfile.
38+
#
39+
# You can optionally change these environment variables:
3940
# TRAMPOLINE_IMAGE_UPLOAD:
4041
# (true|false): Whether to upload the Docker image after the
4142
# successful builds.
4243
# TRAMPOLINE_BUILD_FILE: The script to run in the docker container.
4344
# TRAMPOLINE_WORKSPACE: The workspace path in the docker container.
4445
# Defaults to /workspace.
46+
# TRAMPOLINE_SKIP_DOWNLOAD_IMAGE: Skip downloading the image when you
47+
# know you have the image locally.
4548
#
4649
# Potentially there are some repo specific envvars in .trampolinerc in
4750
# the project root.
@@ -194,19 +197,24 @@ do
194197
fi
195198
done
196199

197-
log_yellow "Preparing Docker image."
198-
# Download the docker image specified by `TRAMPOLINE_IMAGE`
199-
200-
set +e # ignore error on docker operations
201-
# We may want to add --max-concurrent-downloads flag.
202-
203-
log_yellow "Start pulling the Docker image: ${TRAMPOLINE_IMAGE}."
204-
if docker pull "${TRAMPOLINE_IMAGE}"; then
205-
log_green "Finished pulling the Docker image: ${TRAMPOLINE_IMAGE}."
200+
if [[ "${TRAMPOLINE_SKIP_DOWNLOAD_IMAGE:-false}" == "true" ]]; then
201+
log_yellow "Re-using the local Docker image."
206202
has_cache="true"
207203
else
208-
log_red "Failed pulling the Docker image: ${TRAMPOLINE_IMAGE}."
209-
has_cache="false"
204+
log_yellow "Preparing Docker image."
205+
# Download the docker image specified by `TRAMPOLINE_IMAGE`
206+
207+
set +e # ignore error on docker operations
208+
# We may want to add --max-concurrent-downloads flag.
209+
210+
log_yellow "Start pulling the Docker image: ${TRAMPOLINE_IMAGE}."
211+
if docker pull "${TRAMPOLINE_IMAGE}"; then
212+
log_green "Finished pulling the Docker image: ${TRAMPOLINE_IMAGE}."
213+
has_cache="true"
214+
else
215+
log_red "Failed pulling the Docker image: ${TRAMPOLINE_IMAGE}."
216+
has_cache="false"
217+
fi
210218
fi
211219

212220

scripts/run_tests_local.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ directory="$(realpath "$1")"
5454
relative_dir=${directory#"${PROJECT_ROOT}/"}
5555
export RUN_TESTS_DIRS="${relative_dir}"
5656

57-
if [[ -z "${TRAMPOLINE_DOCKERFILE:-}" ]]; then
58-
export TRAMPOLINE_DOCKERFILE="none"
59-
fi
57+
# We want to test this directory regardless of whether there's a change.
58+
export TRAMPOLINE_BUILD_FILE=".kokoro/tests/run_tests.sh"
6059

6160
if [[ $# -ge 2 ]]; then
6261
sessions=("${@:2}")
@@ -71,4 +70,7 @@ for session in "${sessions[@]}"
7170
do
7271
export RUN_TESTS_SESSION="${session}"
7372
"${PROJECT_ROOT}/.kokoro/trampoline_v2.sh"
73+
# We can re-use the image after the first iteration.
74+
export TRAMPOLINE_SKIP_DOWNLOAD_IMAGE="true"
75+
export TRAMPOLINE_DOCKERFILE="none"
7476
done

0 commit comments

Comments
 (0)