coverall2 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. COVERAGE_FILE=${PWD}/coverage.txt
  3. COV_SORTED=${PWD}/coverallsorted.out
  4. touch "$COVERAGE_FILE"
  5. function test_package {
  6. DIR=".$1"
  7. DEP=$(go list -f '{{ join .Deps "\n" }}' "$DIR" | grep xray | tr '\n' ',')
  8. DEP=${DEP}$DIR
  9. RND_NAME=$(openssl rand -hex 16)
  10. COV_PROFILE=${RND_NAME}.out
  11. go test -coverprofile="$COV_PROFILE" -coverpkg="$DEP" "$DIR" || return
  12. }
  13. TEST_FILES=(./*_test.go)
  14. if [ -f "${TEST_FILES[0]}" ]; then
  15. test_package ""
  16. fi
  17. # shellcheck disable=SC2044
  18. for DIR in $(find ./* -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do
  19. TEST_FILES=("$DIR"/*_test.go)
  20. if [ -f "${TEST_FILES[0]}" ]; then
  21. test_package "/$DIR"
  22. fi
  23. done
  24. # merge out
  25. while IFS= read -r -d '' OUT_FILE
  26. do
  27. echo "Merging file ${OUT_FILE}"
  28. < "${OUT_FILE}" grep -v "mode: set" >> "$COVERAGE_FILE"
  29. done < <(find ./* -name "*.out" -print0)
  30. < "$COVERAGE_FILE" sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > "$COV_SORTED"
  31. echo "mode: set" | cat - "${COV_SORTED}" > "${COVERAGE_FILE}"
  32. bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'