From 969b8a300971abec9914f807e23fb219132cd06d Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Thu, 9 May 2019 07:47:31 +0100 Subject: [PATCH 1/2] Check for examples changes in all branch commits Review all the commits in the branch looking for changes inside content/*/examples and if any are found, trigger testing. This assumes that the main line branch is named "master" --- scripts/test_examples.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/test_examples.sh b/scripts/test_examples.sh index baee55c6bae4f..7e6dec78f2607 100755 --- a/scripts/test_examples.sh +++ b/scripts/test_examples.sh @@ -3,17 +3,14 @@ set -e # List files changed in the commit to check -FILES=`git log -n 2 --name-only --format=""` +FILES=($( git diff "$( git merge-base --fork-point master )" --name-only )) TEST_EXAMPLES=No -# Currently examine en directory only, can extend to other lang when neded -for f in $FILES; do - if [[ $f =~ "content/en/examples/" ]]; then +# Check if examples folders (all locales) change in this branch +if printf -- '%s\n' "${FILES[@]}" | grep -qE '^"?content/[^/]+/examples/'; then TEST_EXAMPLES=Yes - break - fi -done +fi function install() { if [[ $TEST_EXAMPLES == No ]]; then From 98d68187a40402d17c6f30386f7f09dd7e9085c2 Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Thu, 9 May 2019 07:47:59 +0100 Subject: [PATCH 2/2] Tidy examples testing wrapper - print diagnostics to standard error - check for a "Yes" value rather than for absence of "No" --- scripts/test_examples.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/test_examples.sh b/scripts/test_examples.sh index 7e6dec78f2607..16ee42877737f 100755 --- a/scripts/test_examples.sh +++ b/scripts/test_examples.sh @@ -13,8 +13,8 @@ if printf -- '%s\n' "${FILES[@]}" | grep -qE '^"?content/[^/]+/examples/'; then fi function install() { - if [[ $TEST_EXAMPLES == No ]]; then - echo "PR not touching examples, skipping example tests install" + if ! [[ $TEST_EXAMPLES == Yes ]]; then + echo "PR not touching examples, skipping example tests install" 1>&2 exit 0 fi @@ -39,8 +39,8 @@ function install() { } function run_test() { - if [[ $TEST_EXAMPLES == No ]]; then - echo "PR not touching examples, skipping example tests execution" + if ! [[ $TEST_EXAMPLES == Yes ]]; then + echo "PR not touching examples, skipping example tests execution" 1>&2 exit 0 fi go test -v k8s.io/website/content/en/examples