Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: start using btlr #3959

Merged
merged 18 commits into from
Jun 9, 2020
Merged
64 changes: 64 additions & 0 deletions .kokoro/tests/run_single_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/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
#
# 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.

# Run the test, assuming it's already in the target directory.
# Requirements:
# The current directory is the test target directory.
# Env var `PROJECT_ROOT` is defined.

echo "------------------------------------------------------------"
echo "- testing ${PWD}"
echo "------------------------------------------------------------"

# If no local noxfile exists, copy the one from root
if [[ ! -f "noxfile.py" ]]; then
PARENT_DIR=$(cd ../ && pwd)
while [[ "$PARENT_DIR" != "${PROJECT_ROOT}" && \
! -f "$PARENT_DIR/noxfile-template.py" ]];
do
PARENT_DIR=$(dirname "$PARENT_DIR")
done
cp "$PARENT_DIR/noxfile-template.py" "./noxfile.py"
echo -e "\n Using noxfile-template from parent folder ($PARENT_DIR). \n"
cleanup_noxfile=1
else
cleanup_noxfile=0
fi

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

# If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log
# to the Build Cop Bot.
# See:
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
if [[ "${REPORT_TO_BUILD_COP_BOT:-}" == "true" ]]; then
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
fi

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

# Remove noxfile.py if we copied.
if [[ $cleanup_noxfile -eq 1 ]]; then
rm noxfile.py
fi

exit ${EXIT}
118 changes: 31 additions & 87 deletions .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ fi
# `--only-diff-head` will only run tests on project changes from the
# previous commit.
if [[ $* == *--only-diff-head* ]]; then
DIFF_FROM="HEAD~.."
set +e
git diff --quiet "HEAD~.." .kokoro/tests .kokoro/docker \
.kokoro/trampoline_v2.sh
CHANGED=$?
set -e
if [[ "${CHANGED}" -eq 0 ]]; then
DIFF_FROM="HEAD~.."
else
echo "Changes to test driver files detected. Running full tests."
fi
fi

if [[ -z "${PROJECT_ROOT:-}" ]]; then
Expand Down Expand Up @@ -94,97 +103,32 @@ set +e
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"

# First we look up the environment variable `RUN_TESTS_DIRS`. If
# the value is set, we'll iterate through the colon separated
# directory list. If the target directory is not under any
# directory in the list, we skip this directory.
# This environment variables are primarily for
# `scripts/run_tests_local.sh`.
#
# The value must be a colon separated list of relative paths from
# the project root.
#
# Example:
# cdn:appengine/flexible
# run tests for `cdn` and `appengine/flexible` directories.
# logging/cloud-client
# only run tests for `logging/cloud-client` directory.
#
if [[ -n "${RUN_TESTS_DIRS:-}" ]]; then
match=0
for d in $(echo "${RUN_TESTS_DIRS}" | tr ":" "\n"); do
# If the current dir starts with one of the
# RUN_TESTS_DIRS, we should run the tests.
if [[ "${file}" = "${d}"* ]]; then
match=1
break
fi
done
if [[ $match -eq 0 ]]; then
continue
fi
fi
# If $DIFF_FROM is set, use it to check for changes in this directory.
if [[ -n "${DIFF_FROM:-}" ]]; then
git diff --quiet "$DIFF_FROM" .
CHANGED=$?
if [[ "$CHANGED" -eq 0 ]]; then
# echo -e "\n Skipping $file: no changes in folder.\n"
continue
fi
fi
test_prog="${PROJECT_ROOT}/.kokoro/tests/run_single_test.sh"

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

# If no local noxfile exists, copy the one from root
if [[ ! -f "noxfile.py" ]]; then
PARENT_DIR=$(cd ../ && pwd)
while [[ "$PARENT_DIR" != "$ROOT" && ! -f "$PARENT_DIR/noxfile-template.py" ]];
do
PARENT_DIR=$(dirname "$PARENT_DIR")
done
cp "$PARENT_DIR/noxfile-template.py" "./noxfile.py"
echo -e "\n Using noxfile-template from parent folder ($PARENT_DIR). \n"
cleanup_noxfile=1
else
cleanup_noxfile=0
fi
btlr_args=(
"run"
"**/requirements.txt"
"--max-concurrency"
"30"
)

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

# If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log
# to the Build Cop Bot.
# See:
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
if [[ "${REPORT_TO_BUILD_COP_BOT:-}" == "true" ]]; then
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
fi
if [[ -n "${DIFF_FROM:-}" ]]; then
btlr_args+=(
"--git-diff"
"${DIFF_FROM} ."
)
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
btlr_args+=(
"--"
"${test_prog}"
)

# Remove noxfile.py if we copied.
if [[ $cleanup_noxfile -eq 1 ]]; then
rm noxfile.py
fi
echo "testing/btlr" "${btlr_args[@]}"

testing/btlr "${btlr_args[@]}"

done
RTN=$?
cd "$ROOT"

# Remove secrets if we used decrypt-secrets.sh.
Expand Down
Loading