Skip to content
Open
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
65 changes: 65 additions & 0 deletions .github/workflows/checkCoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

name: Coverage

defaults:
run:
shell: bash

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- { name: "Ubuntu gcc", os: ubuntu-latest, cc: "gcc", cxx: "g++", icon: "Linux" }
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Restore stats
run: mkdir -p "${{github.workspace}}/build"
&& git clone --branch gh-stats https://github.com/T-PLAY/hub.git ${{github.workspace}}/build/decline

- name: Install lcov
run: sudo apt install lcov

- name: Configure CMake
run: cmake -B "${{github.workspace}}/build" -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }}
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=install -DHUB_ENABLE_TESTS=ON -DHUB_ENABLE_COVERAGE=ON

- name: Build
run: cmake --build "${{github.workspace}}/build" --config ${{env.BUILD_TYPE}}

- name: Build coverage
run: cmake --build "${{github.workspace}}/build" --target hub-coverage

# Check coverage decline with save stats on gh-stats branch (main coverages)
- name: Check coverage decline
run: cmake --build "${{github.workspace}}/build" --target hub-coverage-checkDecline

# Save coverage stats only when pushing on main
- name: Save coverage stats
if: github.event_name == 'push'
run: cmake --build "${{github.workspace}}/build" --target hub-coverage-saveStats

- name: Save stats
if: github.event_name == 'push'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ${{github.workspace}}/build/decline # The folder the action should deploy.
clean: true
single-commit: true
branch: gh-stats

2 changes: 1 addition & 1 deletion .github/workflows/deployDoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ssciwr/[email protected]

