Skip to content

Commit

Permalink
[CI] Add a clang-tidy build (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
msiddhu authored Jul 17, 2024
1 parent baecbb9 commit aac2b77
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 39 deletions.
48 changes: 9 additions & 39 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Checks: >
-*,
performance-*,
portability-*,
abseil-*,
-abseil-string-find-str-contains,
bugprone-*,
Expand All @@ -13,7 +15,6 @@ Checks: >
-bugprone-unchecked-optional-access,
-bugprone-unhandled-exception-at-new,
-bugprone-unused-local-non-trivial-variable,
-bugprone-unused-return-value,
google-*,
-google-build-using-namespace,
-google-default-arguments,
Expand All @@ -29,41 +30,10 @@ Checks: >
-misc-non-private-member-variables-in-classes,
-misc-unused-alias-decls,
-misc-use-anonymous-namespace,
performance-*,
-performance-move-const-arg,
portability-*
# readability-*,
# -readability-convert-member-functions-to-static,
# -readability-else-after-return,
# -readability-function-cognitive-complexity,
# -readability-identifier-length,
# -readability-implicit-bool-conversion,
# -readability-isolate-declaration,
# -readability-magic-numbers,
# -readability-named-parameter,
# -readability-redundant-*,
# -readability-string-compare,
# cppcoreguidelines-*,
# -cppcoreguidelines-avoid-c-arrays,
# -cppcoreguidelines-avoid-magic-numbers,
# -cppcoreguidelines-init-variables,
# -cppcoreguidelines-macro-usage,
# -cppcoreguidelines-non-private-member-variables-in-classes,
# -cppcoreguidelines-pro-*,
# modernize-*,
# -modernize-use-default-member-init,
# -modernize-use-nodiscard,
# -modernize-use-trailing-return-type,
# -modernize-avoid-c-arrays,
# -modernize-use-using

# Use existing clang-format for formatting the code
# FormatStyle: 'file'

# TODO: include checks: readability, cppcoreguidelines, modernize , google-readability-namespace-comments, google-readability-avoid-underscore-in-googletest-name, performance-move-const-arg






cppcoreguidelines-*,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-pro-*
84 changes: 84 additions & 0 deletions .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: clang-tidy

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
clang-tidy:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Environment
env:
PROTOBUF_VERSION: '23.3'
ABSEIL_CPP_VERSION: '20230125.3'
CXX_STANDARD: '14'
run: |
sudo apt update -y
sudo apt install -y --no-install-recommends --no-install-suggests \
build-essential \
iwyu \
cmake \
libssl-dev \
libcurl4-openssl-dev \
libprotobuf-dev \
protobuf-compiler \
libgmock-dev \
libgtest-dev \
libbenchmark-dev
if ! command -v clang-tidy &> /dev/null; then
echo "clang-tidy could not be found"
exit 1
fi
echo "Using clang-tidy version: $(clang-tidy --version)"
echo "clang-tidy installed at: $(which clang-tidy)"
- name: Prepare CMake
env:
CC: clang
CXX: clang++
run: |
mkdir -p build && cd build
echo "Running cmake..."
cmake .. \
-DCMAKE_CXX_STANDARD=14 \
-DWITH_STL=CXX14 \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_EXAMPLES=ON \
-DWITH_EXAMPLES_HTTP=ON \
-DBUILD_W3CTRACECONTEXT_TEST=ON \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_CLANG_TIDY="clang-tidy"
- name: Run clang-tidy
run: |
cd build
make -j$(nproc) 2>&1 | tee -a clang-tidy.log || exit 1
- uses: actions/upload-artifact@v4
with:
name: Logs (clang-tidy)
path: ./build/clang-tidy.log

- name: Count warnings
run: |
cd build
COUNT=$(grep -c "warning:" clang-tidy.log)
echo "clang-tidy reported ${COUNT} warning(s)"
# TODO: include WITH_OTLP_GRPC and WITH_ABSEIL flags.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Increment the:

## [Unreleased]

* [CI] Add a clang-tidy build
[#3001](https://github.com/open-telemetry/opentelemetry-cpp/pull/3001)

## [1.16.1 2024-07-17]

* [BUILD] Add bazel missing BUILD file
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ if(WITH_PROMETHEUS)
message(STATUS "Trying to use local prometheus-cpp from submodule")
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
set(ENABLE_TESTING OFF)
set(CMAKE_CXX_CLANG_TIDY "")
add_subdirectory(third_party/prometheus-cpp)
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
else()
message(
FATAL_ERROR
Expand Down Expand Up @@ -444,7 +447,10 @@ if(WITH_OTLP_GRPC
include(CMakeDependentOption)

message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}")
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
set(CMAKE_CXX_CLANG_TIDY "")
include(cmake/opentelemetry-proto.cmake)
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
endif()

#
Expand Down

1 comment on commit aac2b77

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: aac2b77 Previous: baecbb9 Ratio
BM_ProcYieldSpinLockThrashing/2/process_time/real_time 0.7614453379719403 ms/iter 0.2012429162753934 ms/iter 3.78
BM_ProcYieldSpinLockThrashing/4/process_time/real_time 1.7524690770391207 ms/iter 0.6078500596303789 ms/iter 2.88
BM_NaiveSpinLockThrashing/2/process_time/real_time 0.6547290009337586 ms/iter 0.21916308434180964 ms/iter 2.99
BM_NaiveSpinLockThrashing/4/process_time/real_time 2.387300614387758 ms/iter 0.7295628224522615 ms/iter 3.27

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.