Skip to content

Commit

Permalink
build: add kokoro templates for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 committed May 20, 2020
1 parent 9c1a2fa commit 85eaf42
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/google-cloud-texttospeech/.kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ python3.6 -m pip install --upgrade --quiet nox
python3.6 -m nox --version

python3.6 -m nox

# Run sample tests
python3.6 -m nox -f samples/noxfile.py
11 changes: 11 additions & 0 deletions packages/google-cloud-texttospeech/.kokoro/continuous/samples.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "True"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-texttospeech/.kokoro/test-samples.sh"
}
Empty file.
11 changes: 11 additions & 0 deletions packages/google-cloud-texttospeech/.kokoro/periodic/samples.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "False"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-texttospeech/.kokoro/test-samples.sh"
}
11 changes: 11 additions & 0 deletions packages/google-cloud-texttospeech/.kokoro/presubmit/samples.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Format: //devtools/kokoro/config/proto/build.proto

env_vars: {
key: "INSTALL_LIBRARY_FROM_SOURCE"
value: "True"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-texttospeech/.kokoro/test-samples.sh"
}
84 changes: 84 additions & 0 deletions packages/google-cloud-texttospeech/.kokoro/test-samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# Copyright 2020 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
#
# https://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

cd github/python-texttospeech

# TODO(busunkim): Add logic to checkout library at latest release for periodic

# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1

# Debug: show build environment
env | grep KOKORO

# Install nox
python3.6 -m pip install --upgrade --quiet nox

# Unencrypt and extract secrets
SECRETS_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secrets-password.txt")
./scripts/decrypt-secrets.sh "${SECRETS_PASSWORD}"

source ./testing/test-env.sh
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json
export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json

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

cd samples

# Switch to 'fail at end' to allow all tests to complete before exiting.
set +e
# Use RTN to return a non-zero value if the test fails.
RTN=0
ROOT=$(pwd)
# Find all requirements.txt in the repository (may break on whitespace).
for file in **/requirements.txt; do
cd "$ROOT"
# Navigate to the project folder.
file=$(dirname "$file")
cd "$file"

echo "------------------------------------------------------------"
echo "- testing $file"
echo "------------------------------------------------------------"

# Use nox to execute the tests for the project.
python3.6 -m nox -s "$RUN_TESTS_SESSION"
EXIT=$?

# If this is a periodic build, send the test log to the Build Cop Bot.
# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
fi

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

done
cd "$ROOT"

# Workaround for Kokoro permissions issue: delete secrets
rm testing/{test-env.sh,client-secrets.json,service-account.json}

exit "$RTN"
26 changes: 26 additions & 0 deletions packages/google-cloud-texttospeech/scripts/decrypt-secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
#
# 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.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT=$( dirname "$DIR" )

# Work from the project root.
cd $ROOT

openssl aes-256-cbc -k "$1" -md sha256 \
-in testing/secrets.tar.enc -out secrets.tar -d
tar xvf secrets.tar
rm secrets.tar

0 comments on commit 85eaf42

Please sign in to comment.