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..dcc8474 --- /dev/null +++ b/.github/workflows/cpp-ci.yml @@ -0,0 +1,76 @@ +name: "C++ CI" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + code-quality: + name: "Code Quality" + runs-on: ubuntu-latest + 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 + + - name: "Run code quality checks" + run: ./scripts/code-quality.sh + + build-and-test: + name: "Build & Test" + runs-on: ubuntu-latest + needs: code-quality + 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 + + - 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 6b2d4b1..c6f4b1b 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' @@ -22,45 +22,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 } @@ -125,12 +137,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/src/httpp/parser/http_message_parser.hpp b/src/httpp/parser/http_message_parser.hpp index 227efb4..62c3ad1 100644 --- a/src/httpp/parser/http_message_parser.hpp +++ b/src/httpp/parser/http_message_parser.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ class HttpMessageParser { protected: HttpMessageParser() = default; - static constexpr std::string CRLF = "\r\n"; + static constexpr std::string_view CRLF = "\r\n"; static constexpr size_t MAX_START_LINE_SIZE = 8192; /* Current state of the parser. */