submit_coverage.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. # Collect and submit coverage reports.
  3. #
  4. # Args:
  5. # $1: Flag(s) for codecov, separated by comma.
  6. set -e
  7. # Change to grandparent dir (POSIXly).
  8. CDPATH='' cd -P -- "$(dirname -- "$0")/../.." || exit
  9. echo "=== running submit_coverage in $PWD: $* ==="
  10. "$GCOV" --version
  11. # Download/install codecov-bash and gcovr once.
  12. codecov_sh="${TEMP:-/tmp}/codecov.bash"
  13. if ! [ -f "$codecov_sh" ]; then
  14. curl --retry 5 --silent --fail -o "$codecov_sh" https://codecov.io/bash
  15. chmod +x "$codecov_sh"
  16. python -m pip install --quiet --user gcovr
  17. fi
  18. (
  19. cd build
  20. python -m gcovr --branches --exclude-unreachable-branches --print-summary -j 2 --exclude '.*/auto/.*' --root .. --delete -o ../coverage.xml --xml
  21. )
  22. # Upload to codecov.
  23. # -X gcov: disable gcov, done manually above.
  24. # -X fix: disable fixing of reports (not necessary, rather slow)
  25. # -Z: exit non-zero on failure
  26. # -F: flag(s)
  27. # NOTE: ignoring flags for now, since this causes timeouts on codecov.io then,
  28. # which they know about for about a year already...
  29. # Flags must match pattern ^[\w\,]+$ ("," as separator).
  30. codecov_flags="$(uname -s),${1}"
  31. codecov_flags=$(echo "$codecov_flags" | sed 's/[^,_a-zA-Z0-9]/_/g')
  32. if ! "$codecov_sh" -f coverage.xml -X gcov -X fix -Z -F "${codecov_flags}"; then
  33. echo "codecov upload failed."
  34. fi
  35. # Cleanup always, especially collected data.
  36. find . \( -name '*.gcov' -o -name '*.gcda' \) -ls -delete | wc -l
  37. rm -f coverage.xml
  38. # Upload Lua coverage (generated manually on AppVeyor/Windows).
  39. if [ "$USE_LUACOV" = 1 ] && [ "$1" != "oldtest" ]; then
  40. if [ -x "${DEPS_BUILD_DIR}/usr/bin/luacov" ]; then
  41. "${DEPS_BUILD_DIR}/usr/bin/luacov"
  42. fi
  43. if ! "$codecov_sh" -f luacov.report.out -X gcov -X fix -Z -F "lua,${codecov_flags}"; then
  44. echo "codecov upload failed."
  45. fi
  46. rm luacov.stats.out
  47. fi