Skip to content

Commit 9c919fa

Browse files
authored
test: skip sample tests if no changes detected (#1106)
* test: skip sample tests if no changes detected * add exception for test file
1 parent 3ab74b2 commit 9c919fa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.kokoro/test-samples-impl.sh

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

23+
DIFF_FROM="origin/main..."
24+
2325
# Exit early if samples don't exist
2426
if ! find samples -name 'requirements.txt' | grep -q .; then
2527
echo "No tests run. './samples/**/requirements.txt' not found"
@@ -71,6 +73,16 @@ for file in samples/**/requirements.txt; do
7173
file=$(dirname "$file")
7274
cd "$file"
7375

76+
# If $DIFF_FROM is set, use it to check for changes in this directory.
77+
if [[ -n "${DIFF_FROM:-}" ]]; then
78+
git diff --quiet "$DIFF_FROM" .
79+
CHANGED=$?
80+
if [[ "$CHANGED" -eq 0 ]]; then
81+
# echo -e "\n Skipping $file: no changes in folder.\n"
82+
continue
83+
fi
84+
fi
85+
7486
echo "------------------------------------------------------------"
7587
echo "- testing $file"
7688
echo "------------------------------------------------------------"

owlbot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def get_staging_dirs(
137137
".github/workflows", # exclude gh actions as credentials are needed for tests
138138
"README.rst",
139139
".github/release-please.yml",
140+
".kokoro/test-samples-impl.sh",
140141
],
141142
)
142143

0 commit comments

Comments
 (0)