diff --git a/.github/actions/install/gcovr/action.yml b/.github/actions/install/gcovr/action.yml new file mode 100644 index 000000000..f4ab5ce8f --- /dev/null +++ b/.github/actions/install/gcovr/action.yml @@ -0,0 +1,22 @@ +name: Install gcovr +description: Install gcovr for generating coverage reports + +inputs: + version: + description: gcovr version to install + required: false + default: "8.3" # pick the latest stable version + +runs: + using: composite + steps: + - name: Install Python and pip + run: | + sudo apt-get install -y python3 python3-pip + shell: bash + + - name: Install gcovr + run: | + python3 -m pip install --upgrade pip + python3 -m pip install gcovr==${{ inputs.version }} + shell: bash diff --git a/.github/actions/install/gtest/action.yml b/.github/actions/install/gtest/action.yml index 11a6c5f34..4b4008f65 100644 --- a/.github/actions/install/gtest/action.yml +++ b/.github/actions/install/gtest/action.yml @@ -3,7 +3,7 @@ description: Install and setup GTest for linking and building test application runs: using: composite steps: - - run: sudo apt-get install libgtest-dev lcov + - run: sudo apt-get install libgtest-dev # lcov shell: bash - run: (cd /usr/src/gtest && sudo `which cmake` .) shell: bash diff --git a/.github/actions/install/lcov/action.yml b/.github/actions/install/lcov/action.yml new file mode 100644 index 000000000..f90c471ea --- /dev/null +++ b/.github/actions/install/lcov/action.yml @@ -0,0 +1,34 @@ +name: Install lcov +description: Install lcov from official tarball and required Perl modules + +inputs: + version: + description: The lcov version to install + required: false + default: "2.3.1" + +runs: + using: composite + steps: + - name: Install system dependencies + run: | + sudo apt-get install -y \ + libcapture-tiny-perl \ + libdatetime-perl \ + libfile-slurp-perl \ + libfile-copy-recursive-perl \ + libsort-naturally-perl + shell: bash + + - name: Download lcov tarball + run: | + cd /tmp + wget https://github.com/linux-test-project/lcov/releases/download/v${{ inputs.version }}/lcov-${{ inputs.version }}.tar.gz + tar -zxf lcov-${{ inputs.version }}.tar.gz + shell: bash + + - name: Build and install lcov + run: | + cd /tmp/lcov-${{ inputs.version }} + sudo make install + shell: bash diff --git a/.github/workflows/jwt.yml b/.github/workflows/jwt.yml index 46eed9718..85b9b504f 100644 --- a/.github/workflows/jwt.yml +++ b/.github/workflows/jwt.yml @@ -13,12 +13,16 @@ jobs: - uses: actions/checkout@v4 - uses: lukka/get-cmake@latest - uses: ./.github/actions/install/gtest + # - uses: ./.github/actions/install/lcov + - uses: ./.github/actions/install/gcovr - uses: ./.github/actions/install/danielaparker-jsoncons - uses: ./.github/actions/install/boost-json - uses: ./.github/actions/install/open-source-parsers-jsoncpp - name: configure run: cmake --preset coverage + # - name: run-lcov + # run: cmake --build --preset coverage - name: run run: cmake --build --preset coverage @@ -31,19 +35,19 @@ jobs: fuzzing: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: lukka/get-cmake@latest - - - name: configure - run: cmake --preset ci-fuzzing - - name: build - run: cmake --build --preset ci-fuzzing - - - name: run - run: | - cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseEncodeFuzz-run - cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseDecodeFuzz-run - cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-TokenDecodeFuzz-run + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + + - name: configure + run: cmake --preset ci-fuzzing + - name: build + run: cmake --build --preset ci-fuzzing + + - name: run + run: | + cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseEncodeFuzz-run + cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseDecodeFuzz-run + cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-TokenDecodeFuzz-run asan: runs-on: ubuntu-latest diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c7b75504..7251868c3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -81,5 +81,30 @@ if(JWT_ENABLE_COVERAGE) setup_coverage(jwt-cpp-test) set(COVERAGE_EXCLUDES "/usr/**" "/home/*/.conan/**" "*test*" "*build*" "**/nlohmann/json.hpp" "**/picojson/picojson.h" "*boost*" "*jsoncons*") - setup_target_for_coverage_lcov(NAME coverage EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-test) + + # --- LCOV target with ignore flags --- + # setup_target_for_coverage_lcov( + # NAME coverage + # EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-test + # EXCLUDE ${COVERAGE_EXCLUDES} + # LCOV_ARGS --ignore-errors inconsistent,mismatch,unused,count + # ) + + # --- GCOVR target --- + add_custom_target(coverage + COMMAND ${CMAKE_COMMAND} -E echo "Running gcovr coverage..." + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-test + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=$ENV{PYTHONPATH} gcovr + -r ${CMAKE_SOURCE_DIR} + --lcov=${CMAKE_BINARY_DIR}/coverage.info + --exclude '.*test.*' + --exclude '/.*/build/' + --exclude '.*nlohmann/json.hpp' + --exclude '.*picojson/picojson.h' + --exclude '.*boost.*' + --exclude '.*jsoncons.*' + DEPENDS jwt-cpp-test + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generate coverage report with gcovr" + ) endif()