run_go_codecov.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. FILE_COVERAGE_INFO="go_coverage.txt"
  18. FILE_COVERAGE_HTML="go_coverage.html"
  19. BASEDIR=$(dirname "$0")
  20. source $BASEDIR/setenv.sh
  21. set -ex
  22. echo "mode: atomic" > ${FILE_COVERAGE_INFO}
  23. # run unittest
  24. echo "Running unittest under ./internal & ./pkg"
  25. TEST_CMD=$@
  26. if [ -z "$TEST_CMD" ]; then
  27. TEST_CMD="go test"
  28. fi
  29. # starting the timer
  30. beginTime=`date +%s`
  31. pushd cmd/tools
  32. $TEST_CMD -race -tags dynamic,test -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic ./...
  33. if [ -f profile.out ]; then
  34. grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ../${FILE_COVERAGE_INFO}
  35. rm profile.out
  36. fi
  37. popd
  38. for d in $(go list ./internal/... | grep -v -e vendor -e kafka -e planparserv2/generated -e mocks); do
  39. $TEST_CMD -race -tags dynamic,test -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
  40. if [ -f profile.out ]; then
  41. grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ${FILE_COVERAGE_INFO}
  42. rm profile.out
  43. fi
  44. done
  45. pushd pkg
  46. for d in $(go list ./... | grep -v -e vendor -e kafka -e planparserv2/generated -e mocks); do
  47. $TEST_CMD -race -tags dynamic,test -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
  48. if [ -f profile.out ]; then
  49. grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ../${FILE_COVERAGE_INFO}
  50. rm profile.out
  51. fi
  52. done
  53. popd
  54. # milvusclient
  55. pushd client
  56. for d in $(go list ./... | grep -v -e vendor -e kafka -e planparserv2/generated -e mocks); do
  57. $TEST_CMD -race -tags dynamic -v -coverpkg=./... -coverprofile=profile.out -covermode=atomic "$d"
  58. if [ -f profile.out ]; then
  59. grep -v kafka profile.out | grep -v planparserv2/generated | grep -v mocks | sed '1d' >> ../${FILE_COVERAGE_INFO}
  60. rm profile.out
  61. fi
  62. done
  63. popd
  64. endTime=`date +%s`
  65. echo "Total time for go unittest:" $(($endTime-$beginTime)) "s"
  66. # generate html report
  67. go tool cover -html=./${FILE_COVERAGE_INFO} -o ./${FILE_COVERAGE_HTML}
  68. echo "Generate go coverage report to ${FILE_COVERAGE_HTML}"