Skip to content

Commit 1f3ad4c

Browse files
test: presubmit against Lite samples (#425)
* test: presubmit against Lite samples * mark new presubmit test required
1 parent cf84695 commit 1f3ad4c

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed

packages/google-cloud-pubsub/.github/sync-repo-settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ branchProtectionRules:
66
- pattern: master
77
requiredStatusCheckContexts:
88
- 'Kokoro'
9+
- 'Kokoro - Against Pub/Sub Lite samples'
910
- 'cla/google'
1011
- 'Samples - Lint'
1112
- 'Samples - Python 3.6'
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
# Copyright 2021 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+
17+
# `-e` enables the script to automatically fail when a command fails
18+
# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
19+
set -eo pipefail
20+
# Enables `**` to include files nested inside sub-folders
21+
shopt -s globstar
22+
23+
# Disable buffering, so that the logs stream through.
24+
export PYTHONUNBUFFERED=1
25+
26+
# Debug: show build environment
27+
env | grep KOKORO
28+
29+
# Install nox
30+
python3.6 -m pip install --upgrade --quiet nox
31+
32+
# Use secrets acessor service account to get secrets
33+
if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then
34+
gcloud auth activate-service-account \
35+
--key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \
36+
--project="cloud-devrel-kokoro-resources"
37+
fi
38+
39+
cd github/python-pubsub
40+
41+
# This script will create 3 files:
42+
# - testing/test-env.sh
43+
# - testing/service-account.json
44+
# - testing/client-secrets.json
45+
./scripts/decrypt-secrets.sh
46+
47+
source ./testing/test-env.sh
48+
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json
49+
50+
# For cloud-run session, we activate the service account for gcloud sdk.
51+
gcloud auth activate-service-account \
52+
--key-file "${GOOGLE_APPLICATION_CREDENTIALS}"
53+
54+
export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
55+
56+
echo -e "\n******************** TESTING PROJECTS ********************"
57+
58+
# Switch to 'fail at end' to allow all tests to complete before exiting.
59+
set +e
60+
# Use RTN to return a non-zero value if the test fails.
61+
RTN=0
62+
ROOT=$(pwd)
63+
64+
# Clone googleapis/python-pubsublite
65+
git clone https://github.com/googleapis/python-pubsublite.git
66+
67+
# Find all requirements.txt in the Pub/Sub Lite samples directory (may break on whitespace).
68+
for file in python-pubsublite/samples/**/requirements.txt; do
69+
cd "$ROOT"
70+
# Navigate to the project folder.
71+
file=$(dirname "$file")
72+
cd "$file"
73+
74+
echo "------------------------------------------------------------"
75+
echo "- testing $file"
76+
echo "------------------------------------------------------------"
77+
78+
# Use pytest to execute tests for py-3.6
79+
python3.6 -m venv py-3.6
80+
source py-3.6/bin/activate
81+
# Install python-pubsublite samples tests requirements.
82+
python -m pip install -r requirements.txt -q
83+
python -m pip install -r requirements-test.txt -q
84+
# Install python-pubsub from source.
85+
python -m pip install -e "$ROOT" -q
86+
python -m pytest quickstart_test.py
87+
deactivate py-3.6
88+
rm -rf py-3.6/
89+
90+
EXIT=$?
91+
92+
if [[ $EXIT -ne 0 ]]; then
93+
RTN=1
94+
echo -e "\n Testing failed: Nox returned a non-zero exit code. \n"
95+
else
96+
echo -e "\n Testing completed.\n"
97+
fi
98+
99+
done
100+
cd "$ROOT"
101+
102+
# Workaround for Kokoro permissions issue: delete secrets
103+
rm testing/{test-env.sh,client-secrets.json,service-account.json}
104+
105+
exit "$RTN"

packages/google-cloud-pubsub/.kokoro/presubmit/common.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ env_vars: {
2121
key: "TRAMPOLINE_IMAGE"
2222
value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
2323
}
24+
25+
# Obtain environment variables for running Pub/Sub Lite samples tests
2426
env_vars: {
25-
key: "TRAMPOLINE_BUILD_FILE"
26-
value: "github/python-pubsub/.kokoro/build.sh"
27-
}
27+
key: "SECRET_MANAGER_KEYS"
28+
value: "python-docs-samples-test-env"
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
7+
8+
env_vars: {
9+
key: "TRAMPOLINE_BUILD_FILE"
10+
value: "github/python-pubsub/.kokoro/presubmit-against-pubsublite-samples.sh"
11+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# Format: //devtools/kokoro/config/proto/build.proto
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "TRAMPOLINE_BUILD_FILE"
5+
value: "github/python-pubsub/.kokoro/build.sh"
6+
}

0 commit comments

Comments
 (0)