1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ # The default test runner for samples.
17+ #
18+ # For periodic builds, we rewinds the repo to the latest release, and
19+ # run test-samples-impl.sh.
1620
1721# `-e` enables the script to automatically fail when a command fails
1822# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
@@ -24,87 +28,19 @@ cd github/python-monitoring
2428
2529# Run periodic samples tests at latest release
2630if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = * " periodic" * ]]; then
31+ # preserving the test runner implementation.
32+ cp .kokoro/test-samples-impl.sh " ${TMPDIR} /test-samples-impl.sh"
33+ echo " --- IMPORTANT IMPORTANT IMPORTANT ---"
34+ echo " Now we rewind the repo back to the latest release..."
2735 LATEST_RELEASE=$( git describe --abbrev=0 --tags)
2836 git checkout $LATEST_RELEASE
29- fi
30-
31- # Exit early if samples directory doesn't exist
32- if [ ! -d " ./samples" ]; then
33- echo " No tests run. ` ./samples` not found"
34- exit 0
35- fi
36-
37- # Disable buffering, so that the logs stream through.
38- export PYTHONUNBUFFERED=1
39-
40- # Debug: show build environment
41- env | grep KOKORO
42-
43- # Install nox
44- python3.6 -m pip install --upgrade --quiet nox
45-
46- # Use secrets acessor service account to get secrets
47- if [[ -f " ${KOKORO_GFILE_DIR} /secrets_viewer_service_account.json" ]]; then
48- gcloud auth activate-service-account \
49- --key-file=" ${KOKORO_GFILE_DIR} /secrets_viewer_service_account.json" \
50- --project=" cloud-devrel-kokoro-resources"
51- fi
52-
53- # This script will create 3 files:
54- # - testing/test-env.sh
55- # - testing/service-account.json
56- # - testing/client-secrets.json
57- ./scripts/decrypt-secrets.sh
58-
59- source ./testing/test-env.sh
60- export GOOGLE_APPLICATION_CREDENTIALS=$( pwd) /testing/service-account.json
61-
62- # For cloud-run session, we activate the service account for gcloud sdk.
63- gcloud auth activate-service-account \
64- --key-file " ${GOOGLE_APPLICATION_CREDENTIALS} "
65-
66- export GOOGLE_CLIENT_SECRETS=$( pwd) /testing/client-secrets.json
67-
68- echo -e " \n******************** TESTING PROJECTS ********************"
69-
70- # Switch to 'fail at end' to allow all tests to complete before exiting.
71- set +e
72- # Use RTN to return a non-zero value if the test fails.
73- RTN=0
74- ROOT=$( pwd)
75- # Find all requirements.txt in the samples directory (may break on whitespace).
76- for file in samples/** /requirements.txt; do
77- cd " $ROOT "
78- # Navigate to the project folder.
79- file=$( dirname " $file " )
80- cd " $file "
81-
82- echo " ------------------------------------------------------------"
83- echo " - testing $file "
84- echo " ------------------------------------------------------------"
85-
86- # Use nox to execute the tests for the project.
87- python3.6 -m nox -s " $RUN_TESTS_SESSION "
88- EXIT=$?
89-
90- # If this is a periodic build, send the test log to the FlakyBot.
91- # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot.
92- if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = * " periodic" * ]]; then
93- chmod +x $KOKORO_GFILE_DIR /linux_amd64/flakybot
94- $KOKORO_GFILE_DIR /linux_amd64/flakybot
37+ echo " The current head is: "
38+ echo $( git rev-parse --verify HEAD)
39+ echo " --- IMPORTANT IMPORTANT IMPORTANT ---"
40+ # move back the test runner implementation if there's no file.
41+ if [ ! -f .kokoro/test-samples-impl.sh ]; then
42+ cp " ${TMPDIR} /test-samples-impl.sh" .kokoro/test-samples-impl.sh
9543 fi
44+ fi
9645
97- if [[ $EXIT -ne 0 ]]; then
98- RTN=1
99- echo -e " \n Testing failed: Nox returned a non-zero exit code. \n"
100- else
101- echo -e " \n Testing completed.\n"
102- fi
103-
104- done
105- cd " $ROOT "
106-
107- # Workaround for Kokoro permissions issue: delete secrets
108- rm testing/{test-env.sh,client-secrets.json,service-account.json}
109-
110- exit " $RTN "
46+ exec .kokoro/test-samples-impl.sh
0 commit comments