diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 55c2b0b3da60..a3ce28669510 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -17,14 +17,44 @@ 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 -if [ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then +if [[ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ]]; then export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_ROOT}/src/${GOOGLE_APPLICATION_CREDENTIALS}) fi diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index 89302a415028..b2ba55d55096 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" } + +# 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 {