Skip to content

Commit

Permalink
ci: add more checks (#40)
Browse files Browse the repository at this point in the history
* ci: add more checks
* ci: add clang-tidy workflow
* style: fix clang-tidy warnings
  • Loading branch information
sjinks authored Nov 16, 2024
1 parent 0c3de5f commit f54f23e
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 11 deletions.
75 changes: 66 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,70 @@ permissions:
contents: read

jobs:
build:
name: Build and Test
prepare:
name: Prepare list of configurations
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
presets: ${{ steps.set-matrix.outputs.presets }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
github.com:443
- name: Check out the source code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set matrix
id: set-matrix
run: echo presets="$(jq '.configurePresets[] | select(.hidden == false) | {name, description}' CMakePresets.json | jq --slurp -c .)" >> "${GITHUB_OUTPUT}"

build:
needs: prepare
name: Build and Test (${{ matrix.preset.description }})
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
preset: ${{ fromJson(needs.prepare.outputs.presets) }}
permissions:
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
azure.archive.ubuntu.com:80
esm.ubuntu.com:443
github.com:443
motd.ubuntu.com:443
objects.githubusercontent.com:443
packages.microsoft.com:443
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Build and test
run: |
cmake --preset ${{ matrix.preset.name }}
cmake --build --preset ${{ matrix.preset.name }} -j $(nproc)
ctest --preset ${{ matrix.preset.name }}
smoke:
name: Smoke test
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
Expand All @@ -27,6 +88,7 @@ jobs:
esm.ubuntu.com:443
github.com:443
motd.ubuntu.com:443
objects.githubusercontent.com:443
packages.microsoft.com:443
- name: Check out code
Expand All @@ -35,16 +97,11 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Build
- name: Build and install
run: |
cmake -B build
cmake --build build
- name: Test
run: ctest --test-dir build

- name: Install
run: sudo cmake --install build
sudo cmake --install build
- name: Smoke test
run: |
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: clang-tidy

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
clang-tidy:
name: Run clang-tidy
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
azure.archive.ubuntu.com:80
esm.ubuntu.com:443
github.com:443
motd.ubuntu.com:443
objects.githubusercontent.com:443
packages.microsoft.com:443
- name: Check out the source code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Configure
run: cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: Run clang-tidy
run: clang-tidy -p build $(jq -r '.[].file' build/compile_commands.json) --warnings-as-errors='*'
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,42 @@ project(
)
set(CMAKE_VERBOSE_MAKEFILE ON)

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(WITH_TESTING "Whether to enable tests" ON)
option(INSTALL_SYSLOG_EXPORTER "Whether to install the syslog exporter" ON)
option(ENABLE_MAINTAINER_MODE "Enable maintainer mode" OFF)

if(CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES "Coverage" "ASAN" "LSAN" "TSAN" "UBSAN")
endif()

string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
string(TOLOWER "${CMAKE_CONFIGURATION_TYPES}" CMAKE_CONFIGURATION_TYPES_LOWER)

string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_CXX_COMPILER_ID}")
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_CXX_COMPILER_ID}")

if(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS_ASAN "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(CMAKE_CXX_FLAGS_TSAN "-O1 -g -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_LSAN "-O1 -g -fsanitize=leak -fno-omit-frame-pointer -fno-optimize-sibling-calls")

if(CMAKE_COMPILER_IS_GNU)
set(CMAKE_CXX_FLAGS_COVERAGE "-Og -g --coverage -fprofile-abs-path")
set(CMAKE_CXX_FLAGS_UBSAN "-O1 -g -fsanitize=undefined -fsanitize=float-divide-by-zero -fno-omit-frame-pointer")
elseif(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS_COVERAGE "-O1 -g --coverage")
set(CMAKE_CXX_FLAGS_UBSAN "-O1 -g -fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=integer -fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability -fno-omit-frame-pointer")
endif()
endif()

if(ENABLE_MAINTAINER_MODE)
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS_MM -Weverything -Werror -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-missing-prototypes -Wno-padded -pedantic -Wno-global-constructors -Wno-exit-time-destructors)
elseif(CMAKE_COMPILER_IS_GNU)
set(CMAKE_CXX_FLAGS_MM -Wall -Wextra -Werror -pedantic)
endif()
endif()

include(FetchContent)

