github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/build/upload-coverage.sh (about) 1 #!/usr/bin/env bash 2 3 set -euxo pipefail 4 5 if [ -z "${COVERALLS_TOKEN-}" ]; then 6 echo "FAIL: Missing or empty COVERALLS_TOKEN." 7 exit 1 8 fi 9 if [ -z "${CODECOV_TOKEN-}" ]; then 10 echo "FAIL: Missing or empty CODECOV_TOKEN." 11 exit 1 12 fi 13 14 prefix=github.com/cockroachdb/cockroach/pkg 15 16 coverage_dir=coverage 17 coverage_profile=$coverage_dir/coverage.out 18 19 trap "rm -rf $coverage_dir" EXIT 20 21 rm -rf $coverage_dir 22 mkdir -p $coverage_dir 23 24 # Run coverage on each package, because go test "cannot use test profile flag 25 # with multiple packages". See https://github.com/golang/go/issues/6909. 26 for pkg in $(go list $prefix/...); do 27 # Only generate coverage for cockroach dependencies. 28 # 29 # Note that grep's exit status is ignored here to allow for packages with no 30 # dependencies. 31 coverpkg=$(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}{{"\n"}}{{join .XTestImports "\n"}}' $pkg | \ 32 sort -u | grep -v '^C$' | \ 33 xargs go list -f '{{if not .Standard}}{{join .Deps "\n" }}{{end}}' | \ 34 sort -u | grep -v '^C$' | \ 35 xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | \ 36 grep $prefix || true) 37 38 time make test PKG="$pkg" TESTFLAGS="-coverpkg=${coverpkg//$'\n'/,} -coverprofile=${coverage_dir}/${pkg//\//-}.cover -covermode=count" 39 done 40 41 # Merge coverage profiles and remove lines that match our ignore filter. 42 gocovmerge $coverage_dir/*.cover | \ 43 grep -vE "$prefix/(acceptance|cmd|ui/embedded|bench|.*\.pb(\.gw)?\.go)" > $coverage_profile 44 45 # Upload profiles to coveralls.io. 46 goveralls \ 47 -coverprofile=$coverage_profile \ 48 -service=teamcity \ 49 -repotoken="$COVERALLS_TOKEN" 50 51 # Upload profiles to codecov.io. Uses CODECOV_TOKEN. 52 bash <(curl -s https://codecov.io/bash) -f $coverage_profile