Skip to content

Commit c482712

Browse files
authoredMay 29, 2020
feat: add templates for python samples projects (#506) (#924)
These templates will be used for templates in python-docs-samples and in Python client libraries. The README generation code is a modified version of https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/scripts/readme-gen. Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Source-Date: Thu May 28 14:39:58 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: ffe10407ee2f261c799fb0d01bf32a8abc67ed1e Source-Link: googleapis/synthtool@ffe1040
1 parent 510d17a commit c482712

18 files changed

+315
-2
lines changed
 

‎.kokoro/samples/lint/common.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Specify which tests to run
11+
env_vars: {
12+
key: "RUN_TESTS_SESSION"
13+
value: "lint"
14+
}
15+
16+
env_vars: {
17+
key: "TRAMPOLINE_BUILD_FILE"
18+
value: "github/google-api-python-client/.kokoro/test-samples.sh"
19+
}
20+
21+
# Configure the docker image for kokoro-trampoline.
22+
env_vars: {
23+
key: "TRAMPOLINE_IMAGE"
24+
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
25+
}
26+
27+
# Download secrets for samples
28+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
29+
30+
# Download trampoline resources.
31+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
32+
33+
# Use the trampoline script to run in docker.
34+
build_file: "google-api-python-client/.kokoro/trampoline.sh"

‎.kokoro/samples/lint/continuous.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

‎.kokoro/samples/lint/periodic.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "False"
6+
}

‎.kokoro/samples/lint/presubmit.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

‎.kokoro/samples/python3.6/common.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Specify which tests to run
11+
env_vars: {
12+
key: "RUN_TESTS_SESSION"
13+
value: "py-3.6"
14+
}
15+
16+
env_vars: {
17+
key: "TRAMPOLINE_BUILD_FILE"
18+
value: "github/google-api-python-client/.kokoro/test-samples.sh"
19+
}
20+
21+
# Configure the docker image for kokoro-trampoline.
22+
env_vars: {
23+
key: "TRAMPOLINE_IMAGE"
24+
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
25+
}
26+
27+
# Download secrets for samples
28+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
29+
30+
# Download trampoline resources.
31+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
32+
33+
# Use the trampoline script to run in docker.
34+
build_file: "google-api-python-client/.kokoro/trampoline.sh"
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
7+
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "False"
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

‎.kokoro/samples/python3.7/common.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Specify which tests to run
11+
env_vars: {
12+
key: "RUN_TESTS_SESSION"
13+
value: "py-3.7"
14+
}
15+
16+
env_vars: {
17+
key: "TRAMPOLINE_BUILD_FILE"
18+
value: "github/google-api-python-client/.kokoro/test-samples.sh"
19+
}
20+
21+
# Configure the docker image for kokoro-trampoline.
22+
env_vars: {
23+
key: "TRAMPOLINE_IMAGE"
24+
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
25+
}
26+
27+
# Download secrets for samples
28+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
29+
30+
# Download trampoline resources.
31+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
32+
33+
# Use the trampoline script to run in docker.
34+
build_file: "google-api-python-client/.kokoro/trampoline.sh"
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "False"
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

‎.kokoro/samples/python3.8/common.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Specify which tests to run
11+
env_vars: {
12+
key: "RUN_TESTS_SESSION"
13+
value: "py-3.8"
14+
}
15+
16+
env_vars: {
17+
key: "TRAMPOLINE_BUILD_FILE"
18+
value: "github/google-api-python-client/.kokoro/test-samples.sh"
19+
}
20+
21+
# Configure the docker image for kokoro-trampoline.
22+
env_vars: {
23+
key: "TRAMPOLINE_IMAGE"
24+
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
25+
}
26+
27+
# Download secrets for samples
28+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
29+
30+
# Download trampoline resources.
31+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
32+
33+
# Use the trampoline script to run in docker.
34+
build_file: "google-api-python-client/.kokoro/trampoline.sh"
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "False"
6+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

‎.kokoro/test-samples.sh

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
# 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+
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+
cd github/google-api-python-client
24+
25+
# Run periodic samples tests at latest release
26+
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
27+
LATEST_RELEASE=$(git describe --abbrev=0 --tags)
28+
git checkout $LATEST_RELEASE
29+
fi
30+
31+
# Disable buffering, so that the logs stream through.
32+
export PYTHONUNBUFFERED=1
33+
34+
# Debug: show build environment
35+
env | grep KOKORO
36+
37+
# Install nox
38+
python3.6 -m pip install --upgrade --quiet nox
39+
40+
# Use secrets acessor service account to get secrets
41+
if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then
42+
gcloud auth activate-service-account \
43+
--key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \
44+
--project="cloud-devrel-kokoro-resources"
45+
fi
46+
47+
# This script will create 3 files:
48+
# - testing/test-env.sh
49+
# - testing/service-account.json
50+
# - testing/client-secrets.json
51+
./scripts/decrypt-secrets.sh
52+
53+
source ./testing/test-env.sh
54+
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json
55+
56+
# For cloud-run session, we activate the service account for gcloud sdk.
57+
gcloud auth activate-service-account \
58+
--key-file "${GOOGLE_APPLICATION_CREDENTIALS}"
59+
60+
export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
61+
62+
echo -e "\n******************** TESTING PROJECTS ********************"
63+
64+
# Switch to 'fail at end' to allow all tests to complete before exiting.
65+
set +e
66+
# Use RTN to return a non-zero value if the test fails.
67+
RTN=0
68+
ROOT=$(pwd)
69+
# Find all requirements.txt in the samples directory (may break on whitespace).
70+
for file in samples/**/requirements.txt; do
71+
cd "$ROOT"
72+
# Navigate to the project folder.
73+
file=$(dirname "$file")
74+
cd "$file"
75+
76+
echo "------------------------------------------------------------"
77+
echo "- testing $file"
78+
echo "------------------------------------------------------------"
79+
80+
# Use nox to execute the tests for the project.
81+
python3.6 -m nox -s "$RUN_TESTS_SESSION"
82+
EXIT=$?
83+
84+
# If this is a periodic build, send the test log to the Build Cop Bot.
85+
# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
86+
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
87+
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
88+
$KOKORO_GFILE_DIR/linux_amd64/buildcop
89+
fi
90+
91+
if [[ $EXIT -ne 0 ]]; then
92+
RTN=1
93+
echo -e "\n Testing failed: Nox returned a non-zero exit code. \n"
94+
else
95+
echo -e "\n Testing completed.\n"
96+
fi
97+
98+
done
99+
cd "$ROOT"
100+
101+
# Workaround for Kokoro permissions issue: delete secrets
102+
rm testing/{test-env.sh,client-secrets.json,service-account.json}
103+
104+
exit "$RTN"

‎synth.metadata

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/google-api-python-client.git",
7-
"sha": "b8458c0b73030155b64a3c2392b2f70e5fbc3baf"
7+
"sha": "510d17a52e0d500fd1a68c554a7d3dcbfdc1a5d6"
88
}
99
},
1010
{
1111
"git": {
1212
"name": "synthtool",
1313
"remote": "https://github.com/googleapis/synthtool.git",
14-
"sha": "d2364eb80b840a36136c8ce12f1c6efabcc9600e"
14+
"sha": "ffe10407ee2f261c799fb0d01bf32a8abc67ed1e"
1515
}
1616
}
1717
]

0 commit comments

Comments
 (0)