Skip to content

Commit c6b6648

Browse files
committed
Add .kokoro/tests/diff_tests.sh to only run tests on changed files during presubmit.
1 parent 406c0f7 commit c6b6648

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.kokoro/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/getting-started-java/.kokoro/tests/run_tests.sh"
20+
value: "github/getting-started-java/.kokoro/tests/diff_tests.sh"
2121
}
2222

.kokoro/tests/diff_tests.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# Copyright 2018 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e -o pipefail
17+
shopt -s globstar
18+
# We spin up some subprocesses. Don't kill them on hangup
19+
trap '' HUP
20+
21+
# Update gcloud and check version
22+
gcloud components update --quiet
23+
echo -e "\n ********** GCLOUD INFO *********** \n"
24+
gcloud -v
25+
echo -e "\n ********** MAVEN INFO *********** \n"
26+
mvn -v
27+
echo -e "\n ********** GRADLE INFO *********** "
28+
gradle -v
29+
30+
# Setup required enviormental variables
31+
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
32+
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
33+
# Activate service account
34+
gcloud auth activate-service-account\
35+
--key-file=$GOOGLE_APPLICATION_CREDENTIALS \
36+
--project=$GOOGLE_CLOUD_PROJECT
37+
38+
echo -e "\n******************** CHECKING FOR AFFECTED FOLDERS ********************"
39+
# Diff to find out what has changed from master
40+
cd github/getting-started-java
41+
find ./*/ -name pom.xml -print0 | sort -z | while read -d $'\0' file
42+
do
43+
file=$(dirname "$file")
44+
echo "------------------------------------------------------------"
45+
echo "- checking $file"
46+
echo "------------------------------------------------------------"
47+
48+
49+
pushd "$file" > /dev/null
50+
set +e
51+
git diff --quiet master.. .
52+
RTN=$?
53+
set -e
54+
55+
# Check for changes to the current folder
56+
if [ "$CHANGED" -eq 1 ] && [ "$PARENT" -eq 0 ]; then
57+
mvn -q --batch-mode --fail-at-end clean verify \
58+
-Dfile.encoding="UTF-8" \
59+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
60+
-Dmaven.test.redirectTestOutputToFile=true \
61+
-Dbigtable.projectID="${GOOGLE_CLOUD_PROJECT}" \
62+
-Dbigtable.instanceID=instance
63+
echo -e " Tests complete. \n"
64+
else
65+
echo -e "\n NO change found. \n"
66+
fi
67+
68+
popd > /dev/null
69+
70+
done

0 commit comments

Comments
 (0)