Skip to content

Commit 1362362

Browse files
authored
Only run samples for changed files (GoogleCloudPlatform#343)
1 parent 38a9cf2 commit 1362362

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

testing/run_test_suite.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,30 @@ if [ "${RUN_CS_FIXER}" = "true" ]; then
2020
${HOME}/php-cs-fixer fix --dry-run --diff
2121
fi
2222

23-
# loop through all directories containing "phpunit.xml*" and run them
23+
# Determine all files changed on this branch
24+
# (will be empty if running from "master").
25+
FILES_CHANGED=$(git diff --name-only HEAD $(git merge-base HEAD master))
26+
27+
# If any files outside the sample directires changed, or if we are not
28+
# on a Pull Request, run the whole test suite.
29+
if grep -q ^testing\/ <<< "$FILES_CHANGED" || \
30+
grep -qv \/ <<< "$FILES_CHANGED" || \
31+
[ -e $TRAVIS_PULL_REQUEST_BRANCH ]; then
32+
RUN_ALL_TESTS=1
33+
else
34+
RUN_ALL_TESTS=0
35+
fi
36+
37+
# Loop through all directories containing "phpunit.xml*" and run the test suites.
2438
find * -name 'phpunit.xml*' -not -path '*/vendor/*' -exec dirname {} \; | while read DIR
2539
do
40+
# Only run tests for samples that have changed.
41+
if [ "$RUN_ALL_TESTS" -ne "1" ]; then
42+
if ! grep -q ^$DIR <<< "$FILES_CHANGED" ; then
43+
echo "Skipping tests in $DIR\n"
44+
continue
45+
fi
46+
fi
2647
pushd ${DIR}
2748
if [ -f "composer.json" ]; then
2849
composer install

0 commit comments

Comments
 (0)