From 960eb12d72a6720a1682fa6cf207378900364967 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Mon, 24 Oct 2016 15:03:28 -0700 Subject: [PATCH 1/3] Travis - Only run tests that have changed --- travis.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/travis.sh b/travis.sh index 3f822b8e2df..6bd060afd53 100755 --- a/travis.sh +++ b/travis.sh @@ -23,8 +23,46 @@ SKIP_TESTS=false if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ] ; then SKIP_TESTS=true fi + +# Finds the closest parent dir that encompasses all changed files, and has a +# pom.xml +travis_changed_files_parent() { + [ -z "$TRAVIS_PULL_REQUEST" ] && return 0 # If we're not in a PR, forget it + + ( + set +e + + changed="$(git diff --name-only "$TRAVIS_COMMIT" "$TRAVIS_BRANCH")" + if [ $? -ne 0 ]; then + # Fall back to git head + changed="$(git diff --name-only "$(git rev-parse HEAD)" "$TRAVIS_BRANCH")" + [ $? -ne 0 ] && return 0 # Give up. Just run everything. + fi + + # Find the common prefix + prefix="$(echo "$changed" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')" + + while [ ! -z "$prefix" ] && [ ! -r "$prefix/pom.xml" ] && [ "${prefix%/*}" != "$prefix" ]; do + prefix="${prefix%/*}" + done + + [ -r "$prefix/pom.xml" ] || return 0 + + echo "$prefix" + ) +} + +git branch +exit 1 +travis_changed_files_parent +common_travis_dir="$(travis_changed_files_parent)" + +[ -z "$common_travis_dir" ] || pushd "$common_travis_dir" + mvn --batch-mode clean verify -DskipTests=$SKIP_TESTS | egrep -v "(^\[INFO\] Download|^\[INFO\].*skipping)" +[ -z "$common_travis_dir" ] || popd + # Check that all shell scripts in this repo (including this one) pass the # Shell Check linter. shellcheck ./**/*.sh @@ -44,7 +82,9 @@ test_localhost() { appengine/datastore/indexes-perfect ) for testdir in "${devserver_tests[@]}" ; do - ./java-repo-tools/scripts/test-localhost.sh appengine "${testdir}" + if [ -z "$common_travis_dir" ] || [[ $testdir = $common_travis_dir* ]]; then + ./java-repo-tools/scripts/test-localhost.sh appengine "${testdir}" + fi done # newplugin_std_tests=( From d2b6849c79528289db22455f13830929017e86c1 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Mon, 24 Oct 2016 15:03:28 -0700 Subject: [PATCH 2/3] Travis - Only run tests that have changed --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0e48bda620a..caec04458d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,3 +53,4 @@ after_success: branches: only: - master + - travis-run-changed From 1c13ba392ad3c4e79a816f9de43e57fac485eab3 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Mon, 24 Oct 2016 18:41:04 -0700 Subject: [PATCH 3/3] Break a test --- travis.sh | 2 +- .../cloud/vision/samples/facedetect/FaceDetectAppTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/travis.sh b/travis.sh index 6bd060afd53..45d167cb0dd 100755 --- a/travis.sh +++ b/travis.sh @@ -52,7 +52,7 @@ travis_changed_files_parent() { ) } -git branch +git branch -r exit 1 travis_changed_files_parent common_travis_dir="$(travis_changed_files_parent)" diff --git a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java index 8c843dcad29..ef2c8959b95 100644 --- a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java +++ b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java @@ -59,7 +59,7 @@ public class FaceDetectAppTest { // Assert assertThat(img.getRGB(10, 5) & 0x00ff00) .named("img face #1 vertex (10, 5) green channel") - .isEqualTo(0x00ff00); + .isEqualTo(0x0fff00); assertThat(img.getRGB(20, 5) & 0x00ff00) .named("img face #1 vertex (20, 5) green channel") .isEqualTo(0x00ff00);