@@ -24,26 +24,69 @@ export PYTHONUNBUFFERED=1
2424# Setup firestore account credentials
2525export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR} /firebase-credentials.json
2626
27- # Setup service account credentials.
28- export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR} /service-account.json
29-
30- # Setup project id.
31- export PROJECT_ID=$( cat " ${KOKORO_GFILE_DIR} /project-id.json" )
32-
33- RETVAL=0
34-
3527export PROJECT_ROOT=$( realpath $( dirname " ${BASH_SOURCE[0]} " ) /..)
3628
3729cd " $PROJECT_ROOT "
3830
39- pwd
40-
41- # A file for running system tests
42- system_test_script=" ${PROJECT_ROOT} /.kokoro/system-single.sh"
43-
4431# This is needed in order for `git diff` to succeed
4532git config --global --add safe.directory $( realpath .)
4633
34+ RETVAL=0
35+
36+ pwd
37+
38+ run_package_test () {
39+ local package_name=$1
40+ local package_path=" packages/${package_name} "
41+
42+ # Declare local overrides to prevent bleeding into the next loop iteration
43+ local PROJECT_ID
44+ local GOOGLE_APPLICATION_CREDENTIALS
45+ local NOX_FILE
46+ local NOX_SESSION
47+
48+ echo " ------------------------------------------------------------"
49+ echo " Configuring environment for: ${package_name} "
50+ echo " ------------------------------------------------------------"
51+
52+ case " ${package_name} " in
53+ " google-auth" )
54+ # Copy files needed for google-auth system tests
55+ mkdir -p " ${package_path} /system_tests/data"
56+ cp " ${KOKORO_GFILE_DIR} /google-auth-service-account.json" " ${package_path} /system_tests/data/service_account.json"
57+ cp " ${KOKORO_GFILE_DIR} /google-auth-authorized-user.json" " ${package_path} /system_tests/data/authorized_user.json"
58+ cp " ${KOKORO_GFILE_DIR} /google-auth-impersonated-service-account.json" " ${package_path} /system_tests/data/impersonated_service_account.json"
59+
60+ PROJECT_ID=$( cat " ${KOKORO_GFILE_DIR} /google-auth-project-id.json" )
61+ GOOGLE_APPLICATION_CREDENTIALS=" ${KOKORO_GFILE_DIR} /google-auth-service-account.json"
62+ NOX_FILE=" system_tests/noxfile.py"
63+ NOX_SESSION=" "
64+ ;;
65+ * )
66+ PROJECT_ID=$( cat " ${KOKORO_GFILE_DIR} /project-id.json" )
67+ GOOGLE_APPLICATION_CREDENTIALS=" ${KOKORO_GFILE_DIR} /service-account.json"
68+ NOX_FILE=" noxfile.py"
69+ NOX_SESSION=" system-3.12"
70+ ;;
71+ esac
72+
73+ # Export variables for the duration of this function's sub-processes
74+ export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION
75+
76+ gcloud auth activate-service-account --key-file=" $GOOGLE_APPLICATION_CREDENTIALS "
77+ gcloud config set project " $PROJECT_ID "
78+
79+ # Run the actual test
80+ pushd " ${package_path} " > /dev/null
81+ set +e
82+ " ${system_test_script} "
83+ local res=$?
84+ set -e
85+ popd > /dev/null
86+
87+ return $res
88+ }
89+
4790packages_with_system_tests=(
4891 " google-auth"
4992 " google-cloud-bigquery-storage"
@@ -56,42 +99,38 @@ packages_with_system_tests=(
5699 " google-cloud-testutils"
57100)
58101
102+ # A file for running system tests
103+ system_test_script=" ${PROJECT_ROOT} /.kokoro/system-single.sh"
104+
59105# Join array elements with | for the pattern match
60106packages_with_system_tests_pattern=$( printf " |*%s*" " ${packages_with_system_tests[@]} " )
61107packages_with_system_tests_pattern=" ${packages_with_system_tests_pattern: 1} " # Remove the leading pipe
62108
63-
64- # Run system tests for each package with directory packages/*/tests/system
65- for dir in ` find ' packages' -type d -wholename ' packages/*/tests/system' ` ; do
66- # Get the path to the package by removing the suffix /tests/system
67- package=$( echo $dir | cut -f -2 -d ' /' )
68-
69- # Run system tests on every change to these libraries
70- if [[ $package == @ ($packages_with_system_tests_pattern ) ]]; then
71- files_to_check=${package}
72- else
73- files_to_check=${package} /CHANGELOG.md
109+ # Run system tests for each package with directory `packages/*/tests/system` or directory `packages/*/system_tests`
110+ for dir in ` find ' packages' -type d -wholename ' packages/*/tests/system' -o -wholename ' packages/*/system_tests' ` ; do
111+ # Extract the package name and define the relative package path
112+ # 1. Remove the 'packages/' prefix from the start
113+ # 2. Remove everything after the first '/' remaining
114+ package_name=${dir# packages/ }
115+ package_name=${package_name%%/* }
116+ package_path=" packages/${package_name} "
117+
118+ # Determine if we should skip based on git diff
119+ files_to_check=" ${package_path} /CHANGELOG.md"
120+ if [[ $package_name == @ ($packages_with_system_tests_pattern ) ]]; then
121+ files_to_check=" ${package_path} "
74122 fi
75123
76124 echo " checking changes with 'git diff " ${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH} ...${KOKORO_GITHUB_PULL_REQUEST_COMMIT} " -- ${files_to_check} '"
77125 set +e
78126 package_modified=$( git diff " ${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH} ...${KOKORO_GITHUB_PULL_REQUEST_COMMIT} " -- ${files_to_check} | wc -l)
79127 set -e
80- if [[ " ${package_modified} " -eq 0 ]]; then
81- echo " no change detected in ${files_to_check} , skipping"
128+
129+ if [[ " ${package_modified} " -gt 0 ]]; then
130+ # Call the function - its internal exports won't affect the next loop
131+ run_package_test " $package_name " || RETVAL=$?
82132 else
83- echo " change detected in ${files_to_check} "
84- echo " Running system tests for ${package} "
85- pushd ${package}
86- # Temporarily allow failure.
87- set +e
88- ${system_test_script}
89- ret=$?
90- set -e
91- if [ ${ret} -ne 0 ]; then
92- RETVAL=${ret}
93- fi
94- popd
133+ echo " No changes in ${package_name} , skipping."
95134 fi
96135done
97136exit ${RETVAL}
0 commit comments