Skip to content

Commit

Permalink
Merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
averikitsch committed Jun 10, 2019
2 parents c41ea13 + 1a491c8 commit 2cdef7f
Show file tree
Hide file tree
Showing 447 changed files with 17,216 additions and 4,819 deletions.
2 changes: 1 addition & 1 deletion .kokoro/java11/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/java-docs-samples/.kokoro/tests/diff_tests.sh"
value: "github/java-docs-samples/.kokoro/tests/run_diff_only.sh"
}
2 changes: 1 addition & 1 deletion .kokoro/java8/presubmit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/java-docs-samples/.kokoro/tests/diff_tests.sh"
value: "github/java-docs-samples/.kokoro/tests/run_diff_only.sh"
}
89 changes: 0 additions & 89 deletions .kokoro/tests/diff_tests.sh

This file was deleted.

16 changes: 16 additions & 0 deletions .kokoro/tests/run_diff_only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Copyright 2017 Google Inc.
#
# 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.
mydir="${0%/*}"
"$mydir"/run_tests.sh --only-diff
170 changes: 112 additions & 58 deletions .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,126 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar
# We spin up some subprocesses. Don't kill them on hangup
trap '' HUP

# Update gcloud and check version
gcloud components update --quiet
echo "********** GCLOUD INFO ***********"
gcloud -v
echo "********** MAVEN INFO ***********"
mvn -v
echo "********** GRADLE INFO ***********"
gradle -v

