1#!/bin/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 16set -eo pipefail 17 18## Get the directory of the build script 19scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) 20## cd to the parent directory, i.e. the root of the git repo 21cd ${scriptDir}/.. 22 23# include common functions 24source ${scriptDir}/common.sh 25 26# Print out Maven & Java version 27mvn -version 28echo ${JOB_TYPE} 29 30# attempt to install 3 times with exponential backoff (starting with 10 seconds) 31retry_with_backoff 3 10 \ 32 mvn install -B -V -ntp \ 33 -DskipTests=true \ 34 -Dclirr.skip=true \ 35 -Denforcer.skip=true \ 36 -Dmaven.javadoc.skip=true \ 37 -Dgcloud.download.skip=true \ 38 -T 1C 39 40# if GOOGLE_APPLICATION_CREDENTIALS is specified as a relative path, prepend Kokoro root directory onto it 41if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then 42 export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS}) 43fi 44 45RETURN_CODE=0 46set +e 47 48case ${JOB_TYPE} in 49test) 50 echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}" 51 mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT} 52 RETURN_CODE=$? 53 ;; 54lint) 55 mvn com.coveo:fmt-maven-plugin:check -B -ntp 56 RETURN_CODE=$? 57 ;; 58javadoc) 59 mvn javadoc:javadoc javadoc:test-javadoc -B -ntp 60 RETURN_CODE=$? 61 ;; 62integration) 63 mvn -B ${INTEGRATION_TEST_ARGS} \ 64 -ntp \ 65 -Penable-integration-tests \ 66 -DtrimStackTrace=false \ 67 -Dclirr.skip=true \ 68 -Denforcer.skip=true \ 69 -fae \ 70 verify 71 RETURN_CODE=$? 72 ;; 73graalvmA) 74 # Run Unit and Integration Tests with Native Image 75 mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Pnative-test test -pl 'oauth2_http' 76 RETURN_CODE=$? 77 ;; 78graalvmB) 79 # Run Unit and Integration Tests with Native Image 80 mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Pnative-test test -pl 'oauth2_http' 81 RETURN_CODE=$? 82 ;; 83samples) 84 SAMPLES_DIR=samples 85 # only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise. 86 if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]] 87 then 88 SAMPLES_DIR=samples/snapshot 89 fi 90 91 if [[ -f ${SAMPLES_DIR}/pom.xml ]] 92 then 93 for FILE in ${KOKORO_GFILE_DIR}/secret_manager/*-samples-secrets; do 94 [[ -f "$FILE" ]] || continue 95 source "$FILE" 96 done 97 98 pushd ${SAMPLES_DIR} 99 mvn -B \ 100 -ntp \ 101 -DtrimStackTrace=false \ 102 -Dclirr.skip=true \ 103 -Denforcer.skip=true \ 104 -fae \ 105 verify 106 RETURN_CODE=$? 107 popd 108 else 109 echo "no sample pom.xml found - skipping sample tests" 110 fi 111 ;; 112clirr) 113 mvn -B -ntp -Denforcer.skip=true clirr:check 114 RETURN_CODE=$? 115 ;; 116*) 117 ;; 118esac 119 120if [ "${REPORT_COVERAGE}" == "true" ] 121then 122 bash ${KOKORO_GFILE_DIR}/codecov.sh 123fi 124 125# fix output location of logs 126bash .kokoro/coerce_logs.sh 127 128if [[ "${ENABLE_FLAKYBOT}" == "true" ]] 129then 130 chmod +x ${KOKORO_GFILE_DIR}/linux_amd64/flakybot 131 ${KOKORO_GFILE_DIR}/linux_amd64/flakybot -repo=googleapis/google-auth-library-java 132fi 133 134echo "exiting with ${RETURN_CODE}" 135exit ${RETURN_CODE} 136