- name: Configure CMake
run: cmake -B "${{github.workspace}}/build" -DHUB_BUILD_DOC=ON

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Current head v.2.1.0 rc
* Add PULL_REQUEST_TEMPLATE file (#30)
- Tests
* Fix timeout error on macos (#33)
* Check coverage decline (#46)
- Documentation
* Fix doxygen (#20)
* Deploy doxygen doc to github page (#20)
Expand Down
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ endif()
set(HUB_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DHUB_PROJECT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

include(GetVersionFromGitTag)
message(STATUS "${HEADER_MSG} Version: ${${PROJECT_NAME}_VERSION} (hash: ${${PROJECT_NAME}_HASH})")

find_package(Boost QUIET) # tcp socket communication
if(Boost_FOUND)
add_definitions(-DHUB_USE_BOOST)
message(STATUS "${HEADER_MSG} Boost found : ${Boost_DIR}")
message(STATUS "${HEADER_MSG} Found Boost ${Boost_VERSION}")
endif()

find_package(TBB QUIET)
Expand Down Expand Up @@ -159,7 +164,6 @@ if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
add_definitions(-DHUB_USE_ZPP_BITS)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

# cmake-format: off
# # set(HUB_MODULES "core")
Expand Down Expand Up @@ -227,8 +231,7 @@ if(NOT WIN32)
list(GET CPP_CHECK_VERSION_LIST 1 CPP_CHECK_VERSION_MINOR)
# list(GET CPP_CHECK_VERSION_LIST 2 CPP_CHECK_VERSION_PATCH)

# message(STATUS "${HEADER_MSG} Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR}.${CPP_CHECK_VERSION_PATCH} found")
message(STATUS "${HEADER_MSG} Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR} found")
message(STATUS "${HEADER_MSG} Found Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR}")

if(NOT ${CPP_CHECK_VERSION_MAJOR} EQUAL 2)
message(FATAL_ERROR "${CPP_CHECK_OUTPUT} unsupported")
Expand Down
28 changes: 15 additions & 13 deletions cmake/GetVersionFromGitTag.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

find_package(Git QUIET)

# Check if git is found... if (GIT_FOUND AND VERSION_UPDATE_FROM_GIT)
if(GIT_FOUND)
execute_process(
Expand All @@ -24,9 +26,6 @@ if(NOT GIT_FOUND OR GIT_DESCRIBE_ERROR_CODE)
set(${PROJECT_NAME}_VERSION_MINOR ${LATEST_VERSION_MINOR})
set(${PROJECT_NAME}_VERSION_PATCH ${LATEST_VERSION_PATCH})

string(TIMESTAMP DATE_EPOCH "%s" UTC)
set(${PROJECT_NAME}_HASH \"${DATE_EPOCH}\")

else()

# Get partial versions into a list
Expand All @@ -50,8 +49,6 @@ else()
set(${PROJECT_NAME}_VERSION_MAJOR ${LATEST_VERSION_MAJOR})
set(${PROJECT_NAME}_VERSION_MINOR ${LATEST_VERSION_MINOR})
set(${PROJECT_NAME}_VERSION_PATCH ${LATEST_VERSION_PATCH})
string(TIMESTAMP DATE_EPOCH "%s" UTC)
set(${PROJECT_NAME}_HASH \"${DATE_EPOCH}\")
else()
message(FATAL_ERROR "You must update the latest version for offline use")
endif()
Expand All @@ -60,14 +57,6 @@ else()

unset(${PROJECT_NAME}_PARTIAL_VERSION_LIST)

# ############################################## COMMIT GIT HASH
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format="%H"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_HASH
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --date=format:%Y --format=%ad
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand All @@ -81,6 +70,19 @@ else()
message(FATAL_ERROR "You must update the last contribution date for offline use")
endif()

endif() # if(NOT GIT_FOUND OR GIT_DESCRIBE_ERROR_CODE)

# ########################## COMMIT GIT HASH
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format="%H"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_HASH
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
string(TIMESTAMP DATE_EPOCH "%s" UTC)
set(${PROJECT_NAME}_HASH \"${DATE_EPOCH}\")
endif()

# Set project version (without the preceding 'v')
Expand Down
95 changes: 95 additions & 0 deletions scripts/coverageDecline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#! /bin/bash -e


if [ $# -ne 3 -a $# -ne 4 ]; then
echo "usage $0: coverageDir declineDir name [hash]"
exit 1
fi

# echo "param1: $1"
if ! [ -e $1 ]; then
echo "'$1' not found"
exit 2
fi

if ! [ -d $1 ]; then
echo "$1 is not a directory"
exit 3
fi

if ! [ -f "$1/index.html" ]; then
echo "$1 is not a coverage build directory"
exit 4
fi

emptyDeclineDir=0

if ! [ -d $2 ]; then
echo "$2 coverage dir does not exist"
emptyDeclineDir=1
fi


coverageRefFile=""
if ((! $emptyDeclineDir)); then

if [ -f "$2/$3.log" ]; then
coverageRefFile="$2/$3.log"
# echo "coverage file '$3' not found in $2"
# exit 3
fi

# if ! [ -d $2/index.html ]; then
# echo "$2 is not a coverage build directory"
# # echo "$2 coverage dir is empty"
# # emptyDeclineDir=1
# exit 4
# fi
fi

index=$1/index.html
gitHash=""
if [ $# -eq 4 ]; then
gitHash=$4
fi
# indexRef=$2/$3.log

lines=$(cat $index | grep headerCovTableEntryLo | tr -d ' ' | awk -F '[>&%]' '{print $2}' | head -n 1)
functions=$(cat $index | grep headerCovTableEntryLo | tr -d ' ' | awk -F '[>&%]' '{print $2}' | tail -n 1)

# if (($emptyDeclineDir)); then
if [ -z $coverageRefFile ]; then
linesRef=0
functionsRef=0
else
linesRef=$(cat $coverageRefFile | head -n 1 | awk '{print $2}')
functionsRef=$(cat $coverageRefFile | head -n 1 | awk '{print $3}')
fi

echo "lines coverage = $lines% >= $linesRef%"
echo "functions coverage = $functions% >= $functionsRef%"

if (( $(echo "$lines < $linesRef" | bc -l) )) ; then
echo "lines coverage must be superior as $linesRef%"
exit 1
fi

if (( $(echo "$functions < $functionsRef" | bc -l) )); then
echo "functions coverage must be superior as $functionsRef%"
exit 1
fi

############################## SAVING/OVERWRITE #################################

if (($emptyDeclineDir)); then
mkdir -p $2
fi

# gitHash=$(git log -1 --format="%H")
if ! [ -z $gitHash ]; then
echo "'$gitHash $lines $functions' added in $2/$3.log file."
echo "$gitHash $lines $functions" >> $2/$3.log
fi


exit 0
Loading