Skip to content

Commit

Permalink
Switch continuous tests to only test changed files. (#3339)
Browse files Browse the repository at this point in the history
* Switch continous tests to only test changes.

* Match flag to files.

* Update comments.

* Fix typo.
  • Loading branch information
kurtisvg authored Apr 11, 2020
1 parent 2b40ca0 commit d5afc7c
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .kokoro/lint/continuous.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_head.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/lint/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python2.7/continuous.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_head.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python2.7/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.6/continuous.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_head.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.6/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.7/continuous.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_head.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.7/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.8/continuous.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_head.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/python3.8/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
}
25 changes: 15 additions & 10 deletions .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar

# `--only-changed` will only run tests on projects container changes from the master branch.
if [[ $* == *--only-diff* ]]; then
ONLY_DIFF="true"
else
ONLY_DIFF="false"
DIFF_FROM=""

# `--only-diff-master will only run tests on project changes from the master branch.
if [[ $* == *--only-diff-master* ]]; then
DIFF_FROM="origin/master.."
fi

# `--only-diff-master will only run tests on project changes from the previous commit.
if [[ $* == *--only-diff-head* ]]; then
DIFF_FROM="HEAD~.."
fi

cd github/python-docs-samples
Expand Down Expand Up @@ -66,9 +71,9 @@ for file in **/requirements.txt; do
file=$(dirname "$file")
cd "$file"

# If $DIFF_ONLY is true, skip projects without changes.
if [[ "$ONLY_DIFF" = "true" ]]; then
git diff --quiet origin/master.. .
# If $DIFF_FROM is set, use it to check for changes in this directory.
if [[ "$DIFF_FROM" != "" ]]; then
git diff --quiet "$DIFF_FROM" .
CHANGED=$?
if [[ "$CHANGED" -eq 0 ]]; then
# echo -e "\n Skipping $file: no changes in folder.\n"
Expand Down Expand Up @@ -105,9 +110,9 @@ for file in **/requirements.txt; do
nox -s "$RUN_TESTS_SESSION"
EXIT=$?

# If this is a continuous build, send the test log to the Build Cop Bot.
# If this is a periodic build, send the test log to the Build Cop Bot.
# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
mydir="${0%/*}"
"$mydir"/run_tests.sh --only-diff
"$mydir"/run_tests.sh --only-diff-head
16 changes: 16 additions & 0 deletions .kokoro/tests/run_tests_diff_master.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
mydir="${0%/*}"
"$mydir"/run_tests.sh --only-diff-master

0 comments on commit d5afc7c

Please sign in to comment.