Skip to content

Commit 4561fc2

Browse files
authored
[CI] Increase code coverage of iwyu and clang-tidy ci jobs (#3469)
1 parent 7a68bb3 commit 4561fc2

13 files changed

+183
-57
lines changed

.github/workflows/clang-tidy.yaml

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ permissions:
1111

1212
jobs:
1313
clang-tidy:
14-
runs-on: ubuntu-24.04
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- cmake_options: all-options-abiv1-preview
20+
warning_limit: 215
21+
- cmake_options: all-options-abiv2-preview
22+
warning_limit: 216
1523
steps:
1624
- name: Harden the runner (Audit all outbound calls)
1725
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
@@ -23,19 +31,20 @@ jobs:
2331
submodules: recursive
2432

2533
- name: Setup Environment
26-
env:
27-
PROTOBUF_VERSION: '23.3'
28-
ABSEIL_CPP_VERSION: '20230125.3'
29-
CXX_STANDARD: '14'
3034
run: |
3135
sudo apt update -y
3236
sudo apt install -y --no-install-recommends --no-install-suggests \
3337
build-essential \
3438
cmake \
39+
zlib1g-dev \
3540
libssl-dev \
3641
libcurl4-openssl-dev \
42+
nlohmann-json3-dev \
43+
libabsl-dev \
3744
libprotobuf-dev \
45+
libgrpc++-dev \
3846
protobuf-compiler \
47+
protobuf-compiler-grpc \
3948
libgmock-dev \
4049
libgtest-dev \
4150
libbenchmark-dev
@@ -47,42 +56,43 @@ jobs:
4756
echo "Using clang-tidy version: $(clang-tidy --version)"
4857
echo "clang-tidy installed at: $(which clang-tidy)"
4958
50-
5159
- name: Prepare CMake
5260
env:
5361
CC: clang
5462
CXX: clang++
5563
run: |
5664
echo "Running cmake..."
57-
cmake -B build \
65+
cmake -B build-${{ matrix.cmake_options }} \
66+
-C ./test_common/cmake/${{ matrix.cmake_options }}.cmake \
5867
-DCMAKE_CXX_STANDARD=14 \
5968
-DWITH_STL=CXX14 \
60-
-DWITH_OTLP_HTTP=ON \
61-
-DWITH_OTLP_FILE=ON \
62-
-DWITH_PROMETHEUS=ON \
63-
-DWITH_ZIPKIN=ON \
64-
-DWITH_ELASTICSEARCH=ON \
65-
-DWITH_OTLP_HTTP_COMPRESSION=ON \
66-
-DWITH_EXAMPLES=ON \
67-
-DWITH_EXAMPLES_HTTP=ON \
68-
-DBUILD_W3CTRACECONTEXT_TEST=ON \
69-
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
70-
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
71-
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
69+
-DWITH_OPENTRACING=OFF \
70+
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \
71+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
72+
-DCMAKE_CXX_CLANG_TIDY="clang-tidy;--quiet;-p;build-${{ matrix.cmake_options }}"
7273
7374
- name: Run clang-tidy
7475
run: |
75-
cmake --build build --target opentelemetry_proto
76-
jq -r .[].file build/compile_commands.json | grep -vE '/(generated|third_party)/' | xargs -P $(nproc) -n 1 clang-tidy --quiet -p build 2>&1 | tee -a clang-tidy.log
76+
cmake --build build-${{ matrix.cmake_options }} -- -j$(nproc) 2>&1 | tee clang-tidy-${{ matrix.cmake_options }}.log
7777
7878
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7979
with:
80-
name: Logs (clang-tidy)
81-
path: ./clang-tidy.log
80+
name: Logs-clang-tidy-${{ matrix.cmake_options }}
81+
path: ./clang-tidy-${{ matrix.cmake_options }}.log
8282

8383
- name: Count warnings
8484
run: |
85-
COUNT=$(grep -c "warning:" clang-tidy.log)
86-
echo "clang-tidy reported ${COUNT} warning(s)"
85+
COUNT=$(grep -c "warning:" clang-tidy-${{ matrix.cmake_options }}.log)
86+
echo "clang-tidy reported ${COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'"
87+
88+
readonly WARNING_LIMIT=${{ matrix.warning_limit }}
89+
90+
# FAIL the build if COUNT > WARNING_LIMIT
91+
if [ $COUNT -gt $WARNING_LIMIT ] ; then
92+
echo "clang-tidy reported ${COUNT} warning(s) exceeding the existing warning limit of ${WARNING_LIMIT} with cmake options preset '${{ matrix.cmake_options }}'"
93+
exit 1
94+
# WARN in annotations if COUNT > 0
95+
elif [ $COUNT -gt 0 ] ; then
96+
echo "::warning::clang-tidy reported ${COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'"
97+
fi
8798
88-
# TODO: include WITH_OTLP_GRPC flags.

.github/workflows/iwyu.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ permissions:
1313
jobs:
1414
iwyu:
1515
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- cmake_options: all-options-abiv1
21+
warning_limit: 5
22+
- cmake_options: all-options-abiv1-preview
23+
warning_limit: 28
24+
- cmake_options: all-options-abiv2-preview
25+
warning_limit: 48
26+
1627
steps:
1728
- name: Harden the runner (Audit all outbound calls)
1829
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
@@ -46,52 +57,42 @@ jobs:
4657
run: |
4758
sudo ./ci/install_iwyu.sh
4859
- name: Prepare CMake
60+
env:
61+
CC: clang
62+
CXX: clang++
4963
run: |
5064
TOPDIR=`pwd`
51-
mkdir build && cd build
52-
CC="clang" CXX="clang++" cmake \
65+
cmake -B build-${{ matrix.cmake_options }} \
66+
-C ./test_common/cmake/${{ matrix.cmake_options }}.cmake \
5367
-DCMAKE_CXX_STANDARD=14 \
5468
-DWITH_STL=CXX14 \
55-
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \
56-
-DBUILD_TESTING=ON \
57-
-DWITH_EXAMPLES=ON \
58-
-DWITH_EXAMPLES_HTTP=ON \
59-
-DBUILD_W3CTRACECONTEXT_TEST=ON \
60-
-DWITH_OTLP_GRPC=ON \
61-
-DWITH_OTLP_HTTP=ON \
62-
-DWITH_OTLP_FILE=ON \
63-
-DWITH_OPENTRACING=ON \
64-
-DWITH_OTLP_HTTP_COMPRESSION=ON \
65-
-DWITH_THREAD_INSTRUMENTATION=ON \
66-
-DWITH_ZIPKIN=ON \
67-
-DWITH_PROMETHEUS=ON \
68-
..
69+
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \
70+
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;"
6971
7072
- name: iwyu_tool
7173
run: |
72-
cd build
73-
make -k 2>&1 | tee -a iwyu.log
74+
cmake --build build-${{ matrix.cmake_options }} -- -j$(nproc) -k 2>&1 | tee -a iwyu-${{ matrix.cmake_options }}.log
7475
7576
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7677
if: success() || failure()
7778
with:
78-
name: Logs (include-what-you-use)
79-
path: ./build/*.log
79+
name: Logs-iwyu-${{ matrix.cmake_options }}
80+
path: ./iwyu-${{ matrix.cmake_options }}.log
8081

8182
- name: count warnings
8283
run: |
8384
set +e
8485
echo "include-what-you-use version:"
8586
include-what-you-use --version
86-
cd build
87-
readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu.log`
88-
echo "include-what-you-use reported ${WARNING_COUNT} warning(s)"
87+
readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu-${{ matrix.cmake_options }}.log`
88+
echo "include-what-you-use reported ${WARNING_COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'"
8989
# Acceptable limit, to decrease over time down to 0
90-
readonly WARNING_LIMIT=0
90+
readonly WARNING_LIMIT=${{ matrix.warning_limit }}
9191
# FAIL the build if WARNING_COUNT > WARNING_LIMIT
9292
if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then
93+
echo "include-what-you-use reported ${WARNING_COUNT} warning(s) exceeding the existing warning limit of ${WARNING_LIMIT} with cmake options preset '${{ matrix.cmake_options }}'"
9394
exit 1
9495
# WARN in annotations if WARNING_COUNT > 0
9596
elif [ $WARNING_COUNT -gt 0 ] ; then
96-
echo "::warning::include-what-you-use reported ${WARNING_COUNT} warning(s)"
97+
echo "::warning::include-what-you-use reported ${WARNING_COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'"
9798
fi

cmake/opentelemetry-proto.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ target_include_directories(
318318
PUBLIC "$<BUILD_INTERFACE:${GENERATED_PROTOBUF_PATH}>"
319319
"$<INSTALL_INTERFACE:include>")
320320

321-
# Disable include-what-you-use on generated code.
321+
# Disable include-what-you-use and clang-tidy on generated code.
322322
set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE
323-
"")
323+
"" CXX_CLANG_TIDY "")
324324
if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf)
325325
get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf
326326
INTERFACE_INCLUDE_DIRECTORIES)
@@ -338,9 +338,9 @@ if(WITH_OTLP_GRPC)
338338
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})
339339
set_target_version(opentelemetry_proto_grpc)
340340

341-
# Disable include-what-you-use on generated code.
341+
# Disable include-what-you-use and clang-tidy on generated code.
342342
set_target_properties(opentelemetry_proto_grpc
343-
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
343+
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "")
344344

345345
list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
346346
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)

examples/grpc/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ add_custom_command(
4141
add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
4242
${example_proto_srcs} ${example_proto_hdrs})
4343

44-
# Disable include-what-you-use on generated code.
45-
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
44+
# Disable include-what-you-use and clang-tidy on generated code.
45+
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
46+
CXX_CLANG_TIDY "")
4647

4748
target_include_directories(
4849
example_grpc_proto PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable all options with ABI V1 including preview features
5+
6+
set(WITH_ABI_VERSION_1 ON CACHE BOOL "" FORCE)
7+
set(WITH_ABI_VERSION_2 OFF CACHE BOOL "" FORCE)
8+
9+
set(ENABLE_PREVIEW ON)
10+
include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable all options with ABI V1 except preview features
5+
6+
set(WITH_ABI_VERSION_1 ON CACHE BOOL "" FORCE)
7+
set(WITH_ABI_VERSION_2 OFF CACHE BOOL "" FORCE)
8+
9+
set(ENABLE_PREVIEW OFF)
10+
include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable all options with ABI V2 including preview features
5+
6+
set(WITH_ABI_VERSION_1 OFF CACHE BOOL "" FORCE)
7+
set(WITH_ABI_VERSION_2 ON CACHE BOOL "" FORCE)
8+
9+
set(ENABLE_PREVIEW ON)
10+
include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable all options with ABI V2 except preview features
5+
6+
set(WITH_ABI_VERSION_1 OFF CACHE BOOL "" FORCE)
7+
set(WITH_ABI_VERSION_2 ON CACHE BOOL "" FORCE)
8+
9+
set(ENABLE_PREVIEW OFF)
10+
include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake)

test_common/cmake/all-options.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# All options for the opentelemetry-cpp project.
5+
6+
include(${CMAKE_CURRENT_LIST_DIR}/component-options.cmake)
7+
include(${CMAKE_CURRENT_LIST_DIR}/example-options.cmake)
8+
include(${CMAKE_CURRENT_LIST_DIR}/testing-options.cmake)
9+
include(${CMAKE_CURRENT_LIST_DIR}/preview-options.cmake)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# All components options
5+
6+
if(NOT DEFINED ENABLE_COMPONENTS)
7+
set(ENABLE_COMPONENTS ON)
8+
endif()
9+
10+
set(WITH_OTLP_GRPC ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
11+
set(WITH_OTLP_HTTP ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
12+
set(WITH_OTLP_FILE ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
13+
14+
set(WITH_PROMETHEUS ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
15+
set(WITH_ZIPKIN ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
16+
set(WITH_ELASTICSEARCH ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
17+
18+
if(WIN32)
19+
set(WITH_ETW ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
20+
endif()
21+
22+
if(WITH_ABI_VERSION_1)
23+
set(WITH_OPENTRACING ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE)
24+
endif()

0 commit comments

Comments
 (0)