Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -25,7 +25,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env_vars: {

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-api-python-client/.kokoro/test-samples.sh"
value: "github/google-api-python-client/.kokoro/test-system.sh"
}

# Configure the docker image for kokoro-trampoline.
Expand All @@ -31,7 +31,7 @@ env_vars: {
}

# Download secrets for samples
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
Expand Down
103 changes: 0 additions & 103 deletions .kokoro/test-samples-impl.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ set -eo pipefail
# Enables `**` to include files nested inside sub-folders
shopt -s globstar

exec .kokoro/test-samples-impl.sh
exec .kokoro/test-system-impl.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since .kokoro/test-samples-against-head.sh has been renamed to .kokoro/test-system-against-head.sh, please make sure to update the TRAMPOLINE_BUILD_FILE environment variable in all periodic-head.cfg files (e.g., .kokoro/system/python3.10/periodic-head.cfg, etc.) to point to the new filename. Currently, they still reference the old .kokoro/test-samples-against-head.sh path, which will cause those builds to fail.

78 changes: 78 additions & 0 deletions .kokoro/test-system-impl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# Copyright 2024 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
shopt -s globstar

# Exit early if samples don't exist
if ! find tests/system -name 'requirements.txt' | grep -q .; then
echo "No tests run. './tests/system/**/requirements.txt' not found"
exit 0
fi
Comment on lines +19 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

During periodic builds, the repository is checked out at the LATEST_RELEASE tag (which was created before this migration). At that tag, the tests/system directory does not exist, but samples does. As a result, find tests/system will fail, and the script will silently exit with 0 without running any tests.

To prevent this, we should dynamically fall back to samples if tests/system is not present.

Suggested change
# Exit early if samples don't exist
if ! find tests/system -name 'requirements.txt' | grep -q .; then
echo "No tests run. './tests/system/**/requirements.txt' not found"
exit 0
fi
# Exit early if tests don't exist
TEST_DIR="tests/system"
if [ ! -d "$TEST_DIR" ] && [ -d "samples" ]; then
TEST_DIR="samples"
fi
if ! find "$TEST_DIR" -name 'requirements.txt' | grep -q .; then
echo "No tests run. './$TEST_DIR/**/requirements.txt' not found"
exit 0
fi


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

# Debug: show build environment
env | grep KOKORO

# Install nox
python3.9 -m pip install --upgrade --quiet nox virtualenv==20.26.6

# Setup project id.
if [[ -f "${KOKORO_GFILE_DIR}/project-id.json" ]]; then
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
gcloud config set project "$PROJECT_ID"
fi

# Setup service account credentials.
if [[ -f "${KOKORO_GFILE_DIR}/service-account.json" ]]; then
export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
fi

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

set +e
RTN=0
ROOT=$(pwd)
for file in tests/system/**/requirements.txt; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Use the dynamically resolved $TEST_DIR variable to support running tests on older releases during periodic builds.

Suggested change
for file in tests/system/**/requirements.txt; do
for file in "$TEST_DIR"/**/requirements.txt; do

cd "$ROOT"
file=$(dirname "$file")
cd "$file"

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

python3.9 -m nox -s "$RUN_TESTS_SESSION"
EXIT=$?

if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot
$KOKORO_GFILE_DIR/linux_amd64/flakybot
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"
exit "$RTN"
10 changes: 5 additions & 5 deletions .kokoro/test-samples.sh → .kokoro/test-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# The default test runner for samples.
#
# For periodic builds, we rewinds the repo to the latest release, and
# run test-samples-impl.sh.
# run test-system-impl.sh.

# `-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
Expand All @@ -27,7 +27,7 @@ shopt -s globstar
# Run periodic samples tests at latest release
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
# preserving the test runner implementation.
cp .kokoro/test-samples-impl.sh "${TMPDIR}/test-samples-impl.sh"
cp .kokoro/test-system-impl.sh "${TMPDIR}/test-system-impl.sh"
echo "--- IMPORTANT IMPORTANT IMPORTANT ---"
echo "Now we rewind the repo back to the latest release..."
LATEST_RELEASE=$(git describe --abbrev=0 --tags)
Expand All @@ -36,9 +36,9 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
echo $(git rev-parse --verify HEAD)
echo "--- IMPORTANT IMPORTANT IMPORTANT ---"
# move back the test runner implementation if there's no file.
if [ ! -f .kokoro/test-samples-impl.sh ]; then
cp "${TMPDIR}/test-samples-impl.sh" .kokoro/test-samples-impl.sh
if [ ! -f .kokoro/test-system-impl.sh ]; then
cp "${TMPDIR}/test-system-impl.sh" .kokoro/test-system-impl.sh
fi
fi

exec .kokoro/test-samples-impl.sh
exec .kokoro/test-system-impl.sh
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pep8:
find googleapiclient samples -name "*.py" | xargs pep8 --ignore=E111,E202
find googleapiclient tests/system -name "*.py" | xargs pep8 --ignore=E111,E202

APP_ENGINE_PATH=../google_appengine

Expand Down Expand Up @@ -32,8 +32,8 @@ prerelease:
python expandsymlinks.py
cd snapshot; python setup.py clean
cd snapshot; python setup.py sdist --formats=gztar,zip bdist_wheel --universal
cd snapshot; tar czf google-api-python-client-samples-$(shell python setup.py --version).tar.gz samples
cd snapshot; zip -r google-api-python-client-samples-$(shell python setup.py --version).zip samples
cd snapshot; tar czf google-api-python-client-samples-$(shell python setup.py --version).tar.gz tests/system
cd snapshot; zip -r google-api-python-client-samples-$(shell python setup.py --version).zip tests/system


.PHONY: release
Expand Down
Loading
Loading