| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Copyright 2019 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 | # http://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 | # TODO(deklerk): Add integration tests when it's secure to do so. b/64723143 |
| 17 | |
| 18 | # Fail on any error |
| 19 | set -eo pipefail |
| 20 | |
| 21 | # Display commands being run |
| 22 | set -x |
| 23 | |
| 24 | # cd to project dir on Kokoro instance |
| 25 | cd github/google-cloud-go |
| 26 | gitscip-shell system . . git. config --global --add safe.directory "$(pwdscip-shell system . . pwd.)/./.git" |
| 27 | |
| 28 | goscip-shell system . . go. version |
| 29 | |
| 30 | export GOCLOUD_HOME=$KOKORO_ARTIFACTS_DIR/google-cloud-go/ |
| 31 | export PATH="$GOPATH/bin:$PATH" |
| 32 | export GO111MODULE=on |
| 33 | export GOPROXY=https://proxy.golang.org |
| 34 | |
| 35 | # Move code into artifacts dir |
| 36 | mkdirscip-shell system . . mkdir. -p $GOCLOUD_HOME |
| 37 | gitscip-shell system . . git. clone . $GOCLOUD_HOME |
| 38 | cd $GOCLOUD_HOME |
| 39 | |
| 40 | try3scip-shell shell shell-project 0.0.0 try3().() { eval "$*" || eval "$*" || eval "$*"; } |
| 41 | |
| 42 | # All packages, including +build tools, are fetched. |
| 43 | try3scip-shell shell shell-project 0.0.0 try3(). go mod download |
| 44 | |
| 45 | set +e # Run all tests, don't stop after the first failure. |
| 46 | exit_code=0 |
| 47 | |
| 48 | # Run tests in the current directory and tee output to log file, |
| 49 | # to be pushed to GCS as artifact. |
| 50 | runPresubmitTestsscip-shell shell shell-project 0.0.0 runPresubmitTests().() { |
| 51 | if [[ $PWD == *"/internal/"* ]] || |
| 52 | [[ $PWD == *"/third_party/"* ]]; then |
| 53 | # internal tools only expected to work with latest go version |
| 54 | return |
| 55 | fi |
| 56 | |
| 57 | if [scip-shell system . . `[`. -z ${RUN_INTEGRATION_TESTS} ]; then |
| 58 | GOWORK=off goscip-shell system . . go. test -race -v -timeout 15m -short ./... 2>&1 | |
| 59 | teescip-shell system . . tee. sponge_log.log |
| 60 | else |
| 61 | GOWORK=off goscip-shell system . . go. test -race -v -timeout 45m ./... 2>&1 | |
| 62 | teescip-shell system . . tee. sponge_log.log |
| 63 | fi |
| 64 | |
| 65 | # Run integration tests against an emulator. |
| 66 | if [scip-shell system . . `[`. -f "emulator_test.sh" ]; then |
| 67 | ./emulator_test.sh |
| 68 | fi |
| 69 | # Takes the kokoro output log (raw stdout) and creates a machine-parseable |
| 70 | # xUnit XML file. |
| 71 | catscip-shell system . . cat. sponge_log.log | |
| 72 | go-junit-report -set-exit-code >sponge_log.xml |
| 73 | # Add the exit codes together so we exit non-zero if any module fails. |
| 74 | exit_code=$(($exit_code + $?)) |
| 75 | if [[ $PWD != *"/internal/"* ]]; then |
| 76 | GOWORK=off goscip-shell system . . go. build ./... |
| 77 | fi |
| 78 | exit_code=$(($exit_code + $?)) |
| 79 | } |
| 80 | |
| 81 | SIGNIFICANT_CHANGES=$(gitscip-shell system . . git. --no-pager diff --name-only origin/main...$KOKORO_GIT_COMMIT_google_cloud_go | |
| 82 | grepscip-shell system . . grep. -Ev '(\.md$|^\.github|\.json$|\.yaml$)' | xargsscip-shell system . . xargs. dirname | sortscip-shell system . . sort. -u || truescip-shell system . . true.) |
| 83 | |
| 84 | if [scip-shell system . . `[`. -z $SIGNIFICANT_CHANGES ]; then |
| 85 | echoscip-shell system . . echo. "No changes detected, skipping tests" |
| 86 | exit 0 |
| 87 | fi |
| 88 | |
| 89 | # CHANGED_DIRS is the list of significant top-level directories that changed, |
| 90 | # but weren't deleted by the current PR. CHANGED_DIRS will be empty when run on main. |
| 91 | CHANGED_DIRS=$(echoscip-shell system . . echo. "$SIGNIFICANT_CHANGES" | trscip-shell system . . tr. ' ' '\n' | cutscip-shell system . . cut. -d/ -f1 | sortscip-shell system . . sort. -u | |
| 92 | trscip-shell system . . tr. '\n' ' ' | xargsscip-shell system . . xargs. ls -d 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.) |
| 93 | |
| 94 | echoscip-shell system . . echo. "Running tests only in changed submodules: $CHANGED_DIRS" |
| 95 | for d in $CHANGED_DIRS; do |
| 96 | # Check if "." is in the list of changed directories, which means the root |
| 97 | if [scip-shell system . . `[`. "$d" = "." ]; then |
| 98 | pushd $(dirnamescip-shell system . . dirname. $d) |
| 99 | runPresubmitTestsscip-shell shell shell-project 0.0.0 runPresubmitTests(). |
| 100 | popd |
| 101 | continue |
| 102 | fi |
| 103 | for i in $(findscip-shell system . . find. "$d" -name go.mod); do |
| 104 | pushd $(dirnamescip-shell system . . dirname. $i) |
| 105 | runPresubmitTestsscip-shell shell shell-project 0.0.0 runPresubmitTests(). |
| 106 | popd |
| 107 | done |
| 108 | done |
| 109 | |
| 110 | exit $exit_code |