cppcheck.yml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. name: cppcheck
  2. on:
  3. push:
  4. branches: [ main ]
  5. pull_request:
  6. branches: [ main ]
  7. permissions:
  8. contents: read
  9. jobs:
  10. cppcheck:
  11. runs-on: ubuntu-24.04
  12. steps:
  13. - name: Harden the runner (Audit all outbound calls)
  14. uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
  15. with:
  16. egress-policy: audit
  17. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  18. with:
  19. submodules: 'recursive'
  20. - name: Set up dependencies
  21. run: |
  22. sudo apt update -y
  23. sudo apt install -y cppcheck
  24. - name: Run cppcheck
  25. run: |
  26. cppcheck --version | tee cppcheck.log
  27. cppcheck \
  28. --force \
  29. --enable=warning,performance,portability \
  30. --inline-suppr \
  31. --suppress=unknownMacro:exporters/etw/include/opentelemetry/exporters/etw/TraceLoggingDynamic.h \
  32. --language=c++ \
  33. --std=c++14 \
  34. -I api/include \
  35. -I exporters/elasticsearch/include \
  36. -I exporters/etw/include \
  37. -I exporters/memory/include \
  38. -I exporters/ostream/include \
  39. -I exporters/otlp/include \
  40. -I exporters/prometheus/include \
  41. -I exporters/zipkin/include \
  42. -I ext/include \
  43. -I opentracing-shim/include \
  44. -I sdk/include \
  45. -i build \
  46. -i test \
  47. -i third_party \
  48. -j $(nproc) \
  49. . 2>&1 | tee --append cppcheck.log
  50. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  51. if: success() || failure()
  52. with:
  53. name: Logs (cppcheck)
  54. path: ./cppcheck.log
  55. - name: Count warnings
  56. run: |
  57. set +e
  58. readonly WARNING_COUNT=`grep -c -E "\[.+\]" cppcheck.log`
  59. echo "cppcheck reported ${WARNING_COUNT} warning(s)"
  60. # Acceptable limit, to decrease over time down to 0
  61. readonly WARNING_LIMIT=10
  62. # FAIL the build if WARNING_COUNT > WARNING_LIMIT
  63. if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then
  64. exit 1
  65. # WARN in annotations if WARNING_COUNT > 0
  66. elif [ $WARNING_COUNT -gt 0 ] ; then
  67. echo "::warning::cppcheck reported ${WARNING_COUNT} warning(s)"
  68. fi