github.com/jenkins-x/test-infra@v0.0.7/hack/check-pr.sh (about)

     1  #!/bin/bash
     2  # Copyright 2018 The Kubernetes Authors.
     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  # Usage: check-pr [ref]
    17  #
    18  # Ideally if check-pr passes then your golang PR will pass presubmit tests.
    19  
    20  set -o nounset
    21  set -o errexit
    22  set -o pipefail
    23  
    24  dirs=()
    25  tests=()
    26  ref="${1:-HEAD}"
    27  echo -n "Packages changed since $ref: "
    28  for d in $(git diff --name-only "$ref" | xargs -n 1 dirname | sort -u); do
    29      if ! ls "./$d/"*.go &> /dev/null; then
    30          continue
    31      fi
    32      echo -n "$d "
    33      dirs+=("./$d")
    34      tests+=("//$d:all")
    35  done
    36  
    37  if [[ ${#dirs[@]} == 0 ]]; then
    38      echo NONE
    39      exit 0
    40  fi
    41  echo
    42  
    43  # step <name> <command ...> runs command and prints the output if it fails.
    44  step() {
    45      echo -n "Running $1... "
    46      shift
    47      tmp="$(mktemp)"
    48      if ! "$@" &> "$tmp"; then
    49          echo FAIL:
    50          cat "$tmp"
    51          rm -f "$tmp"
    52          return 1
    53      fi
    54      rm -f "$tmp"
    55      echo PASS
    56      return 0
    57  }
    58  
    59  failing=()
    60  step hack/verify-bazel.sh hack/verify-bazel.sh || failing+=("bazel")
    61  step hack/verify-gofmt.sh hack/verify-gofmt.sh || failing+=("gofmt")
    62  step //:golint bazel run //:golint -- "${dirs[@]}" || failing+=("golint")
    63  step //:govet bazel run //:govet -- "${dirs[@]}" || failing+=("govet")
    64  step "bazel test" bazel test --build_tests_only "${tests[@]}" || failing+=("bazel test")
    65  step hack/verify_boilerplate.py hack/verify_boilerplate.py || failing+=("boilerplate")
    66  
    67  if [[ "${#failing[@]}" != 0 ]]; then
    68      echo "FAILURE: ${#failing[@]} steps failed: ${failing[@]}"
    69      exit 1
    70  fi
    71  echo "SUCCESS"