Skip to content

Commit d5afc7c

Browse files
authored
Switch continuous tests to only test changed files. (#3339)
* Switch continous tests to only test changes. * Match flag to files. * Update comments. * Fix typo.
1 parent 2b40ca0 commit d5afc7c

13 files changed

+42
-21
lines changed

.kokoro/lint/continuous.cfg

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

.kokoro/lint/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
20+
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
2121
}

.kokoro/python2.7/continuous.cfg

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

.kokoro/python2.7/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
20+
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
2121
}

.kokoro/python3.6/continuous.cfg

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

.kokoro/python3.6/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
20+
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
2121
}

.kokoro/python3.7/continuous.cfg

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

.kokoro/python3.7/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
20+
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
2121
}

.kokoro/python3.8/continuous.cfg

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

.kokoro/python3.8/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/python-docs-samples/.kokoro/tests/run_tests_only_diff.sh"
20+
value: "github/python-docs-samples/.kokoro/tests/run_tests_diff_master.sh"
2121
}

.kokoro/tests/run_tests.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ set -eo pipefail
2020
# Enables `**` to include files nested inside sub-folders
2121
shopt -s globstar
2222

23-
# `--only-changed` will only run tests on projects container changes from the master branch.
24-
if [[ $* == *--only-diff* ]]; then
25-
ONLY_DIFF="true"
26-
else
27-
ONLY_DIFF="false"
23+
DIFF_FROM=""
24+
25+
# `--only-diff-master will only run tests on project changes from the master branch.
26+
if [[ $* == *--only-diff-master* ]]; then
27+
DIFF_FROM="origin/master.."
28+
fi
29+
30+
# `--only-diff-master will only run tests on project changes from the previous commit.
31+
if [[ $* == *--only-diff-head* ]]; then
32+
DIFF_FROM="HEAD~.."
2833
fi
2934

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

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

108-
# If this is a continuous build, send the test log to the Build Cop Bot.
113+
# If this is a periodic build, send the test log to the Build Cop Bot.
109114
# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
110-
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then
115+
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
111116
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
112117
$KOKORO_GFILE_DIR/linux_amd64/buildcop
113118
fi

.kokoro/tests/run_tests_only_diff.sh renamed to .kokoro/tests/run_tests_diff_head.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
mydir="${0%/*}"
16-
"$mydir"/run_tests.sh --only-diff
16+
"$mydir"/run_tests.sh --only-diff-head
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 Google LLC
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+
mydir="${0%/*}"
16+
"$mydir"/run_tests.sh --only-diff-master

0 commit comments

Comments
 (0)