Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Checks: >
clang-diagnostic-*,
clang-analyzer-*,
-clang-analyzer-optin.*, # Catch2
bugprone-*,
modernize-*,
performance-*,
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/cpp-ci.yml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 32 additions & 26 deletions scripts/code-quality.sh
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -23,53 +23,65 @@ 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
}

# Show usage information
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"
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion tests/test_event_loop.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <sys/socket.h>
#include <unistd.h>

#include <array>
Expand Down
Loading