coverity-scan.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. # Coverity scan script
  3. #
  4. # To run this script you need to provide API token. This can be done either by:
  5. # - Putting token in ".coverity-token" file
  6. # - Assigning token value to COVERITY_SCAN_TOKEN environment variable
  7. #
  8. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  9. #
  10. # Author : Costa Tsaousis (costa@netdata.cloud)
  11. # Author : Pawel Krupa (paulfantom)
  12. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  13. cpus=$(grep -c ^processor </proc/cpuinfo)
  14. [ -z "${cpus}" ] && cpus=1
  15. token="${COVERITY_SCAN_TOKEN}"
  16. ([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
  17. if [ -z "${token}" ]; then
  18. echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN."
  19. exit 1
  20. fi
  21. export PATH=${PATH}:/opt/coverity/bin/
  22. covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
  23. ([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
  24. if [ -z "${covbuild}" ]; then
  25. echo >&2 "Cannot find 'cov-build' binary in \$PATH."
  26. exit 1
  27. elif [ ! -x "${covbuild}" ]; then
  28. echo >&2 "The command ${covbuild} is not executable. Save command the full filename of cov-build in .coverity-build"
  29. exit 1
  30. fi
  31. version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
  32. echo >&2 "Working on netdata version: ${version}"
  33. echo >&2 "Cleaning up old builds..."
  34. make clean || echo >&2 "Nothing to clean"
  35. [ -d "cov-int" ] && rm -rf "cov-int"
  36. [ -f netdata-coverity-analysis.tgz ] && rm netdata-coverity-analysis.tgz
  37. autoreconf -ivf
  38. ./configure --enable-plugin-nfacct --enable-plugin-freeipmi
  39. "${covbuild}" --dir cov-int make -j${cpus} || exit 1
  40. echo >&2 "Compressing data..."
  41. tar czvf netdata-coverity-analysis.tgz cov-int || exit 1
  42. echo >&2 "Sending analysis for version ${version} ..."
  43. COVERITY_SUBMIT_RESULT=$(curl --progress-bar --form token="${token}" \
  44. --form email=${COVERITY_SCAN_SUBMIT_MAIL} \
  45. --form file=@netdata-coverity-analysis.tgz \
  46. --form version="${version}" \
  47. --form description="netdata, real-time performance monitoring, done right." \
  48. https://scan.coverity.com/builds?project=${REPOSITORY})
  49. echo ${COVERITY_SUBMIT_RESULT} | grep -q -e 'Build successfully submitted' || echo >&2 "scan results were not pushed to coverity. Message was: ${COVERITY_SUBMIT_RESULT}"
  50. echo >&2 "Coverity scan mechanism completed"