-
Notifications
You must be signed in to change notification settings - Fork 101
/
build.sh
executable file
·205 lines (189 loc) · 6.11 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
## Get the directory of the build script
scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
## cd to the parent directory, i.e. the root of the git repo
cd ${scriptDir}/..
# include common functions
source ${scriptDir}/common.sh
# Kokoro integration test uses both JDK 11 and JDK 8. GraalVM dependencies
# require JDK 11 to compile the classes touching GraalVM classes.
if [ -n "${JAVA11_HOME}" ]; then
setJava "${JAVA11_HOME}"
fi
# Print out Maven & Java version
mvn -version
echo ${JOB_TYPE}
# attempt to install 3 times with exponential backoff (starting with 10 seconds)
retry_with_backoff 3 10 \
mvn install -B -V -ntp \
-DskipTests=true \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.javadoc.skip=true \
-Dgcloud.download.skip=true \
-T 1C
# if GOOGLE_APPLICATION_CREDENTIALS is specified as a relative path, prepend Kokoro root directory onto it
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
fi
# Kokoro integration test uses both JDK 11 and JDK 8. We ensure the generated class files
# are compatible with Java 8 when running tests.
if [ -n "${JAVA8_HOME}" ]; then
setJava "${JAVA8_HOME}"
fi
RETURN_CODE=0
set +e
case ${JOB_TYPE} in
test)
# Maven surefire plugin (unit tests) allows us to specify JVM to run the tests.
# https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#jvm
# If we rely on certain things only available in newer JVM than Java 8, this
# tests detect the usage.
echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}"
mvn test -B -V \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Djava.net.preferIPv4Stack=true \
${SUREFIRE_JVM_OPT}
RETURN_CODE=$?
;;
lint)
mvn com.coveo:fmt-maven-plugin:check
RETURN_CODE=$?
;;
javadoc)
mvn javadoc:javadoc javadoc:test-javadoc
RETURN_CODE=$?
;;
integration)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
-Djava.net.preferIPv4Stack=true \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.main.skip=true \
-Dspanner.gce.config.project_id=gcloud-devel \
-Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests \
-fae \
verify
RETURN_CODE=$?
;;
integration-cloud-devel)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
-Djava.net.preferIPv4Stack=true \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.main.skip=true \
-Dspanner.gce.config.server_url=https://staging-wrenchworks.sandbox.googleapis.com \
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/spanner-testing-east1 \
-Dspanner.gce.config.project_id=span-cloud-testing \
-fae \
verify
RETURN_CODE=$?
;;
integration-cloud-staging)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
-Djava.net.preferIPv4Stack=true \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.main.skip=true \
-Dspanner.gce.config.server_url=https://preprod-spanner.sandbox.googleapis.com \
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/spanner-testing \
-Dspanner.gce.config.project_id=span-cloud-testing \
-fae \
verify
RETURN_CODE=$?
;;
graalvm)
# Run Unit and Integration Tests with Native Image
mvn test -Pnative -Penable-integration-tests -Dspanner.gce.config.project_id=gcloud-devel -Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests
RETURN_CODE=$?
;;
graalvm17)
# Run Unit and Integration Tests with Native Image
mvn test -Pnative -Penable-integration-tests -Dspanner.gce.config.project_id=gcloud-devel -Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests
RETURN_CODE=$?
;;
slowtests)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Pslow-tests \
-Djava.net.preferIPv4Stack=true \
-DskipITs=false \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.main.skip=true \
-fae \
verify
RETURN_CODE=$?
;;
samples)
SAMPLES_DIR=samples
# only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise.
if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]]
then
SAMPLES_DIR=samples/snapshot
fi
if [[ -f ${SAMPLES_DIR}/pom.xml ]]
then
for FILE in ${KOKORO_GFILE_DIR}/secret_manager/*-samples-secrets; do
[[ -f "$FILE" ]] || continue
source "$FILE"
done
pushd ${SAMPLES_DIR}
mvn -B \
-ntp \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-fae \
verify
RETURN_CODE=$?
popd
else
echo "no sample pom.xml found - skipping sample tests"
fi
;;
clirr)
mvn -B -Denforcer.skip=true clirr:check
RETURN_CODE=$?
;;
*)
;;
esac
if [ "${REPORT_COVERAGE}" == "true" ]
then
bash ${KOKORO_GFILE_DIR}/codecov.sh
fi
# fix output location of logs
bash .kokoro/coerce_logs.sh
if [[ "${ENABLE_FLAKYBOT}" == "true" ]]
then
chmod +x ${KOKORO_GFILE_DIR}/linux_amd64/flakybot
${KOKORO_GFILE_DIR}/linux_amd64/flakybot -repo=googleapis/java-spanner
fi
echo "exiting with ${RETURN_CODE}"
exit ${RETURN_CODE}