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# 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.
20
21# `-e` enables the script to automatically fail when a command fails
22# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
23set -eo pipefail
24# Enables `**` to include files nested inside sub-folders
25shopt -s globstar
26
27# Run periodic samples tests at latest release
28if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
29    # preserving the test runner implementation.
30    cp .kokoro/test-samples-impl.sh "${TMPDIR}/test-samples-impl.sh"
31    echo "--- IMPORTANT IMPORTANT IMPORTANT ---"
32    echo "Now we rewind the repo back to the latest release..."
33    LATEST_RELEASE=$(git describe --abbrev=0 --tags)
34    git checkout $LATEST_RELEASE
35    echo "The current head is: "
36    echo $(git rev-parse --verify HEAD)
37    echo "--- IMPORTANT IMPORTANT IMPORTANT ---"
38    # move back the test runner implementation if there's no file.
39    if [ ! -f .kokoro/test-samples-impl.sh ]; then
40	cp "${TMPDIR}/test-samples-impl.sh" .kokoro/test-samples-impl.sh
41    fi
42fi
43
44exec .kokoro/test-samples-impl.sh
45