Skip to content

Commit

Permalink
Merge pull request hyperledger-iroha#441 from hyperledger/feature/cov…
Browse files Browse the repository at this point in the history
…erage-comment

Feature/coverage comment
  • Loading branch information
grimadas authored Jul 23, 2017
2 parents e60b369 + afacffd commit b6a93fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ jobs:
steps:
- checkout

- run:
name: deps install
command: apt update && apt install curl -y

- run:
name: ensure, required folders created
command: |
mkdir -p $IROHA_HOME
mkdir -p $IROHA_BUILD
- run:
name: cmake
command: cmake -H$IROHA_HOME -B$IROHA_BUILD
command: cmake -DCOVERAGE=ON -H$IROHA_HOME -B$IROHA_BUILD
- run:
name: make
command: cmake --build $IROHA_BUILD -- -j4
- run:
name: run tests
command: cmake --build $IROHA_BUILD --target test
- run:
name: comment coverage on the pull-request
command: $IROHA_HOME/scripts/comment-coverage.sh

# - run:
# name: analyze source code with cppcheck and sonarqube
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ PROJECT(iroha C CXX)
SET(CMAKE_CXX_FLAGS "-std=c++1y -Wall -fPIC")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wextra -Wno-unused-parameter -O0")
SET(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)

SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
SET(GCC_COVERAGE_LINK_FLAGS "-lgcov")

SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)

option(BENCHMARKING "Build benchmarks" OFF)
option(TESTING "Build tests" ON)
option(COVERAGE "Enable coverage" OFF)
option(FUZZING "Build fuzzing binaries" OFF)

if (NOT CMAKE_BUILD_TYPE)
Expand All @@ -17,6 +23,7 @@ message(STATUS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(STATUS "-DTESTING=${TESTING}")
message(STATUS "-DBENCHMARKING=${BENCHMARKING}")
message(STATUS "-DFUZZING=${FUZZING}")
message(STATUS "-DCOVERAGE=${COVERAGE}")

SET(IROHA_SCHEMA_DIR "${PROJECT_SOURCE_DIR}/schema")
include_directories(
Expand All @@ -35,6 +42,11 @@ add_subdirectory(iroha-cli)

link_directories(${PROJECT_BINARY_DIR}/lib)

if (COVERAGE)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
endif()

if(TESTING)
enable_testing()
add_subdirectory(test)
Expand Down
26 changes: 26 additions & 0 deletions scripts/comment-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -v


if [ "$CIRCLE_PULL_REQUEST" == false ] || [ -z "$CIRCLE_PULL_REQUEST" ]; then
exit 0
fi


if [[ $CIRCLE_PULL_REQUEST =~ ([0-9]*)$ ]]; then
PR_NUMBER=${BASH_REMATCH[1]}
fi


# depencies
apt-get update -y && apt-get install -y lcov npm nodejs-legacy
npm install -g lcov-summary

cd $IROHA_BUILD
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --remove coverage.info '*external*' --output-file coverage.info
RESULT_COVERAGE=`lcov-summary ./coverage.info | sed -z 's/\n/\\\\n/g'`

curl -XPOST -H 'Content-Type:application/json' -H "Authorization: token $GITHUB_TOKEN" -d "{\"body\":\"$RESULT_COVERAGE\"}" https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/issues/$PR_NUMBER/comments

0 comments on commit b6a93fb

Please sign in to comment.