Skip to content

Commit 2bad24a

Browse files
committed
update kokoro scripts for system tests
1 parent 9aa84fd commit 2bad24a

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

.kokoro/system-single.sh

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,32 @@
11
#!/bin/bash
22
# Copyright 2022 Google LLC
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-
# `-e` enables the script to automatically fail when a command fails
17-
# `-o pipefail` sets the exit code to non-zero if any command fails,
18-
# or zero if all commands in the pipeline exit successfully.
3+
# Licensed under the Apache License, Version 2.0 (the "License"); ...
194
set -eo pipefail
205

216
pwd
227

23-
# If NOX_SESSION is set, it only runs the specified session,
24-
# otherwise run all the sessions.
258
NOX_SESSION_ARG=""
26-
27-
# IF NOX_FILE is set, it runs the specific nox file,
28-
# otherwise it runs noxfile.py in the package directory.
299
NOX_FILE_ARG=""
3010

3111
[[ -z "${NOX_SESSION}" ]] || NOX_SESSION_ARG="-s ${NOX_SESSION}"
32-
3312
[[ -z "${NOX_FILE}" ]] || NOX_FILE_ARG="-f ${NOX_FILE}"
3413

35-
python3 -m pip install uv
14+
# 3-Attempt retry loop to absorb GCP quota limits and network blips
3615
for attempt in 1 2 3; do
16+
echo "============================================"
3717
echo "Execution attempt $attempt of 3..."
38-
if uvx --with 'nox[uv]' nox ${NOX_SESSION_ARG} $NOX_FILE_ARG; then
18+
echo "============================================"
19+
20+
if uvx --with 'nox[uv]' nox ${NOX_SESSION_ARG} ${NOX_FILE_ARG}; then
3921
echo "Tests passed successfully!"
4022
exit 0
4123
fi
4224

43-
echo "Tests failed. Backing off for 15 seconds..."
44-
sleep 15
25+
if [[ $attempt -lt 3 ]]; then
26+
echo "Tests failed. Backing off for 15 seconds to absorb quota limits..."
27+
sleep 15
28+
fi
4529
done
4630

4731
echo "Tests failed after 3 attempts. Hard failure."
48-
exit 1
32+
exit 1

.kokoro/system.sh

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,26 @@
11
#!/bin/bash
22
# Copyright 2020 Google LLC
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-
# https://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-
# `-e` enables the script to automatically fail when a command fails
17-
# `-o pipefail` sets the exit code to non-zero if any command fails,
18-
# or zero if all commands in the pipeline exit successfully.
3+
# Licensed under the Apache License, Version 2.0 (the "License"); ...
194
set -eo pipefail
205

21-
# Disable buffering, so that the logs stream through.
226
export PYTHONUNBUFFERED=1
23-
24-
# Setup firestore account credentials
257
export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/firebase-credentials.json
26-
278
export PROJECT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
289

2910
cd "$PROJECT_ROOT"
30-
31-
# This is needed in order for `git diff` to succeed
3211
git config --global --add safe.directory $(realpath .)
3312

34-
RETVAL=0
13+
# HOISTED: Install uv exactly once globally before we fan out
14+
echo "Installing uv globally..."
15+
python3 -m pip install uv
3516

17+
RETVAL=0
3618
pwd
3719

3820
run_package_test() {
3921
local package_name=$1
4022
local package_path="packages/${package_name}"
4123

42-
# Declare local overrides to prevent bleeding into the next loop iteration
4324
local PROJECT_ID
4425
local GOOGLE_APPLICATION_CREDENTIALS
4526
local NOX_FILE
@@ -52,7 +33,6 @@ run_package_test() {
5233

5334
case "${package_name}" in
5435
"google-auth")
55-
# Copy files needed for google-auth system tests
5636
mkdir -p "${package_path}/system_tests/data"
5737
cp "${KOKORO_GFILE_DIR}/google-auth-service-account.json" "${package_path}/system_tests/data/service_account.json"
5838
cp "${KOKORO_GFILE_DIR}/google-auth-authorized-user.json" "${package_path}/system_tests/data/authorized_user.json"
@@ -72,14 +52,13 @@ run_package_test() {
7252
;;
7353
esac
7454

75-
# Export variables for the duration of this function's sub-processes
7655
export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION
7756
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
57+
58+
# NEW: Subshell-isolated GCP auth. Never modify the global gcloud config!
59+
export CLOUDSDK_CORE_PROJECT="${PROJECT_ID}"
60+
export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE="${GOOGLE_APPLICATION_CREDENTIALS}"
7861

79-
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
80-
gcloud config set project "$PROJECT_ID"
81-
82-
# Run the actual test
8362
pushd "${package_path}" > /dev/null
8463
set +e
8564
"${system_test_script}"
@@ -110,35 +89,27 @@ packages_with_system_tests=(
11089
"sqlalchemy-spanner"
11190
)
11291

113-
# A file for running system tests
11492
system_test_script="${PROJECT_ROOT}/.kokoro/system-single.sh"
115-
116-
# Join array elements with | for the pattern match
11793
packages_with_system_tests_pattern=$(printf "|*%s*" "${packages_with_system_tests[@]}")
118-
packages_with_system_tests_pattern="${packages_with_system_tests_pattern:1}" # Remove the leading pipe
94+
packages_with_system_tests_pattern="${packages_with_system_tests_pattern:1}"
11995

12096
declare -A pids
12197

122-
# Run system tests for each package with directory packages/*/tests/system
12398
for path in `find 'packages' \
12499
\( -type d -wholename 'packages/*/tests/system' \) -o \
125100
\( -type d -wholename 'packages/*/system_tests' \) -o \
126101
\( -type f -wholename 'packages/*/tests/system.py' \)`; do
127102

128-
# Extract the package name and define the relative package path
129-
# 1. Remove the 'packages/' prefix
130-
# 2. Remove everything after the first '/'
131103
package_name=${path#packages/}
132104
package_name=${package_name%%/*}
133105
package_path="packages/${package_name}"
134106

135-
# Determine if we should skip based on git diff
136107
files_to_check="${package_path}/CHANGELOG.md"
137108
if [[ $package_name == @($packages_with_system_tests_pattern) ]]; then
138109
files_to_check="${package_path}"
139110
fi
140111

141-
echo "checking changes with 'git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check}'"
112+
echo "checking changes with 'git diff ${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT} -- ${files_to_check}'"
142113
set +e
143114
package_modified=$(git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check} | wc -l)
144115
set -e
@@ -159,14 +130,17 @@ if [[ "${package_modified}" -gt 0 || "$KOKORO_BUILD_ARTIFACTS_SUBDIR" == *"conti
159130
done
160131

161132
echo "============================================================"
162-
echo "Waiting for all concurrent system tests to complete..."
133+
echo "All affected packages dispatched. Waiting for completion..."
163134
echo "============================================================"
164135

165136
for package in "${!pids[@]}"; do
166137
wait ${pids[$package]} || {
138+
echo "============================================================"
167139
echo "ERROR: System tests failed for $package"
140+
echo "============================================================"
168141
RETVAL=1
169142
}
170143
done
171144

145+
echo "All concurrent tests completed."
172146
exit ${RETVAL}

0 commit comments

Comments
 (0)