Skip to content

Commit

Permalink
Attempt to test only reactor-test if all changes are in reactor-test/
Browse files Browse the repository at this point in the history
This works by overriding the default build script from Travis CI and
delegating to a bash script (so that any errors will correctly fail the
build).

The script detects a PR build vs a push build, and looks for any
affected file not starting with `reactor-test/`:

 - PR build: lists the files changed by the commits in the whole PR
   (FETCH_HEAD..TRAVIS_BRANCH, the later being the target branch of the
   PR)
 - push build: use the commit range provided by Travis
   (TRAVIS_COMMIT_RANGE) but work around a few issues. The commit range
   from travis uses `...` notation and we fix it to `..` (as noted in
   issue travis-ci#4596). Furthermore, the range is invalid in case of
   a brand new PR or a rebase/force push. In this case, the diff fails
   and we fallback to only looking at the last commit. This is not ideal
   but the associated PR build should at least test the whole code.

The grep is inverted (-v) and quiet (-q), meaning it will succeed if
anything else than reactor-test is present.

master and 3.0.x push builds are detected in order to force a full test,
as these are merge commits.
  • Loading branch information
simonbasle committed Jun 6, 2017
1 parent 5eefdbb commit 97c3599
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ jdk:

sudo: required

script: ./travis-build.sh

after_success:
- bash <(curl -s https://codecov.io/bash)

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.m2
Expand Down
39 changes: 39 additions & 0 deletions travis-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -ev

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
COMMIT_RANGE="FETCH_HEAD..$TRAVIS_BRANCH"
echo "travis PR #$TRAVIS_PULL_REQUEST build, looking at files in $COMMIT_RANGE"
COMMIT_CONTENT=`git diff --name-only $COMMIT_RANGE`
echo "PR content: $COMMIT_CONTENT"
echo $COMMIT_CONTENT | grep -qv '^reactor-test/' && {
echo "something else than reactor-test was touched -> full test"
./gradlew check
} || {
echo "only reactor-test was touched -> selective test"
./gradlew :reactor-test:check
}
elif [ "$TRAVIS_BRANCH" == "master" ] || [ "$TRAVIS_BRANCH" == "3.0.x" ]; then
echo "master or 3.0.x: this is a merge test -> full test"
./gradlew check
else
COMMIT_RANGE=${TRAVIS_COMMIT_RANGE/.../..}
if ! git diff --quiet "$COMMIT_RANGE" -- ; then
echo "travis commit range diff failed, probably new PR or force push, falling back to single commit"
COMMIT_CONTENT=`git diff-tree --no-commit-id --name-only -r $TRAVIS_COMMIT`
else
echo "travis push build, looking at files in $COMMIT_RANGE"
COMMIT_CONTENT=`git diff --name-only $COMMIT_RANGE`
fi
echo "commits content: $COMMIT_CONTENT"
echo $COMMIT_CONTENT | grep -qv '^reactor-test/' && {
echo "something else than reactor-test was touched -> full test"
./gradlew check
} || {
echo "only reactor-test was touched -> selective test"
./gradlew :reactor-test:check
}
fi

exit 0;

0 comments on commit 97c3599

Please sign in to comment.