From 80d7feb27628303f7885f0b52d76460984ab8933 Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 00:49:14 -0500 Subject: [PATCH 1/6] Add a coverage target --- CMakeLists.txt | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db322ac..9bc5860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,10 @@ find_package(Threads REQUIRED) # server library add_library(${LIBRARY} - src/HttpServer.cpp - include/HttpServer.h - include/AtomicQueue.h - include/constants.h + src/HttpServer.cpp + include/HttpServer.h + include/AtomicQueue.h + include/constants.h ) target_include_directories(${LIBRARY} PUBLIC include) target_compile_features(${LIBRARY} PRIVATE cxx_std_17) @@ -27,7 +27,7 @@ target_link_libraries(${LIBRARY} PRIVATE Threads::Threads) enable_testing() add_executable(${TEST_TARGET} test/HttpServerTest.cpp) target_link_libraries(${TEST_TARGET} - PRIVATE ${LIBRARY} GTest::gtest_main + PRIVATE ${LIBRARY} GTest::gtest_main ) include(GoogleTest) @@ -38,8 +38,21 @@ target_link_options(${TEST_TARGET} PRIVATE -O0 -g --coverage) # server implementation executable add_executable(${TARGET} - src/main.cpp + src/main.cpp ) target_compile_options(${TARGET} PRIVATE -g -O0 -g --coverage) target_link_options(${TARGET} PRIVATE -O0 -g --coverage) target_link_libraries(${TARGET} PRIVATE ${LIBRARY}) + +# coverage target +# find required tools +find_program(LCOV lcov REQUIRED) +find_program(GENHTML genhtml REQUIRED) + +# add coverage target +add_custom_target(coverage + # gather data + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles/server_library.dir/src + COMMAND ${LCOV} -c -d . -o coverage.info + COMMAND ${GENHTML} coverage.info -o out +) From 36604bc97e005edfaacaa33ed785a83df1f91fb5 Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 00:52:23 -0500 Subject: [PATCH 2/6] Add build and package steps to conanfile.py Automatically build and create target executables with "conan build ." --- conanfile.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index b89a080..b743c81 100644 --- a/conanfile.py +++ b/conanfile.py @@ -2,7 +2,7 @@ # To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements from conan import ConanFile -from conan.tools.cmake import cmake_layout, CMakeToolchain +from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain class ConanApplication(ConanFile): package_type = "application" @@ -20,4 +20,13 @@ def generate(self): def requirements(self): requirements = self.conan_data.get('requirements', []) for requirement in requirements: - self.requires(requirement) \ No newline at end of file + self.requires(requirement) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() \ No newline at end of file From 55c69fd28b254797aa42487dcd67b0b9f83bcdae Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 00:57:21 -0500 Subject: [PATCH 3/6] Simplify Conan setup workflow and implement code coverage --- .github/workflows/server_workflows.yml | 38 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/server_workflows.yml b/.github/workflows/server_workflows.yml index db9b674..08438b1 100644 --- a/.github/workflows/server_workflows.yml +++ b/.github/workflows/server_workflows.yml @@ -9,26 +9,34 @@ jobs: build-and-test: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Apt update + - name: Install required apt packages run: | sudo apt update - sudo apt install -y cmake + sudo apt install -y cmake lcov make - - name: Install Conan - run: pip3 install conan + - name: Setup Conan Client + uses: conan-io/setup-conan@v1 + with: + conan_audit_token: ${{ secrets.CONAN_AUDIT_TOKEN }} - - name: Configure Conan Packages - run: | - conan profile detect --force - conan install . --build=missing + - name: Install Conan dependencies + run: conan build . --build=missing - - name: CMake Configure - run: cmake -S . -B build/Release -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release + - name: Run GTest + run: ctest --test-dir build/Release - - name: CMake Build - run: cmake --build build/Release + - name: Coverage + shell: bash + run: | + cd build/Release + make coverage - - name: Run tests - run: ./build/Release/server_tests_bin \ No newline at end of file + - name: Coveralls + if: ${{ github.actor != 'nektos/act' }} + uses: coverallsapp/github-action@master + with: + path-to-lcov: build/Release/CMakeFiles/server_library.dir/src/coverage.info + github-token: ${{ secrets.GITHUB_TOKEN }} From 6ff059cec64a4ea4ab610cd230cb151cb8cf0500 Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 00:57:40 -0500 Subject: [PATCH 4/6] Simplify docs --- README.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fd27e2c..85bc863 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ ## Building the source code -### Building for Release mode +## Building for Release mode ```bash conan build . --build=missing -cmake -S . -B build/Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release - -# runs the underlying build system (Makefiles, VStudio solution files) -cmake --build build/Release ``` ## Command to run the HttpServer impl example @@ -18,22 +14,17 @@ cmake --build build/Release ## Command to run the Tests ```bash # run tests -./build/Release/server_test_bin +./build/Release/server_tests_bin ``` ## Generation of coverage reports ```bash -cmake --build build/Release \ -&& ctest \ -&& cd CMakeFiles/server_library.dir/src \ -&& gcov HttpServer.cpp.gcno \ -&& lcov -c -d . -o coverage.info \ -&& genhtml coverage.info -o out +make -C build/Release coverage ``` ### Open the coverage report ```bash # specific to Linux -xdg-open build/Debug/generators/CMakeFiles/server_library.dir/src/out/index.html +xdg-open build/Release/CMakeFiles/server_library.dir/src/out/index.html ``` From 8b9668d06cb2b8e5e9466d96099a8943012a891d Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 01:09:41 -0500 Subject: [PATCH 5/6] Add a github actions report lcov workflow --- .github/workflows/server_workflows.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/server_workflows.yml b/.github/workflows/server_workflows.yml index 08438b1..7d503e8 100644 --- a/.github/workflows/server_workflows.yml +++ b/.github/workflows/server_workflows.yml @@ -34,9 +34,9 @@ jobs: cd build/Release make coverage - - name: Coveralls - if: ${{ github.actor != 'nektos/act' }} - uses: coverallsapp/github-action@master + - name: Report Code Coverage + uses: zgosalvez/github-actions-report-lcov@v4 with: - path-to-lcov: build/Release/CMakeFiles/server_library.dir/src/coverage.info - github-token: ${{ secrets.GITHUB_TOKEN }} + coverage-files: build/Release/CMakeFiles/server_library.dir/src/coverage.info + artifact-name: code-coverage-report + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From e6b2d127c8316c3cda05c11f53456a1b614ccc9b Mon Sep 17 00:00:00 2001 From: James Yab Date: Fri, 12 Dec 2025 01:13:20 -0500 Subject: [PATCH 6/6] Add write-all permissions to workflows --- .github/workflows/server_workflows.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/server_workflows.yml b/.github/workflows/server_workflows.yml index 7d503e8..929bade 100644 --- a/.github/workflows/server_workflows.yml +++ b/.github/workflows/server_workflows.yml @@ -8,6 +8,7 @@ on: jobs: build-and-test: runs-on: ubuntu-22.04 + permissions: write-all steps: - name: Checkout code uses: actions/checkout@v4