github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/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 pushd / 24 hash goveralls 2>/dev/null || go install github.com/mattn/goveralls@v0.0.11 25 popd 26 27 generate_cover_data() { 28 for d in $(go list ./...) ; do 29 ( 30 local output="${coverdir}/${d//\//-}.cover" 31 go test -coverprofile="${output}" -covermode="$covermode" "$d" 32 ) 33 done 34 35 echo "mode: $covermode" >"$profile" 36 grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile" 37 } 38 39 push_to_coveralls() { 40 goveralls -coverprofile="${profile}" -service=circle-ci 41 } 42 43 generate_cover_data 44 go tool cover -func "${profile}" 45 46 case "${1-}" in 47 --html) 48 go tool cover -html "${profile}" 49 ;; 50 --coveralls) 51 push_to_coveralls 52 ;; 53 esac 54