coverall.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env 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 v2ray | 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. for DIR in $(find ./* -type d ! -path "*.git*"); do
  18. TEST_FILES=("$DIR"/*_test.go)
  19. if [ -f "${TEST_FILES[0]}" ]; then
  20. test_package "/$DIR"
  21. fi
  22. done
  23. # merge out
  24. while IFS= read -r -d '' OUT_FILE
  25. do
  26. echo "Merging file ${OUT_FILE}"
  27. < "${OUT_FILE}" grep -v "mode: set" >> "$COVERAGE_FILE"
  28. done < <(find ./* -name "*.out" -print0)
  29. < "$COVERAGE_FILE" sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" > "$COV_SORTED"
  30. echo "mode: set" | cat - "${COV_SORTED}" > "${COVERAGE_FILE}"
  31. bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'