diff --git a/.clang-tidy b/.clang-tidy index 730a5b0..5901b3c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ Checks: > clang-diagnostic-*, clang-analyzer-*, + -clang-analyzer-optin.*, # Catch2 bugprone-*, modernize-*, performance-*, diff --git a/.github/workflows/cpp-ci.yml b/.github/workflows/cpp-ci.yml new file mode 100644 index 0000000..4aa69a4 --- /dev/null +++ b/.github/workflows/cpp-ci.yml @@ -0,0 +1,84 @@ +name: "C++ CI" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + code-quality: + name: "Code Quality (${{ matrix.backend }})" + runs-on: ubuntu-latest + strategy: + matrix: + backend: [epoll, select] + steps: + - name: "Checkout" + uses: actions/checkout@v4 + with: + submodules: true + + - name: "Add LLVM repository" + run: | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + sudo add-apt-repository -y "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main" + + - name: "Install dependencies" + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: cmake ninja-build clang-18 clang-tidy-18 clang-format-18 + version: 1.0 + + - name: "Configure CMake" + run: | + cmake -B build \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DBACKEND=${{ matrix.backend }} + + - name: "Run code quality checks" + run: ./scripts/code-quality.sh + + build-and-test: + name: "Build & Test (${{ matrix.backend }})" + runs-on: ubuntu-latest + needs: code-quality + strategy: + matrix: + backend: [epoll, select] + steps: + - name: "Checkout" + uses: actions/checkout@v4 + with: + submodules: true + + - name: "Add LLVM repository" + run: | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + sudo add-apt-repository -y "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main" + + - name: "Install dependencies" + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: cmake ninja-build clang-18 + version: 1.0 + + - name: "Configure CMake" + run: | + cmake -B build \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_COMPILER=clang++-18 \ + -DBACKEND=${{ matrix.backend }} + + - name: "Build" + run: cmake --build build --parallel + + - name: "Run tests" + run: | + cd build + ctest --output-on-failure --parallel diff --git a/scripts/code-quality.sh b/scripts/code-quality.sh index c7b323d..75147fc 100755 --- a/scripts/code-quality.sh +++ b/scripts/code-quality.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This script performs code quality checks using clang-tidy, cppcheck, and clang-format. +# This script performs code quality checks using Clang-Format and Clang-Tidy. # Colors for output RED='\033[0;31m' @@ -23,45 +23,57 @@ SOURCE_FILES=$(find "${SOURCE_DIRS[@]}" -type f \( -name "*.cpp" -o -name "*.hpp # Logging functions pinfo() { echo -e "${GREEN}[INFO]${NO_COLOR} $1"; } -pwarn() { echo -e "${YELLOW}[WARN]${NO_COLOR} $1"; } -perr() { echo -e "${RED}[ERROR]${NO_COLOR} $1"; } +pwarn() { + if [[ -n "$GITHUB_ACTIONS" ]]; then + echo "::warning::$1" + else + echo -e "${YELLOW}[WARN]${NO_COLOR} $1" + fi +} +perr() { + if [[ -n "$GITHUB_ACTIONS" ]]; then + echo "::error::$1" + else + echo -e "${RED}[ERROR]${NO_COLOR} $1" + fi +} -# clang-tidy +# Clang-Tidy run_clang_tidy() { - pinfo "Running clang-tidy static analysis..." + pinfo "Running Clang-Tidy analysis..." - if ! command -v clang-tidy &>/dev/null; then - pwarn "clang-tidy not found, skipping..." + if ! command -v run-clang-tidy-18 &>/dev/null; then + pwarn "Clang-Tidy not found" return 0 fi if [[ ! -f "${BUILD_DIR}/compile_commands.json" ]]; then - pwarn "compile_commands.json not found in ${BUILD_DIR}, skipping..." + pwarn "No compile_commands.json found in ${BUILD_DIR}" return 0 fi - if echo "$SOURCE_FILES" | xargs clang-tidy -p "${BUILD_DIR}"; then - pinfo "clang-tidy completed successfully" + if echo "$SOURCE_FILES" | xargs run-clang-tidy-18 -p "${BUILD_DIR}" -quiet; then + pinfo "Clang-Tidy check passed" else - perr "clang-tidy found issues" + perr "Clang-Tidy found linting issues" return 1 fi } -# clang-format +# Clang-Format run_clang_format() { - pinfo "Running clang-format check..." + pinfo "Running Clang-Format check..." - if ! command -v clang-format &>/dev/null; then - pwarn "clang-format not found, skipping..." + if ! command -v clang-format-18 &>/dev/null; then + pwarn "Clang-Format not found" return 0 fi - if echo "$SOURCE_FILES" | xargs clang-format --dry-run --Werror; then - pinfo "clang-format check completed successfully" + if echo "$SOURCE_FILES" | xargs clang-format-18 --dry-run --Werror; then + pinfo "Clang-Format check passed" else - perr "clang-format found formatting issues" - return 1 + pwarn "Clang-Format found formatting issues" + return 0 fi } @@ -69,7 +81,7 @@ run_clang_format() { show_usage() { echo "Usage: $0 [OPTIONS]" echo "" - echo "By default, runs all code quality checks (clang-tidy, cppcheck, clang-format)." + echo "By default, runs all code quality checks (clang-tidy, clang-format)." echo "" echo "Options:" echo " -h, --help Show this help message" @@ -126,12 +138,6 @@ main() { [[ $run_tidy == true ]] && { run_clang_tidy || exit_code=1; } [[ $run_format == true ]] && { run_clang_format || exit_code=1; } - if [[ $exit_code -eq 0 ]]; then - pinfo "All code quality checks passed!" - else - perr "Some code quality checks failed." - fi - exit $exit_code } diff --git a/tests/test_event_loop.cpp b/tests/test_event_loop.cpp index 8f2b15d..55d2bc0 100644 --- a/tests/test_event_loop.cpp +++ b/tests/test_event_loop.cpp @@ -1,4 +1,3 @@ -#include #include #include