From 16687c045feecd9faf9a250415d0259d954523bd Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 18 Jan 2019 10:04:12 -0800 Subject: [PATCH 1/3] Add environment variable for allowing skipping ITs --- .kokoro/common.cfg | 6 ++++++ .kokoro/presubmit/common.cfg | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index 89302a415028..94066c1fa48c 100644 --- a/.kokoro/common.cfg +++ b/.kokoro/common.cfg @@ -11,3 +11,9 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/google-auth-library-java/.kokoro/build.sh" } +q +# By default, always run integration tests +env_vars: { + key: "SKIP_INTEGRATION_TESTS_IF_NO_CHANGES" + value: "false" +} diff --git a/.kokoro/presubmit/common.cfg b/.kokoro/presubmit/common.cfg index 772a5bee1b2f..41dd193a4bb5 100644 --- a/.kokoro/presubmit/common.cfg +++ b/.kokoro/presubmit/common.cfg @@ -14,13 +14,19 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" build_file: "google-cloud-java/.kokoro/trampoline.sh" env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/google-cloud-java/.kokoro/build.sh" + key: "TRAMPOLINE_BUILD_FILE" + value: "github/google-cloud-java/.kokoro/build.sh" } env_vars: { - key: "JOB_TYPE" - value: "test" + key: "JOB_TYPE" + value: "test" +} + +# For presubmits, only run integrations if the code has changed +env_vars: { + key: "SKIP_INTEGRATION_TESTS_IF_NO_CHANGES" + value: "true" } before_action { From 449fe03a90f0dff52297ea7f7113fea02ab6be1b Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 18 Jan 2019 10:29:10 -0800 Subject: [PATCH 2/3] Skip integration tests if there are no changes in that directory --- .kokoro/build.sh | 10 +++++++++- .kokoro/common.cfg | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 55c2b0b3da60..4b2f42dda1b6 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -24,7 +24,7 @@ echo $JOB_TYPE mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgcloud.download.skip=true -B -V # prepend Kokoro root directory onto GOOGLE_APPLICATION_CREDENTIALS path -if [ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then +if [[ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ]]; then export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS}) fi @@ -40,6 +40,14 @@ javadoc) mvn javadoc:javadoc javadoc:test-javadoc ;; integration) + if [[ "${SKIP_INTEGRATION_TESTS_IF_NO_CHANGES}" == "true" ]]; then + DIRECTORY=$(echo ${INTEGRATION_TEST_ARGS} | cut -d' ' -f1) + MASTER_DIFF=$(git diff master ${DIRECTORY}) + if [[ -z "${MASTER_DIFF}" ]]; then + echo "No difference form master, skipping tests." + exit 0 + fi + fi mvn -B -pl ${INTEGRATION_TEST_ARGS} -DtrimStackTrace=false -fae verify ;; *) diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index 94066c1fa48c..b2ba55d55096 100644 --- a/.kokoro/common.cfg +++ b/.kokoro/common.cfg @@ -11,7 +11,7 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/google-auth-library-java/.kokoro/build.sh" } -q + # By default, always run integration tests env_vars: { key: "SKIP_INTEGRATION_TESTS_IF_NO_CHANGES" From 6b870548b358509d4eb5cf82519090eadeb4c266 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Fri, 18 Jan 2019 11:03:32 -0800 Subject: [PATCH 3/3] Also check google-cloud-core client and the grpc-api generated models --- .kokoro/build.sh | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 4b2f42dda1b6..a3ce28669510 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -17,10 +17,40 @@ set -eo pipefail cd github/google-cloud-java/ +function client_has_changes() { + CLIENT_NAME=$1 + if [[ ! -z $(git diff master google-cloud-clients/google-cloud-core*) ]]; then + echo "true" + return + fi + + if [[ ! -z $(git diff master google-cloud-clients/${CLIENT_NAME}) ]]; then + echo "true" + return + fi + + if [[ ! -z $(git diff master google-api-grpc/*${CLIENT_NAME}*) ]]; then + echo "true" + return + fi + + echo "false" +} + # Print out Java version java -version echo $JOB_TYPE +if [[ "${SKIP_INTEGRATION_TESTS_IF_NO_CHANGES}" == "true" ]] && + [[ "${JOB_TYPE}" == "integration" ]]; then + CLIENT=$(echo ${INTEGRATION_TEST_ARGS} | cut -d' ' -f1 | cut -d'/' -f2) + CLIENT_HAS_CHANGES=$(client_has_changes ${CLIENT}) + if [[ "${CLIENT_HAS_CHANGES}" == "false" ]]; then + echo "No difference from master, skipping tests." + exit 0 + fi +fi + mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dgcloud.download.skip=true -B -V # prepend Kokoro root directory onto GOOGLE_APPLICATION_CREDENTIALS path @@ -40,14 +70,6 @@ javadoc) mvn javadoc:javadoc javadoc:test-javadoc ;; integration) - if [[ "${SKIP_INTEGRATION_TESTS_IF_NO_CHANGES}" == "true" ]]; then - DIRECTORY=$(echo ${INTEGRATION_TEST_ARGS} | cut -d' ' -f1) - MASTER_DIFF=$(git diff master ${DIRECTORY}) - if [[ -z "${MASTER_DIFF}" ]]; then - echo "No difference form master, skipping tests." - exit 0 - fi - fi mvn -B -pl ${INTEGRATION_TEST_ARGS} -DtrimStackTrace=false -fae verify ;; *)