Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add a clang-tidy build #3001

Merged
merged 32 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
091efdd
Added the CI for clang-tidy in github workflows.
msiddhu Jul 11, 2024
aeaa2be
testing
msiddhu Jul 11, 2024
337b105
testing
msiddhu Jul 11, 2024
ac8ac31
Added the CI for clang-tidy in github workflows.
msiddhu Jul 11, 2024
883598c
Added the CI for clang-tidy in github workflows.
msiddhu Jul 11, 2024
705af4f
Added the CI for clang-tidy in github workflows.
msiddhu Jul 11, 2024
42a4c7e
Trying to run CI without sh file as .sh file is not present in main.
msiddhu Jul 11, 2024
304c066
Format and remove clang installation as ubuntu24 image has it.
msiddhu Jul 11, 2024
8e8bcbd
Delete install_clang18.sh as clang18 is already included in ubuntu24 …
msiddhu Jul 11, 2024
4546b1d
markdown fix
msiddhu Jul 11, 2024
834f934
markdown fix
msiddhu Jul 11, 2024
df852b2
remove dump config.
msiddhu Jul 11, 2024
5db5c69
Resolve some comments by maintainer.
msiddhu Jul 11, 2024
e610af4
Resolve some comments by maintainer.
msiddhu Jul 11, 2024
e4b0b40
Resolve some comments by maintainer.
msiddhu Jul 11, 2024
a89117e
testing
msiddhu Jul 11, 2024
9f00e4c
testing
msiddhu Jul 11, 2024
2a450d3
testing
msiddhu Jul 11, 2024
3042338
testing
msiddhu Jul 11, 2024
154b162
testing
msiddhu Jul 11, 2024
86e166a
Merge branch 'main' into ci_clang_tidy
msiddhu Jul 12, 2024
23c4e37
Change log rewrite
msiddhu Jul 14, 2024
2233338
Removed TOPDIR
msiddhu Jul 14, 2024
516ea26
Added back multithreading make
msiddhu Jul 15, 2024
5c540cf
changes regex to exclude the opentelemetry proto
msiddhu Jul 15, 2024
952d309
Negative regex with third party
msiddhu Jul 15, 2024
0d70409
Merge branch 'main' into ci_clang_tidy
msiddhu Jul 15, 2024
f3278f2
Made changes to cmake file to exclude clang-tidy to parse warnings fr…
msiddhu Jul 16, 2024
d04b21f
Fixed opentracing=ON flag.
msiddhu Jul 16, 2024
629fbdc
changed some configs
msiddhu Jul 16, 2024
d76751f
Added missing comma
msiddhu Jul 16, 2024
ba3a6d8
Merge branch 'main' into ci_clang_tidy
marcalff Jul 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_googletest.sh
sudo -E ./ci/install_abseil.sh
sudo -E ./ci/install_protobuf.sh
sudo -E ./ci/setup_grpc.sh -m -p protobuf -p abseil-cpp
marcalff marked this conversation as resolved.
Show resolved Hide resolved


# WITH_OPENTRACING_SHIM and WITH_ETW is not present and will be excluded.
- name: Prepare CMake
run: |
TOPDIR=$(pwd)
mkdir -p build && cd build
echo "Running cmake..."
CC="clang" CXX="clang++" cmake .. \
-DCMAKE_CXX_STANDARD=14 \
-DWITH_STL=CXX14 \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_ABSEIL=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 \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON
cd ..

- name: Run Clang-Tidy
run: |
chmod +x tools/clang-tidy.sh
marcalff marked this conversation as resolved.
Show resolved Hide resolved
./tools/clang-tidy.sh | tee clang-tidy-output.log

- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Logs (clang-tidy)
path: clang-tidy-output.log

- name: Count Warnings
run: |
COUNT=$(grep -c "warning:" clang-tidy-output.log)
echo "clang-tidy reported ${COUNT} warning(s)"
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] Added clang-tidy to the CI pipeline, which outputs
the number of warnings and generates a log file containing the
details of these warnings [#2051](https://github.com/open-telemetry/opentelemetry-cpp/issues/2051)
msiddhu marked this conversation as resolved.
Show resolved Hide resolved
* [SECURITY] Remove OTLP HTTP support for TLS 1.0 and TLS 1.1,
require TLS 1.2 or better
[#2721](https://github.com/open-telemetry/opentelemetry-cpp/pull/2721)
Expand Down
59 changes: 59 additions & 0 deletions tools/clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# Define the find command to exclude certain directories and find relevant files

# This command will exclude the following directories: same as format.sh but removing the opentelemetry-shim as well.
# - third_party
# - tools
# - .git
# - _deps
# - build
# - out
# - .vs
# - opentelemetry_logo.png
# - TraceLoggingDynamic.h:
# - opentelemetry-shim

FIND="find . -name third_party -prune -o -name opentracing-shim -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name build -prune -o -name out -prune -o -name .vs -prune -o -name opentelemetry_logo.png -prune -o -name TraceLoggingDynamic.h -prune -o -name '*.h' -o -name '*.cc' -print"
marcalff marked this conversation as resolved.
Show resolved Hide resolved

# Define the path to the compile_commands.json
COMPILE_COMMANDS_PATH="./build/compile_commands.json"

# Define the log file name
LOG_FILE="clang-tidy-output.log"


# Don't require this in the log file as the clang-tidy just want to go into system libraries and produce those warnings as well.
# This should be probably avioded with header-filter
FILTER_PATTERN="Suppressed [0-9]* warnings.*|Use -header-filter=.*|Use -system-headers.* | warnings generated."

# Check if the log file is empty or does not exist
rm -f $LOG_FILE

run_clang_tidy() {
file=$1
echo "Running clang-tidy on $file" >> $LOG_FILE
clang-tidy -p=$COMPILE_COMMANDS_PATH "$file" 2>&1 | grep -Ev "$FILTER_PATTERN" | tee -a $LOG_FILE
}

NUM_PROCESSORS=$(nproc)


export -f run_clang_tidy
export COMPILE_COMMANDS_PATH
export LOG_FILE
export FILTER_PATTERN

# Find all relevant files and store them in a variable
FILES=$(eval $FIND)
NUM_FILES=$(echo "$FILES" | wc -l)


echo "Number of processors available: $NUM_PROCESSORS"
echo "Number of files to process: $NUM_FILES"

# Run clang-tidy in parallel on each file found by the find command
echo "$FILES" | xargs -P $NUM_PROCESSORS -n 1 bash -c 'run_clang_tidy "$@"' _
Loading