|
| 1 | +#!/bin/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 | + |
| 16 | +set -eo pipefail |
| 17 | +shopt -s globstar |
| 18 | + |
| 19 | +set -xe |
| 20 | +# We spin up some subprocesses. Don't kill them on hangup |
| 21 | +trap '' HUP |
| 22 | + |
| 23 | +# Temporary directory to store any output to display on error |
| 24 | +export ERROR_OUTPUT_DIR |
| 25 | +ERROR_OUTPUT_DIR="$(mktemp -d)" |
| 26 | +trap 'rm -r "${ERROR_OUTPUT_DIR}"' EXIT |
| 27 | + |
| 28 | +delete_app_version() { |
| 29 | + yes | gcloud --project="${GOOGLE_PROJECT_ID}" \ |
| 30 | + app versions delete "${1}" |
| 31 | +} |
| 32 | + |
| 33 | +handle_error() { |
| 34 | + errcode=$? # Remember the error code so we can exit with it after cleanup |
| 35 | + |
| 36 | + # Clean up remote app version |
| 37 | + delete_app_version "${1}" & |
| 38 | + |
| 39 | + # Display any errors |
| 40 | + if [ -n "$(find "${2}" -mindepth 1 -print -quit)" ]; then |
| 41 | + cat "${2:?}"/* 1>&2 |
| 42 | + fi |
| 43 | + |
| 44 | + wait |
| 45 | + |
| 46 | + exit ${errcode} |
| 47 | +} |
| 48 | + |
| 49 | +cleanup() { |
| 50 | + delete_app_version "${GOOGLE_VERSION_ID}" & |
| 51 | + ( [ -d "${ERROR_OUTPUT_DIR}" ] && rm -r "${ERROR_OUTPUT_DIR:?}/"* ) || /bin/true |
| 52 | +} |
| 53 | + |
| 54 | +export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json |
| 55 | +export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing |
| 56 | +export PATH=/google-cloud-sdk/bin:$PATH |
| 57 | + |
| 58 | +echo "******** Environment *********" |
| 59 | +env |
| 60 | +echo "******** mvn & Java *********" |
| 61 | +mvn -version |
| 62 | + |
| 63 | +echo "Update gcloud ********" |
| 64 | +gcloud components update --quiet |
| 65 | + |
| 66 | +echo "******** activate-service-account ********" |
| 67 | +ls -lr ${KOKORO_GFILE_DIR} |
| 68 | + |
| 69 | +gcloud auth activate-service-account\ |
| 70 | + --key-file=$GOOGLE_APPLICATION_CREDENTIALS \ |
| 71 | + --project=$GOOGLE_CLOUD_PROJECT |
| 72 | + |
| 73 | +echo "********* gcloud config ********" |
| 74 | +gcloud config list |
| 75 | + |
| 76 | +echo "******** build everything ********" |
| 77 | +cd github/java-docs-samples |
| 78 | +mvn clean verify | grep -E -v "(^\[INFO\] Download|^\[INFO\].*skipping)" |
| 79 | + |
| 80 | + |
| 81 | +# ( |
| 82 | +# # Stop echoing commands, so we don't leak secret env vars |
| 83 | +# # -Pselenium | \ # LV3 20170616 turn off selenium for now. |
| 84 | +# set +x |
| 85 | +# mvn --batch-mode clean verify \ |
| 86 | +# -Dbookshelf.clientID="${OAUTH2_CLIENT_ID}" \ |
| 87 | +# -Dbookshelf.clientSecret="${OAUTH2_CLIENT_SECRET}" \ |
| 88 | +# -Dbookshelf.bucket="${GCS_BUCKET envvar is unset}" \ |
| 89 | +# | \ |
| 90 | +# grep -E -v "(^\[INFO\] Download|^\[INFO\].*skipping)" |
| 91 | +# ) |
| 92 | +# |
| 93 | +# Test running samples on localhost. |
| 94 | +# git clone https://github.com/GoogleCloudPlatform/java-repo-tools.git |
| 95 | +# ./java-repo-tools/scripts/test-localhost.sh jetty helloworld-jsp -- -DskipTests=true |
| 96 | +# ./java-repo-tools/scripts/test-localhost.sh jetty helloworld-servlet -- -DskipTests=true |
| 97 | +# ./java-repo-tools/scripts/test-localhost.sh jetty helloworld-compat -- -DskipTests=true |
| 98 | +# ./java-repo-tools/scripts/test-localhost.sh spring-boot helloworld-springboot -- -DskipTests=true |
| 99 | + |
| 100 | +# Check that all shell scripts in this repo (including this one) pass the |
| 101 | +Shell Check linter. |
| 102 | +shellcheck ./**/*.sh |
0 commit comments