diff --git a/.github/workflows/server_workflows.yml b/.github/workflows/server_workflows.yml index db9b674..929bade 100644 --- a/.github/workflows/server_workflows.yml +++ b/.github/workflows/server_workflows.yml @@ -8,27 +8,36 @@ on: jobs: build-and-test: runs-on: ubuntu-22.04 + permissions: write-all 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: Report Code Coverage + uses: zgosalvez/github-actions-report-lcov@v4 + with: + 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 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 +) 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 ``` 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