# Setup required enviormental variables
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
source ${KOKORO_GFILE_DIR}/aws-secrets.sh
source ${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh
source ${KOKORO_GFILE_DIR}/dlp_secrets.txt
# Activate service account
gcloud auth activate-service-account\
--key-file=$GOOGLE_APPLICATION_CREDENTIALS \
--project=$GOOGLE_CLOUD_PROJECT

echo -e "\n******************** TESTING AFFECTED PROJECTS ********************"

# `--debug` can be added make local testing of this script easier
if [[ $* == *--script-debug* ]]; then
SCRIPT_DEBUG="true"
JAVA_VERSION="1.8"
else
SCRIPT_DEBUG="false"
fi

# `--only-changed` will only run tests on projects container changes from the master branch.
if [[ $* == *--only-diff* ]]; then
ONLY_DIFF="true"
else
ONLY_DIFF="false"
fi

# Verify Java versions have been specified
if [[ -z ${JAVA_VERSION+x} ]]; then
echo -e "'JAVA_VERSION' env var should be a comma delimited list of valid java versions."
exit 1
fi

if [[ "$SCRIPT_DEBUG" != "true" ]]; then
# Update `gcloud` and log versioning for debugging.
gcloud components update --quiet
echo "********** GCLOUD INFO ***********"
gcloud -v
echo "********** MAVEN INFO ***********"
mvn -v
echo "********** GRADLE INFO ***********"
gradle -v

# Setup required env variables
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
source "${KOKORO_GFILE_DIR}/aws-secrets.sh"
source "${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh"
source "${KOKORO_GFILE_DIR}/dlp_secrets.txt"
source "${KOKORO_GFILE_DIR}/bigtable_secrets.txt"
# Activate service account
gcloud auth activate-service-account \
--key-file="$GOOGLE_APPLICATION_CREDENTIALS" \
--project="$GOOGLE_CLOUD_PROJECT"

cd github/java-docs-samples
fi

# Package local jetty dependency for Java11 samples
if [[ "$JAVA_VERSION" == "11" ]]; then
cd appengine-java11/appengine-simple-jetty-main/
mvn install
cd ../../
fi

echo -e "\n******************** TESTING PROJECTS ********************"
# Switch to 'fail at end' to allow all tests to complete before exiting.
set +e
RESULT=0
cd github/java-docs-samples
# For every pom.xml (may break on whitespace)
# Use RTN to return a non-zero value if the test fails.
RTN=0
ROOT=$(pwd)
# Find all POMs in the repository (may break on whitespace).
for file in **/pom.xml; do
# Navigate to project
cd "$ROOT"
# Navigate to the project folder.
file=$(dirname "$file")
pushd "$file" > /dev/null

# Only test leafs to prevent testing twice
PARENT=$(grep "<modules>" pom.xml -c)

# Get the Java version from the pom.xml
VERSION=$(grep -oP '(?<=<maven.compiler.target>).*?(?=</maven.compiler.target>)' pom.xml)

# Check for changes to the current folder
if [ "$PARENT" -eq 0 ] && [[ "$JAVA_VERSION" = *"$VERSION"* ]]; then
echo "------------------------------------------------------------"
echo "- testing $file"
echo "------------------------------------------------------------"

# Run tests and update RESULT if failed
mvn -q --batch-mode --fail-at-end clean verify \
-Dfile.encoding="UTF-8" \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
-Dmaven.test.redirectTestOutputToFile=true \
-Dbigtable.projectID="${GOOGLE_CLOUD_PROJECT}" \
-Dbigtable.instanceID=instance
EXIT=$?

if [ $EXIT -ne 0 ]; then
echo -e "\n Tests failed. \n"
RESULT=1
else
echo -e "\n Tests complete. \n"
cd "$file"

# If $DIFF_ONLY is true, skip projects without changes.
if [[ "$ONLY_DIFF" = "true" ]]; then
git diff --quiet origin/master.. .
CHANGED=$?
if [[ "$CHANGED" -eq 0 ]]; then
# echo -e "\n Skipping $file: no changes in folder.\n"
continue
fi
fi

popd > /dev/null
echo "------------------------------------------------------------"
echo "- testing $file"
echo "------------------------------------------------------------"

# Fail the tests if no Java version was found.
POM_JAVA=$(grep -oP '(?<=<maven.compiler.target>).*?(?=</maven.compiler.target>)' pom.xml)
if [[ "$POM_JAVA" = "" ]]; then
RTN=1
echo -e "\n Testing failed: Unable to determine Java version. Please set in pom:"
echo -e "\n<properties>"
echo -e " <maven.compiler.target>1.8</maven.compiler.target>"
echo -e " <maven.compiler.source>1.8</maven.compiler.source>"
echo -e "</properties>\n"
continue
fi

# Skip tests that don't have the correct Java version.
if ! [[ ",$JAVA_VERSION," =~ ",$POM_JAVA," ]]; then
echo -e "\n Skipping tests: Java version ($POM_JAVA) not required ($JAVA_VERSION)\n"
continue
fi

# Use maven to execute the tests for the project.
mvn -q --batch-mode --fail-at-end clean verify \
-Dfile.encoding="UTF-8" \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
-Dmaven.test.redirectTestOutputToFile=true \
-Dbigtable.projectID="${GOOGLE_CLOUD_PROJECT}" \
-Dbigtable.instanceID=instance
EXIT=$?

if [[ $EXIT -ne 0 ]]; then
RTN=1
echo -e "\n Testing failed: Maven returned a non-zero exit code. \n"
else
echo -e "\n Testing completed.\n"
fi

done

exit $RESULT
exit "$RTN"
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ accept your pull requests.

## Contributing a new sample

1. App Engine Standard samples all go into `/appengine` (java 7) or `/java8-appengine` (Java 8) (if you're contributing a group of samples,
please put the App Engine Standard sample into `/appengine` and provide a link in both `README.md`'s for
the project for the additional sample.

1. App Engine Flexible samples all go into `/flexible`

1. Technology samples go into the project root.
1. See the [SAMPLE_FORMAT.md](SAMPLE_FORMAT.md) for guidelines on the preferred sample format.


## Build Tools
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is a repository that contains java code snippets on [Cloud Platform Documen
Technology Samples:

* [Bigquery](bigquery)
* [Data Catalog](datacatalog)
* [Datastore](datastore)
* [Endpoints](endpoints)
* [Identity-Aware Proxy](iap)
Expand Down
Loading

0 comments on commit 2cdef7f

Please sign in to comment.