8000 Merge branch 'master' into tasksWithAuth · ulfjack/java-docs-samples@7631a89 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7631a89

Browse files
authored
Merge branch 'master' into tasksWithAuth
2 parents c6abcfa + f
10000
8d02b4 commit 7631a89

File tree

196 files changed

+463
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+463
-938
lines changed

.kokoro/java11/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/java-docs-samples/.kokoro/tests/diff_tests.sh"
20+
value: "github/java-docs-samples/.kokoro/tests/run_diff_only.sh"
2121
}

.kokoro/java8/presubmit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Tell the trampoline which build file to use.
1818
env_vars: {
1919
key: "TRAMPOLINE_BUILD_FILE"
20-
value: "github/java-docs-samples/.kokoro/tests/diff_tests.sh"
20+
value: "github/java-docs-samples/.kokoro/tests/run_diff_only.sh"
2121
}

.kokoro/tests/diff_tests.sh

Lines changed: 0 additions & 89 deletions
This file was deleted.

.kokoro/tests/run_diff_only.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2017 Google Inc.
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+
mydir="${0%/*}"
16+
"$mydir"/run_tests.sh --only-diff

.kokoro/tests/run_tests.sh

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,118 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# `-e` enables the script to automatically fail when a command fails
17+
# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
1618
set -eo pipefail
19+
# Enables `**` to include files nested inside sub-folders
1720
shopt -s globstar
18-
# We spin up some subprocesses. Don't kill them on hangup
19-
trap '' HUP
20-
21-
# Update gcloud and check version
22-
gcloud components update --quiet
23-
echo "********** GCLOUD INFO ***********"
24-
gcloud -v
25-
echo "********** MAVEN INFO ***********"
26-
mvn -v
27-
echo "********** GRADLE INFO ***********"
28-
gradle -v
29-
30-
# Setup required enviormental variables
31-
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
32-
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
33-
source ${KOKORO_GFILE_DIR}/aws-secrets.sh
34-
source ${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh
35-
source ${KOKORO_GFILE_DIR}/dlp_secrets.txt
36-
# Activate service account
37-
gcloud auth activate-service-account\
38-
--key-file=$GOOGLE_APPLICATION_CREDENTIALS \
39-
--project=$GOOGLE_CLOUD_PROJECT
40-
41-
echo -e "\n******************** TESTING AFFECTED PROJECTS ********************"
21+
22+
# `--debug` can be added make local testing of this script easier
23+
if [[ $* == *--script-debug* ]]; then
24+
SCRIPT_DEBUG="true"
25+
JAVA_VERSION="1.8"
26+
else
27+
SCRIPT_DEBUG="false"
28+
fi
29+
30+
# `--only-changed` will only run tests on projects container changes from the master branch.
31+
if [[ $* == *--only-diff* ]]; then
32+
ONLY_DIFF="true"
33+
else
34+
ONLY_DIFF="false"
35+
fi
36+
37+
# Verify Java versions have been specified
38+
if [[ -z ${JAVA_VERSION+x} ]]; then
39+
echo -e "'JAVA_VERSION' env var should be a comma delimited list of valid java versions."
40+
exit 1
41+
fi
42+
43+
if [[ "$SCRIPT_DEBUG" != "true" ]]; then
44+
# Update `gcloud` and log versioning for debugging.
45+
gcloud components update --quiet
46+
echo "********** GCLOUD INFO ***********"
47+
gcloud -v
48+
echo "********** MAVEN INFO ***********"
49+
mvn -v
50+
echo "********** GRADLE INFO ***********"
51+
gradle -v
52+
53+
# Setup required env variables
54+
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
55+
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
56+
source "${KOKORO_GFILE_DIR}/aws-secrets.sh"
57+
source "${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh"
58+
source "${KOKORO_GFILE_DIR}/dlp_secrets.txt"
59+
# Activate service account
60+
gcloud auth activate-service-account \
61+
--key-file="$GOOGLE_APPLICATION_CREDENTIALS" \
62+
--project="$GOOGLE_CLOUD_PROJECT"
63+
64+
cd github/java-docs-samples
65+
fi
66+
67+
echo -e "\n******************** TESTING PROJECTS ********************"
68+
# Switch to 'fail at end' to allow all tests to complete before exiting.
4269
set +e
43-
RESULT=0
44-
cd github/java-docs-samples
45-
# For every pom.xml (may break on whitespace)
70+
# Use RTN to return a non-zero value if the test fails.
71+
RTN=0
72+
ROOT=$(pwd)
73+
# Find all POMs in the repository (may break on whitespace).
4674
for file in **/pom.xml; do
47-
# Navigate to project
75+
cd "$ROOT"
76+
# Navigate to the project folder.
4877
file=$(dirname "$file")
49-
pushd "$file" > /dev/null
50-
51-
# Only test leafs to prevent testing twice
52-
PARENT=$(grep "<modules>" pom.xml -c)
53-
54-
# Get the Java version from the pom.xml
55-
VERSION=$(grep -oP '(?<=<maven.compiler.target>).*?(?=</maven.compiler.target>)' pom.xml)
56-
57-
# Check for changes to the current folder
58-
if [ "$PARENT" -eq 0 ] && [[ "$JAVA_VERSION" = *"$VERSION"* ]]; then
59-
echo "------------------------------------------------------------"
60-
echo "- testing $file"
61-
echo "------------------------------------------------------------"
62-
63-
# Run tests and update RESULT if failed
64-
mvn -q --batch-mode --fail-at-end clean verify \
65-
-Dfile.encoding="UTF-8" \
66-
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
67-
-Dmaven.test.redirectTestOutputToFile=true \
68-
-Dbigtable.projectID="${GOOGLE_CLOUD_PROJECT}" \
69-
-Dbigtable.instanceID=instance
70-
EXIT=$?
71-
72-
if [ $EXIT -ne 0 ]; then
73-
echo -e "\n Tests failed. \n"
74-
RESULT=1
75-
else
76-
echo -e "\n Tests complete. \n"
78+
cd "$file"
79+
80+
# If $DIFF_ONLY is true, skip projects without changes.
81+
if [[ "$ONLY_DIFF" = "true" ]]; then
82+
git diff --quiet origin/master.. .
83+
CHANGED=$?
84+
if [[ "$CHANGED" -eq 0 ]]; then
85+
# echo -e "\n Skipping $file: no changes in folder.\n"
86+
continue
7787
fi
7888
fi
7989

80-
popd > /dev/null
90+
echo "------------------------------------------------------------"
91+
echo "- testing $file"
92+
echo "------------------------------------------------------------"
93+
94+
# Fail the tests if no Java version was found.
95+
POM_JAVA=$(grep -oP '(?<=<maven.compiler.target>).*?(?=</maven.compiler.target>)' pom.xml)
96+
if [[ "$POM_JAVA" = "" ]]; then
97+
RTN=1
98+
echo -e "\n Testing failed: Unable to determine Java version. Please set in pom:"
99+
echo -e "\n<properties>"
100+
echo -e " <maven.compiler.target>1.8</maven.compiler.target>"
101+
echo -e " <maven.compiler.source>1.8</maven.compiler.source>"
102+
echo -e "</properties>\n"
103+
continue
104+
fi
105+
106+
# Skip tests that don't have the correct Java version.
107+
if ! [[ ",$JAVA_VERSION," =~ ",$POM_JAVA," ]]; then
108+
echo -e "\n Skipping tests: Java version ($POM_JAVA) not required ($JAVA_VERSION)\n"
109+
continue
110+
fi
111+
112+
# Use maven to execute the tests for the project.
113+
mvn -q --batch-mode --fail-at-end clean verify \
114+
-Dfile.encoding="UTF-8" \
115+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
116+
-Dmaven.test.redirectTestOutputToFile=true \
117+
-Dbigtable.projectID="${GOOGLE_CLOUD_PROJECT}" \
118+
-Dbigtable.instanceID=instance
119+
EXIT=$?
120+
121+
if [[ $EXIT -ne 0 ]]; then
122+
RTN=1
123+
echo -e "\n Testing failed: Maven returned a non-zero exit code. \n"
124+
else
125+
echo -e "\n Testing completed.\n"
126+
fi
81127

82128
done
83129

84-
exit $RESULT
130+
exit "$RTN"

appengine-java8/analytics/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>com.google.cloud.samples</groupId>
2929
<artifactId>shared-configuration</artifactId>
30-
<version>1.0.9</version>
30+
<version>1.0.11</version>
3131
</parent>
3232

3333
<properties>

appengine-java8/appidentity/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>com.google.cloud.samples</groupId>
2929
<artifactId>shared-configuration</artifactId>
30-
<version>1.0.9</version>
30+
<version>1.0.11</version>
3131
</parent>
3232

3333
<properties>

appengine-java8/bigquery/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>com.google.cloud.samples</groupId>
2929
<artifactId>shared-configuration</artifactId>
30-
<version>1.0.9</version>
30+
<version>1.0.11</version>
3131
</parent>
3232

3333
<properties>

appengine-java8/bigtable/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ limitations under the License.
3030
<parent>
3131
<groupId>com.google.cloud.samples</groupId>
3232
<artifactId>shared-configuration</artifactId>
33-
<version>1.0.9</version>
33+
<version>1.0.11</version>
3434
</parent>
3535

3636
<properties>
@@ -139,7 +139,7 @@ limitations under the License.
139139
<plugin>
140140
<groupId>org.apache.maven.plugins</groupId>
141141
<artifactId>maven-failsafe-plugin</artifactId>
142-
<version>2.20.1</version>
142+
<version>3.0.0-M3</version>
143143
<configuration>
144144
<systemPropertyVariables>
145145
<BIGTABLE_PROJECT>${bigtable.projectID}</BIGTABLE_PROJECT>

appengine-java8/cloudsql-postgres/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>com.google.cloud.samples</groupId>
2929
<artifactId>shared-configuration</artifactId>
30-
<version>1.0.9</version>
30+
<version>1.0.11</version>
3131
</parent>
3232

3333
<!-- [START gae_java8_postgres_properties] -->

0 commit comments

Comments
 (0)
0