-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathsystem.sh
More file actions
executable file
·149 lines (124 loc) · 5.15 KB
/
system.sh
File metadata and controls
executable file
·149 lines (124 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# Copyright 2020 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.
# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to non-zero if any command fails,
# or zero if all commands in the pipeline exit successfully.
set -eo pipefail
# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1
# Setup firestore account credentials
export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/firebase-credentials.json
export PROJECT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
cd "$PROJECT_ROOT"
# This is needed in order for `git diff` to succeed
git config --global --add safe.directory $(realpath .)
RETVAL=0
pwd
run_package_test() {
local package_name=$1
local package_path="packages/${package_name}"
# Declare local overrides to prevent bleeding into the next loop iteration
local PROJECT_ID
local GOOGLE_APPLICATION_CREDENTIALS
local NOX_FILE
local NOX_SESSION
echo "------------------------------------------------------------"
echo "Configuring environment for: ${package_name}"
echo "------------------------------------------------------------"
case "${package_name}" in
"google-auth")
# Copy files needed for google-auth system tests
mkdir -p "${package_path}/system_tests/data"
cp "${KOKORO_GFILE_DIR}/google-auth-service-account.json" "${package_path}/system_tests/data/service_account.json"
cp "${KOKORO_GFILE_DIR}/google-auth-authorized-user.json" "${package_path}/system_tests/data/authorized_user.json"
cp "${KOKORO_GFILE_DIR}/google-auth-impersonated-service-account.json" "${package_path}/system_tests/data/impersonated_service_account.json"
PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/google-auth-project-id.json")
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/google-auth-service-account.json"
NOX_FILE="system_tests/noxfile.py"
NOX_SESSION=""
;;
*)
PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
NOX_FILE="noxfile.py"
NOX_SESSION="system-3.12"
;;
esac
# Export variables for the duration of this function's sub-processes
export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
gcloud config set project "$PROJECT_ID"
# Run the actual test
pushd "${package_path}" > /dev/null
set +e
"${system_test_script}"
local res=$?
set -e
popd > /dev/null
return $res
}
packages_with_system_tests=(
"bigframes"
"google-auth"
"google-cloud-bigquery-storage"
"google-cloud-bigtable"
"google-cloud-datastore"
"google-cloud-dns"
"google-cloud-error-reporting"
"google-cloud-firestore"
"google-cloud-logging"
"google-cloud-ndb"
"google-cloud-pubsub"
"google-cloud-spanner"
"google-cloud-storage"
"google-cloud-testutils"
"pandas-gbq"
"sqlalchemy-bigquery"
"sqlalchemy-spanner"
)
# A file for running system tests
system_test_script="${PROJECT_ROOT}/.kokoro/system-single.sh"
# Join array elements with | for the pattern match
packages_with_system_tests_pattern=$(printf "|*%s*" "${packages_with_system_tests[@]}")
packages_with_system_tests_pattern="${packages_with_system_tests_pattern:1}" # Remove the leading pipe
# Run system tests for each package with directory packages/*/tests/system
for path in `find 'packages' \
\( -type d -wholename 'packages/*/tests/system' \) -o \
\( -type d -wholename 'packages/*/system_tests' \) -o \
\( -type f -wholename 'packages/*/tests/system.py' \)`; do
# Extract the package name and define the relative package path
# 1. Remove the 'packages/' prefix
# 2. Remove everything after the first '/'
package_name=${path#packages/}
package_name=${package_name%%/*}
package_path="packages/${package_name}"
# Determine if we should skip based on git diff
files_to_check="${package_path}/CHANGELOG.md"
if [[ $package_name == @($packages_with_system_tests_pattern) ]]; then
files_to_check="${package_path}"
fi
echo "checking changes with 'git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check}'"
set +e
package_modified=$(git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check} | wc -l)
set -e
if [[ "${package_modified}" -gt 0 ]]; then
# Call the function - its internal exports won't affect the next loop
run_package_test "$package_name" || RETVAL=$?
else
echo "No changes in ${package_name}, skipping."
fi
done
exit ${RETVAL}