coverall 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. FAIL=0
  3. XRAY_OUT=${PWD}/out/xray
  4. export XRAY_COV=${XRAY_OUT}/cov
  5. COVERAGE_FILE=${XRAY_COV}/coverage.txt
  6. function test_package {
  7. DIR=".$1"
  8. DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep xray | tr '\n' ',')
  9. DEP=${DEP}$DIR
  10. RND_NAME=$(openssl rand -hex 16)
  11. COV_PROFILE=${XRAY_COV}/${RND_NAME}.out
  12. go test -tags "json coverage" -coverprofile=${COV_PROFILE} -coverpkg=$DEP $DIR || FAIL=1
  13. }
  14. rm -rf ${XRAY_OUT}
  15. mkdir -p ${XRAY_COV}
  16. touch ${COVERAGE_FILE}
  17. TEST_FILES=(./*_test.go)
  18. if [ -f ${TEST_FILES[0]} ]; then
  19. test_package ""
  20. fi
  21. for DIR in $(find * -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do
  22. TEST_FILES=($DIR/*_test.go)
  23. if [ -f ${TEST_FILES[0]} ]; then
  24. test_package "/$DIR"
  25. fi
  26. done
  27. for OUT_FILE in $(find ${XRAY_COV} -name "*.out"); do
  28. echo "Merging file ${OUT_FILE}"
  29. cat ${OUT_FILE} | grep -v "mode: set" >> ${COVERAGE_FILE}
  30. done
  31. COV_SORTED=${XRAY_COV}/coverallsorted.out
  32. cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > ${COV_SORTED}
  33. echo "mode: set" | cat - ${COV_SORTED} > ${COVERAGE_FILE}
  34. if [ "$FAIL" -eq 0 ]; then
  35. echo "Uploading coverage datea to codecov."
  36. #bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} -v || echo "Codecov did not collect coverage reports."
  37. fi
  38. exit $FAIL