github.com/ryanhartje/helm@v3.0.0-beta.3+incompatible/scripts/coverage.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright The Helm Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -euo pipefail
    18  
    19  covermode=${COVERMODE:-atomic}
    20  coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX)
    21  profile="${coverdir}/cover.out"
    22  
    23  hash goveralls 2>/dev/null || go get github.com/mattn/goveralls
    24  hash godir 2>/dev/null || go get github.com/Masterminds/godir
    25  
    26  generate_cover_data() {
    27    for d in $(godir) ; do
    28      (
    29        local output="${coverdir}/${d//\//-}.cover"
    30        go test -coverprofile="${output}" -covermode="$covermode" "$d"
    31      )
    32    done
    33  
    34    echo "mode: $covermode" >"$profile"
    35    grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile"
    36  }
    37  
    38  push_to_coveralls() {
    39    goveralls -coverprofile="${profile}" -service=circle-ci
    40  }
    41  
    42  generate_cover_data
    43  go tool cover -func "${profile}"
    44  
    45  case "${1-}" in
    46    --html)
    47      go tool cover -html "${profile}"
    48      ;;
    49    --coveralls)
    50      push_to_coveralls
    51      ;;
    52  esac
    53