Expand Down
120 changes: 120 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,61 @@
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "mm-clang",
"description": "Maintainer mode build with clang",
"inherits": "base",
"hidden": false,
"cacheVariables": {
"ENABLE_MAINTAINER_MODE": "ON",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "mm-gcc",
"description": "Maintainer mode build with gcc",
"inherits": "base",
"hidden": false,
"cacheVariables": {
"ENABLE_MAINTAINER_MODE": "ON",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "debug-vcpkg",
"description": "Debug + vcpkg",
"inherits": "base-vcpkg",
"hidden": false
},
{
"name": "asan",
"description": "AddressSanitizer build",
"inherits": "base",
"hidden": false,
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "ASAN"
}
},
{
"name": "tsan",
"description": "ThreadSanitizer build",
"inherits": "base",
"hidden": false,
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "TSAN"
}
},
{
"name": "ubsan",
"description": "UndefinedBehaviorSanitizer build",
"inherits": "base",
"hidden": false,
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "UBSAN"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -78,12 +128,47 @@
"hidden": false,
"configurePreset": "release"
},
{
"name": "mm-clang",
"description": "Maintainer mode build with clang",
"inherits": "base",
"hidden": false,
"configurePreset": "mm-clang"
},
{
"name": "mm-gcc",
"description": "Maintainer mode build with gcc",
"inherits": "base",
"hidden": false,
"configurePreset": "mm-gcc"
},
{
"name": "debug-vcpkg",
"description": "Debug + vcpkg",
"inherits": "base",
"hidden": false,
"configurePreset": "debug-vcpkg"
},
{
"name": "asan",
"description": "AddressSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "asan"
},
{
"name": "tsan",
"description": "ThreadSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "tsan"
},
{
"name": "ubsan",
"description": "UndefinedBehaviorSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "ubsan"
}
],
"testPresets": [
Expand Down Expand Up @@ -116,12 +201,47 @@
"hidden": false,
"configurePreset": "release"
},
{
"name": "mm-clang",
"description": "Maintainer mode build with clang",
"inherits": "base",
"hidden": false,
"configurePreset": "mm-clang"
},
{
"name": "mm-gcc",
"description": "Maintainer mode build with gcc",
"inherits": "base",
"hidden": false,
"configurePreset": "mm-gcc"
},
{
"name": "debug-vcpkg",
"description": "Debug + vcpkg",
"inherits": "base",
"hidden": false,
"configurePreset": "debug-vcpkg"
},
{
"name": "asan",
"description": "AddressSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "asan"
},
{
"name": "tsan",
"description": "ThreadSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "tsan"
},
{
"name": "ubsan",
"description": "UndefinedBehaviorSanitizer build",
"inherits": "base",
"hidden": false,
"configurePreset": "ubsan"
}
]
}
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC OPENTELEMETRY_EXPORTER_SYSLOG_LOGS_STATIC_DEFINE)
endif()

if(ENABLE_MAINTAINER_MODE)
target_compile_options(${PROJECT_NAME} PRIVATE ${CMAKE_CXX_FLAGS_MM})
endif()

if(INSTALL_SYSLOG_EXPORTER)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
Expand Down
1 change: 1 addition & 0 deletions src/log_record_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace wwa::opentelemetry::exporter::logs {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::shared_ptr<SyslogInterface> SyslogLogRecordExporter::syslog{nullptr};

SyslogLogRecordExporter::SyslogLogRecordExporter(
Expand Down
1 change: 1 addition & 0 deletions src/log_record_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SyslogLogRecordExporter final : public ::opentelemetry::sdk::logs::LogReco

private:
std::atomic<bool> is_shutdown{false};
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static std::shared_ptr<SyslogInterface> syslog;

static void process_record(const Recordable* record);
Expand Down
2 changes: 1 addition & 1 deletion src/recordable.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Recordable final : public ::opentelemetry::sdk::logs::Recordable {

/**
* Set Resource of this log
* @param Resource the resource to set
* @param resource the resource to set
*/
void SetResource(const ::opentelemetry::sdk::resource::Resource& resource) noexcept override;

Expand Down
2 changes: 1 addition & 1 deletion test/test_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TEST_F(SyslogExporterTest, AdvancedTest)
const opentelemetry::nostd::string_view name = "somelib";
const opentelemetry::nostd::string_view version = "1.0";
const std::vector<opentelemetry::nostd::string_view> message{"Part 1", "Part 2"};
std::int64_t event_id = 12345;
const std::int64_t event_id = 12345;
const opentelemetry::nostd::string_view event_name = "event_name";

std::array<const std::uint8_t, opentelemetry::trace::TraceId::kSize> trace_id_raw = {
Expand Down

0 comments on commit f54f23e

Please sign in to comment.