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

Skip to content

Commit 8a97151

Browse files
author
Takashi Matsuo
committed
add RUN_TESTS_DIRS envvar
1 parent 88f44de commit 8a97151

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,27 @@ for file in **/requirements.txt; do
101101
file=$(dirname "$file")
102102
cd "$file"
103103

104+
# First we look up the environment variable `RUN_TESTS_DIRS`. If
105+
# the value is set, we'll iterate through the colon separated
106+
# directory list.
107+
if [[ -n "${RUN_TESTS_DIRS:-}" ]]; then
108+
IFS=":"
109+
read -ra run_tests_dirs <<< "${RUN_TESTS_DIRS}"
110+
match=0
111+
for d in "${run_tests_dirs[@]}"; do
112+
# If the current dir starts with one of the
113+
# RUN_TESTS_DIRS, we should run the tests.
114+
if [[ "${file}" = "${d}"* ]]; then
115+
match=1
116+
break
117+
fi
118+
done
119+
IFS=" "
120+
if [[ $match -eq 0 ]]; then
121+
continue
122+
fi
104123
# If $DIFF_FROM is set, use it to check for changes in this directory.
105-
if [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
124+
elif [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
106125
git diff --quiet "$DIFF_FROM" .
107126
CHANGED=$?
108127
if [[ "$CHANGED" -eq 0 ]]; then
@@ -146,6 +165,9 @@ for file in **/requirements.txt; do
146165
echo -e "\n Testing completed.\n"
147166
fi
148167

168+
# Remove noxfile.py if it's not tracked by git.
169+
git ls-files --error-unmatch noxfile.py > /dev/null 2>&1 | rm noxfile.py
170+
149171
done
150172
cd "$ROOT"
151173

.kokoro/trampoline_v2.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
# TRAMPOLINE_IMAGE_SOURCE: The location of the Dockerfile.
3939
# RUN_TESTS_SESSION: The nox session to run.
4040
# TRAMPOLINE_BUILD_FILE: The script to run in the docker container.
41+
# RUN_TESTS_DIR: A colon separated directory list relative to the
42+
# project root.
4143

4244
set -euo pipefail
4345

@@ -245,12 +247,13 @@ fi
245247
# Passing down env vars
246248
for e in "${pass_down_envvars[@]}"
247249
do
248-
docker_flags+=("--env" "${e}=${!e}")
250+
if [[ -n "${!e:-}" ]]; then
251+
docker_flags+=("--env" "${e}=${!e}")
252+
fi
249253
done
250254

251255
# If arguments are given, all arguments will become the commands run
252256
# in the container, otherwise run TRAMPOLINE_BUILD_FILE.
253-
254257
if [[ $# -ge 1 ]]; then
255258
log_yellow "Running the given commands '" "${@:1}" "' in the container."
256259
readonly commands=("${@:1}")

.trampolinerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ required_envvars+=(
1818
)
1919

2020
pass_down_envvars+=(
21+
"BUILD_SPECIFIC_GCLOUD_PROJECT"
22+
"REPORT_TO_BUILD_COP_BOT"
23+
# The nox session to run.
24+
"RUN_TESTS_DIRS"
2125
"RUN_TESTS_SESSION"
2226
)
2327

0 commit comments

Comments
 (0)