@@ -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"
@@ -57,11 +100,13 @@ packages_with_system_tests=(
57100 " google-cloud-testutils"
58101)
59102
103+ # A file for running system tests
104+ system_test_script=" ${PROJECT_ROOT} /.kokoro/system-single.sh"
105+
60106# Join array elements with | for the pattern match
61107packages_with_system_tests_pattern=$( printf " |*%s*" " ${packages_with_system_tests[@]} " )
62108packages_with_system_tests_pattern=" ${packages_with_system_tests_pattern: 1} " # Remove the leading pipe
63109
64-
65110# Run system tests for each package with directory packages/*/tests/system
66111for path in ` find ' packages' \
67112 \( -type d -wholename ' packages/*/tests/system' \) -o \
@@ -75,32 +120,22 @@ for path in `find 'packages' \
75120 package_name=${package_name%%/* }
76121 package_path=" packages/${package_name} "
77122
78- # Run system tests on every change to these libraries
79- if [[ $package == @ ($packages_with_system_tests_pattern ) ]]; then
80- files_to_check=${package}
81- else
82- files_to_check=${package} /CHANGELOG.md
123+ # Determine if we should skip based on git diff
124+ files_to_check=" ${package_path} /CHANGELOG.md"
125+ if [[ $package_name == @ ($packages_with_system_tests_pattern ) ]]; then
126+ files_to_check=" ${package_path} "
83127 fi
84128
85129 echo " checking changes with 'git diff " ${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH} ...${KOKORO_GITHUB_PULL_REQUEST_COMMIT} " -- ${files_to_check} '"
86130 set +e
87131 package_modified=$( git diff " ${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH} ...${KOKORO_GITHUB_PULL_REQUEST_COMMIT} " -- ${files_to_check} | wc -l)
88132 set -e
89- if [[ " ${package_modified} " -eq 0 ]]; then
90- echo " no change detected in ${files_to_check} , skipping"
133+
134+ if [[ " ${package_modified} " -gt 0 ]]; then
135+ # Call the function - its internal exports won't affect the next loop
136+ run_package_test " $package_name " || RETVAL=$?
91137 else
92- echo " change detected in ${files_to_check} "
93- echo " Running system tests for ${package} "
94- pushd ${package}
95- # Temporarily allow failure.
96- set +e
97- ${system_test_script}
98- ret=$?
99- set -e
100- if [ ${ret} -ne 0 ]; then
101- RETVAL=${ret}
102- fi
103- popd
138+ echo " No changes in ${package_name} , skipping."
104139 fi
105140done
106141exit ${RETVAL}
0 commit comments