Skip to content

Commit f0b1646

Browse files
author
Takashi Matsuo
authored
testing: diff against the common commit on the master (#3916)
* testing: diff against the common commit on the master * Allow git diff to fail * address code review
1 parent 5456119 commit f0b1646

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ shopt -s globstar
2121

2222
DIFF_FROM=""
2323

24-
# `--only-diff-master will only run tests on project changes from the master branch.
24+
# `--only-diff-master` will only run tests on project changes on the
25+
# last common commit from the master branch.
2526
if [[ $* == *--only-diff-master* ]]; then
26-
DIFF_FROM="origin/master.."
27+
set +e
28+
git diff --quiet "origin/master..." .kokoro/tests .kokoro/docker \
29+
.kokoro/trampoline_v2.sh
30+
CHANGED=$?
31+
set -e
32+
if [[ "${CHANGED}" -eq 0 ]]; then
33+
DIFF_FROM="origin/master..."
34+
else
35+
echo "Changes to test driver files detected. Running full tests."
36+
fi
2737
fi
2838

29-
# `--only-diff-master will only run tests on project changes from the previous commit.
39+
# `--only-diff-head` will only run tests on project changes from the
40+
# previous commit.
3041
if [[ $* == *--only-diff-head* ]]; then
3142
DIFF_FROM="HEAD~.."
3243
fi
@@ -83,16 +94,6 @@ set +e
8394
RTN=0
8495
ROOT=$(pwd)
8596

86-
# If some files in .kokoro directory have any changes, we will test everything.
87-
test_all="true"
88-
if [[ -n "${DIFF_FROM:-}" ]]; then
89-
git diff --quiet "$DIFF_FROM" .kokoro/docker .kokoro/tests
90-
CHANGED=$?
91-
if [[ "$CHANGED" -eq 0 ]]; then
92-
test_all="false"
93-
fi
94-
fi
95-
9697
# Find all requirements.txt in the repository (may break on whitespace).
9798
for file in **/requirements.txt; do
9899
cd "$ROOT"
@@ -131,7 +132,7 @@ for file in **/requirements.txt; do
131132
fi
132133
fi
133134
# If $DIFF_FROM is set, use it to check for changes in this directory.
134-
if [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
135+
if [[ -n "${DIFF_FROM:-}" ]]; then
135136
git diff --quiet "$DIFF_FROM" .
136137
CHANGED=$?
137138
if [[ "$CHANGED" -eq 0 ]]; then

0 commit comments

Comments
 (0)