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"); ...
194set -eo pipefail
205
21- # Disable buffering, so that the logs stream through.
226export PYTHONUNBUFFERED=1
23-
24- # Setup firestore account credentials
257export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR} /firebase-credentials.json
26-
278export PROJECT_ROOT=$( realpath $( dirname " ${BASH_SOURCE[0]} " ) /..)
289
2910cd " $PROJECT_ROOT "
30-
31- # This is needed in order for `git diff` to succeed
3211git 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
3618pwd
3719
3820run_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
11492system_test_script=" ${PROJECT_ROOT} /.kokoro/system-single.sh"
115-
116- # Join array elements with | for the pattern match
11793packages_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
12096declare -A pids
12197
122- # Run system tests for each package with directory packages/*/tests/system
12398for 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
159130done
160131
161132echo " ============================================================"
162- echo " Waiting for all concurrent system tests to complete ..."
133+ echo " All affected packages dispatched. Waiting for completion ..."
163134echo " ============================================================"
164135
165136for package in " ${! pids[@]} " ; do
166137 wait ${pids[$package]} || {
138+ echo " ============================================================"
167139 echo " ERROR: System tests failed for $package "
140+ echo " ============================================================"
168141 RETVAL=1
169142 }
170143done
171144
145+ echo " All concurrent tests completed."
172146exit ${RETVAL}
0 commit comments