...

Text file src/cloud.google.com/go/internal/kokoro/presubmit.sh

Documentation: cloud.google.com/go/internal/kokoro

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

View as plain text